Creating A List View Of Objects from Parse Class

App crashes when i try to put objects from parse on a List view, note that objects are present as toast would loop through and give the names, just cant put it in a list view. Here is my code,on create method, please help, what could i have missed?

my Logs error

03-03 12:20:52.352 27230-27230/com.parse.starter E/AndroidRuntime: FATAL EXCEPTION: main Process: com.parse.starter, PID: 27230 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:401) at android.widget.ArrayAdapter.getView(ArrayAdapter.java:369) at android.widget.AbsListView.obtainView(AbsListView.java:2474) at android.widget.ListView.makeAndAddView(ListView.java:1920) at android.widget.ListView.fillDown(ListView.java:717) at android.widget.ListView.fillFromTop(ListView.java:778) at android.widget.ListView.layoutChildren(ListView.java:1715) at android.widget.AbsListView.onLayout(AbsListView.java:2235) at android.view.View.layout(View.java:16961) at android.view.ViewGroup.layout(ViewGroup.java:5606) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1189) at android.view.View.layout(View.java:16961) at android.view.Vie wGroup.layout(ViewGroup.java:5606) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:396) at android.widget.FrameLayout.onLayout(FrameLayout.java:333) at android.view.View.layout(View.java:16961) at android.view.ViewGroup.layout(ViewGroup.java:5606) at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:435) at android.view.View.layout(View.java:16961) at android.view.ViewGroup.layout(ViewGroup.java:5606) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:396) at android.widget.FrameLayout.onLayout(FrameLayout.java:333) at android.view.View.layout(View.java:16961) at android.view.ViewGroup.layout(ViewGroup.java:5606) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:2001) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1844) at android.widget.LinearLayout.onLayout(LinearLayout.java:1753) at android.view.View.layout(View.java:16961) at android.view.ViewGroup.layout(ViewGroup.java:5606) at android.widge t.FrameLayout.layoutChildren(FrameLayout.java:396) at android.widget.FrameLayout.onLayout(FrameLayout.java:333) at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2742) at android.view.View.layout(View.java:16961) at android.view.ViewGroup.layout(ViewGroup.java:5606) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2552) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2255) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1321) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6708) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:894) at android.view.Choreographer.doCallbacks(Choreographer.java:696) at android.view.Choreographer.doFrame(Choreographer.java:631) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:880) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Loop er.java:207) at android.app.ActivityThread.main(ActivityThread.java:5728) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

And here is the code

  @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());
  }

}
链接地址: http://www.djcxy.com/p/93138.html

上一篇: 在printStackTrace()上打印完整的调用堆栈?

下一篇: 从分析类创建对象的列表视图