当我尝试将对象从解析中放入List视图时,应用程序崩溃,请注意,对象存在,因为toast会遍历并提供名称,只是无法将其放在列表视图中。这是我的代码,关于创建方法,请帮助,我可能错过了什么?
我的日志错误
03-03 12:20:52.352 27230-27230 / com.parse.starter E / AndroidRuntime:FATAL EXCEPTION:main 处理:com.parse.starter,PID:27230 java.lang.NullPointerException:尝试调用虚方法' java.lang.String java.lang.Object.toString()'在null对象引用上 在android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:401) 在android.widget.ArrayAdapter.getView(ArrayAdapter.java:369) 在android.widget.AbsListView.obtainView(AbsListView.java:2474) 在android.widget.ListView.makeAndAddView(ListView.java:1920) 在android.widget.ListView.fillDown(ListView.java:717) 在android.widget.ListView.fillFromTop(ListView.java:778) 在android.widget.ListView.layoutChildren(ListView.java:1715) 在android.widget.AbsListView.onLayout(AbsListView.java:2235) 在android.view.View.layout(View.java:16961) 在android.view.ViewGroup.layout(ViewGroup.java:5606) 在android.widget.RelativeLayout.onLayout(RelativeLayout.java:1189) 在android.view.View.layout(View.java:16961) 在android.view.ViewGroup.layout(ViewGroup.java:5606) 在android.widget.FrameLayout.layoutChildren(FrameLayout.java:396) 在android.widget.FrameLayout.onLayout(FrameLayout.java:333) 在android.view.View.layout(View.java:16961) 在android.view.ViewGroup.layout(ViewGroup.java:5606) 在android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:435) 在android.view.View.layout(View.java:16961) 在android.view.ViewGroup.layout(ViewGroup.java:5606) 在android.widget.FrameLayout.layoutChildren(FrameLayout.java:396) 在android.widget.FrameLayout.onLayout(FrameLayout.java:333) 在android.view.View.layout(View.java:16961) 在android.view.ViewGroup.layout(ViewGroup.java:5606) 在android.widget.LinearLayout.setChildFrame(LinearLayout.java:2001) 在android.widget.LinearLayout.layoutVertical(LinearLayout.java:1844) 在android.widget.LinearLayout.onLayout(LinearLayout.java:1753) 在android.view.View.layout(View.java:16961) 在android.view.ViewGroup.layout(ViewGroup.java:5606) 在android.widget.FrameLayout.layoutChildren(FrameLayout.java:396) 在android.widget.FrameLayout.onLayout(FrameLayout.java:333) 在com.android.internal.policy.PhoneWindow $ DecorView.onLayout(PhoneWindow.java:2742) 在android.view.View.layout(View.java:16961) 在android.view.ViewGroup.layout(ViewGroup.java:5606) 在android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2552) 在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2255) 在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1321) 在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:6708) 在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:894) 在android.view.Choreographer.doCallbacks(Choreographer.java:696) 在android.view.Choreographer.doFrame(Choreographer.java:631) 在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:880) 在android.os.Handler.handleCallback(Handler.java:815) 在android.os.Handler.dispatchMessage(Handler.java:104) 在android.os.Looper.loop(Looper.java:207) 在android.app.ActivityThread.main(ActivityThread.java:5728) at java.lang.reflect.Method.invoke(Native Method) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:789) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
这是代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Users home
Toast.makeText(this, "USERS", Toast.LENGTH_SHORT).show();
//Populating listview with values from created parse object
final ArrayList<String> jusernames = new ArrayList<String>();
final ListView userListView = (ListView) findViewById(R.id.listview);
final ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, jusernames);
ParseQuery <ParseObject> query = ParseQuery.getQuery("Help");
//Picking all the users without deleted tag
query.whereNotEqualTo("username", "Deleted");
//Making the list in ascending order
query.addAscendingOrder("username");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if( e == null){
if(objects.size() > 0){
for(ParseObject object : objects){
String user = object.getString("Username");
String category = object.getString("Category");
Toast.makeText(MainActivity.this, category, Toast.LENGTH_SHORT).show();
String description = object.getString("Description");
String price = object.getString("Price");
//Adding the value to listview
jusernames.add(category);
}
userListView.setAdapter(arrayAdapter);
}
}else
{
Toast.makeText(MainActivity.this, "Fail", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
});
ParseAnalytics.trackAppOpenedInBackground(getIntent());
}
}