I have some problem with my code and I just can't find a solution. Here's my project: I have a Parse database that stores users, and these users can post status. On my parse app I have two classes, users and status. When some user upload the status, I save them and the username. The problem is, I can't retrieve the values from 'status' on parse and show on a listview:
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Status");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> status, ParseException e) {
if(e == null) {
mStatus = status;
listview tcam = new listview();
tcam.mac(mStatus);
}else{
System.out.println("Deu ruim");
}
}
});
}
mStatus is declared like this: List<ParseObject> mStatus;
, listview is another java class, and mac is a method(and that's where the problem is). I need to pass mStatus as parameter, so I can use on this method(on listview.java):
public void mac(List<ParseObject> mStatus){
StatusAdapter adapter = new StatusAdapter(getListView().getContext(), mStatus);
setListAdapter(adapter);
}
I get an error on the following lines:
(StatusAdapter adapter = new StatusAdapter(getListView().getContext(), mStatus));
and
(tcam.mac(mStatus);)
and the application closes.
I've tested the variable mStatus
and it is not empty. You may ask why I'm doing this in 2 classes, and it is because the ...getListView().getContext()...
doesn't work without extending ListActivity
, and I'm already extending AppCompactActivity
.(This is the only solution I found)
StatusAdapter
is another class, and I have extended ArrayAdapter<ParseObject>
. And yes, I have a xml layout file to draw my listview...
Thanks!
That's my console error:
12-11 16:48:56.545 22535-22535/com.example.rafael.whatsnew W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x4184c7d0)
12-11 16:48:56.555 22535-22535/com.example.rafael.whatsnew E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException
at android.app.Activity.setContentView(Activity.java:1893)
at android.app.ListActivity.ensureList(ListActivity.java:312)
at android.app.ListActivity.getListView(ListActivity.java:297)
at com.example.rafael.whatsnew.listview.mac(listview.java:21)
at com.example.rafael.whatsnew.home$4.done(home.java:204)
at com.example.rafael.whatsnew.home$4.done(home.java:198)
at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:115)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5031)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)