-6

from the WebServer i can fetch data and pass it correctly into ListView with this class:

ReceiveFields class Structure:

public class ReceiveFields {
    public long lastId;
    public String smsNumber;
    public String mobileNumber;
    public String senderName;
    public String smsBody;
    public String receiveDate;
    private Context ctx;
}

ReceivedSMS Class to get data from WebService:

public class ReceivedSMS extends ListFragment implements AbsListView.OnScrollListener {
    private List<ReceiveFields> rows;
    private int prevVisibleItem;
    private TSMS tsms;
    private String username;
    private String password;
    public  Long getLastReceivedSMSID;
    private boolean isFirstTime;
    private Context context;

    public ResivedSMS(Context context, String username, String password) {
        this.username = username;
        this.password = password;
        this.context = context;
    }

    public ResivedSMS(String username, String password, long start, long count,Context context) {
        this.username = username;
        this.password = password;
        this.context = context;
        tsms = new TSMS(context ,new User(username, password));
        getResivedSMS(start , count);
    }

    public ResivedSMS(List<ReceiveFields> receivedSMSList,Context context){
        rows = receivedSMSList;
        this.context = context;
    }

    public List<ReceiveFields> getResivedSMS(long start, long count) {
        tsms = new TSMS(context,new User(this.username, this.password));
        try {
            rows = tsms.getReceivedSMS(start, count);
        }
        catch (TException e) {
            e.printStackTrace();
            Log.e("ERROR IN Fetch SMS From WebService List<ReceiveFields> getResivedSMS(long start, long count) " , String.valueOf(e));
        }
        return rows;
    }

use ResivedSMS class as :

ResivedSMS receivedSMSList = new ReceivedSMS("username","password",0,20,context);

and pass into ListView :

getSupportFragmentManager().beginTransaction().replace(R.id.drawer, receivedSMSList).commit();

all of this way is correct and i dont have problem. but i want to fetch data from DataBase and pass it insted of ReceivedSMS as :

List<ReceiveFields> r1 = db.getAllReceivedSMSFromDatabase();

receivedSMSList = new ResivedSMS(r1,context);

getSupportFragmentManager().beginTransaction().replace(R.id.drawer, receivedSMSList).commit();

getAllReceivedSMSFromDatabase function :

public List<ReceiveFields> getAllReceivedSMSFromDatabase() {
    SQLiteDatabase db = this.getReadableDatabase();
    String selectQuery = "SELECT * FROM " + this.RECEIVE_FIELDS_TABLE ;
    Cursor cursor = db.rawQuery(selectQuery, null);
    List<ReceiveFields> ListSMS = new ArrayList<ReceiveFields>();
    cursor.moveToFirst();
    while (cursor.moveToNext()) {
        ListSMS.add(new ReceiveFields(
                Long.valueOf(cursor.getString(cursor.getColumnIndex("lastId"))),
                cursor.getString(cursor.getColumnIndex("smsNumber")),
                cursor.getString(cursor.getColumnIndex("mobileNumber")),
                cursor.getString(cursor.getColumnIndex("senderName")),
                cursor.getString(cursor.getColumnIndex("smsBody")),
                cursor.getString(cursor.getColumnIndex("receiveDate"))));
    }

    cursor.close();
    db.close();
    return ListSMS;
}

NOTE: My Database is not empty and have 20 rows

getAllReceivedSMSFromDatabase return value is like with getResivedSMS but i get this error :

enter image description here

getAllReceivedSMSFromDatabase Function Result with `LogCat:

ID: 19  lastId: 29901991  smsNumber: 30007227  mobileNumber: 09000000892  senderName 09122510892  smsBody: tsssasaS  receiveDate: 2014/8/3

ID: 19  lastId: 29901992  smsNumber: 30007227  mobileNumber: 09000000892  senderName 09122510892  smsBody: tsssasaS  receiveDate: 2014/9/3

ID: 19  lastId: 29901993  smsNumber: 30007227  mobileNumber: 09000000892  senderName 09122510892  smsBody: tsssasaS  receiveDate: 2014/10/3
3
  • Your setting the list object, while it requires the fragment, initialize and set your fragment class ReceivedSMS here. Sep 1, 2014 at 11:45
  • @jitainsharma i can't do it. how to?
    – DolDurma
    Sep 1, 2014 at 11:51
  • Like ReceivedSMS receivedSMS = new ReceivedSMS(context, username, password); Sep 1, 2014 at 11:53

1 Answer 1

2

The problem is that you are passing a list as argument to replace() and it is expecting a Fragment as parameter.

public abstract FragmentTransaction replace (int containerViewId, Fragment fragment)

You have passed a list as an argument instead of passing a Fragment.

Try passing ReceivedSMS ( which extends ListFragment) instead of ListSMS which is a list (List<ReceiveFields> ListSMS)

2
  • I dont underestand me sir. can you paste correct way to post? – TuxWorld 21 mins ago
    – DolDurma
    Sep 1, 2014 at 13:45
  • @TuxWorld Repeating that oh so many times is not the best approach to go about getting help... Moreover, your timestamp is in your message already, yet you copied that as well.
    – Unihedron
    Sep 1, 2014 at 13:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.