从分析类创建对象的列表视图

应用程序崩溃时,我尝试将对象从解析列表视图,请注意,对象是作为吐司会循环并提供名称,只是不能把它放在列表视图中。 这里是我的代码,关于创建方法,请帮助,我可以错过什么?

我的日志错误

03-03 12:20:52.352 27230-27230 / com.parse.starter E / AndroidRuntime:致命异常:主进程:com.parse.starter,PID:27230 java.lang.NullPointerException:尝试调用虚拟方法'java。在android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:401)上的空对象引用上的android.widget.ArrayAdapter.getView(ArrayAdapter.java:369)android上的lang.String java.lang.Object.toString() .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。在android.view.View.layout(View.java)android.widget.AbsListView.onLayout(AbsListView.java:2235)android.widget.ListView.layoutChildren(ListView.java:1715)fillFromTop(ListView.java:778) :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)在android.widget.FrameLayout.layoutChildren(FrameLayout.java:396)在android.widget.FrameLayout.onLayout(FrameLayout.java:333)在android.view.View.layout(查看的.java:16961)在android.view.ViewGroup.layout(ViewGroup.java:5606)在android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:435)在android.view.View.layout(查看。的java:16961)在android.view.ViewGroup.layout(ViewGroup.java:5606)在android.widget.FrameLayout.layoutChildren(FrameLayout.java:396)在android.widget.FrameLayout.onLayout(FrameLayout.java:333)在在android.widget.LinearLayout上的android.widget.LinearLayout.setChildFrame(LinearLayout.java:2001)上的android.view.ViewGroup.layout(ViewGroup.java:5606)上的android.view.View.layout(View.java:16961) .layoutVertical(LinearLayout.java:1844)在android.view.ViewGroup.layout(ViewGroup。)的android.view.View.layout(View.java:16961)android.widget.LinearLayout.onLayout(LinearLayout.java:1753)。 java:5606)在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。在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1321)处的android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:6708)上的performTraversals(ViewRootImpl.java:2255)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(编导。 java:880)在android.os.Handler.handleCallback(Handler.java:815)在android.os.Handler.dispatchMessage(Handler.java:104)在android.os.Looper.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)在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());
  }

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

上一篇: Creating A List View Of Objects from Parse Class

下一篇: I'm trying to populate a listview by using an intent