Nullpointer异常 - getCount

时间:2015-12-19 06:07:50

标签: android json listview

我得到了这个Nullpointer异常,我不明白为什么。我已经研究并知道getCount返回null,但我不明白为什么。我试图解析一个JSON数组并将该信息发送到自定义适配器以显示自定义列表视图。在过去的7天里,我一直都是圆形的。该应用程序正在工作并从静态JSON文件中提取数据。我需要在更新数据库时更新feed,因此静态JSON不是一个好的解决方案。我最终屏幕只显示白色,没有任何细节。我可以在普通列表视图中显示数据,但不能在膨胀视图中显示数据。在解决空白屏幕之前,我必须清除此异常。这是主要活动,自定义适配器和模型的代码。我希望有人可以看一看并给予帮助。

logcat的

12-19 01:02:58.516 32588-32588/com.brasiltradefx.btfxalerts E/AndroidRuntime: FATAL EXCEPTION: main
                                                                              Process: com.brasiltradefx.btfxalerts, PID: 32588
                                                                              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.brasiltradefx.btfxalerts/com.brasiltradefx.btfxalertsadmin.AlertMainActivity}: java.lang.NullPointerException
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2350)
                                                                                  at android.app.ActivityThread.access$800(ActivityThread.java:163)
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1257)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                  at android.os.Looper.loop(Looper.java:157)
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5335)
                                                                                  at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                  at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
                                                                                  at dalvik.system.NativeStart.main(Native Method)
                                                                               Caused by: java.lang.NullPointerException
                                                                                  at com.brasiltradefx.btfxalertsadmin.adapter.FeedListAdapter.getCount(FeedListAdapter.java:48)
                                                                                  at android.widget.ListView.setAdapter(ListView.java:486)
                                                                                  at com.brasiltradefx.btfxalertsadmin.AlertMainActivity.onCreate(AlertMainActivity.java:46)

主要活动(已更新)

    public class AlertMainActivity extends Activity {

    private String url = "http://www.contrariantradefx.info/android/btfxalerts/alerts_all_data_clients.php";
    ProgressDialog PD;
    ArrayList<String> feedItems;
    FeedListAdapter listadapter;
    ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alert_main);

        listView = (ListView)findViewById(R.id.list);
        feedItems = new ArrayList<>();

        PD = new ProgressDialog(this);
        PD.setMessage("Loading...");
        PD.setCancelable(false);

        listadapter = new FeedListAdapter(this, feedItems);
        listView.setAdapter(listadapter);

        MakeJsonArrayReq();
    }

    private void MakeJsonArrayReq() {
        PD.show();

        JsonArrayRequest jreq = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {

            @Override
            public void onResponse(JSONArray response) {

                for (int i = 0; i < response.length(); i++) {
                    try {
                        JSONObject jo = response.getJSONObject(i);
                        String date = jo.getString("date");
                        String order = jo.getString("order");
                        String pair = jo.getString("pair");
                        String rate = jo.getString("rate");
                        String quick_target = jo.getString("quick_target");
                        String long_target = jo.getString("long_target");
                        String stop_loss = jo.getString("stop_loss");
                        String break_even = jo.getString("break_even");
                        String name = jo.getString("name");
                        String status = jo.getString("status");
                        String profilePic = jo.getString("profilePic");
                        String image = jo.isNull("image")? null : jo.getString("image");

                        FeedItem item = new FeedItem();

                        item.setDate(date);
                        item.setOrder_type(order);
                        item.setPair(pair);
                        item.setRate(rate);
                        item.setQuick_target(quick_target);
                        item.setLong_target(long_target);
                        item.setStop_loss(stop_loss);
                        item.setBreak_Even(break_even);
                        item.setName(name);
                        item.setStatus(status);
                        item.setProfilePic(profilePic);
                        item.setImge(image);

                        feedItems.add(feedItems); // (feedItems)this is saying add(java.lang.String)  in ArrayList cannot be applied to(java.util.ArrayList<java.lang.String



                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                PD.dismiss();
                listadapter.notifyDataSetChanged();
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });

        AppController.getInstance().addToRequestQueue(jreq, "jreq");
    }

}

FeedListAdapter (已更新)

    public class FeedListAdapter extends BaseAdapter {
    private Activity activity;
    private LayoutInflater inflater;
    private ArrayList<FeedItem> feedItems;

    int size=0 ;
    ImageLoader imageLoader = AppController.getInstance().getImageLoader();


    public FeedListAdapter(AlertMainActivity activity, ArrayList<String> feedItems) {
        this.activity = activity;
        this.feedItems = feedItems; // this is saying incompatible types.   required ArrayList com.brasiltradefx.btfxalertsadmin.data.FeedItem

found ArrayList java.lang.String
        if(this.feedItems !=null && !this.feedItems.isEmpty()){
            size = this.feedItems.size();
        }
    }


    @Override
    public int getCount() {
        return feedItems.size();
    }

    @Override
    public Object getItem(int location) {
        return feedItems.get(location);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (inflater == null)
            inflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (convertView == null)
            convertView = inflater.inflate(R.layout.feed_item, null);

        if (imageLoader == null)
            imageLoader = AppController.getInstance().getImageLoader();

        TextView name = (TextView) convertView.findViewById(R.id.txtname);
        TextView date = (TextView) convertView
                .findViewById(R.id.txtdate);
        TextView statusMsg = (TextView) convertView
                .findViewById(R.id.txtStatusMsg);


        TextView order_type = (TextView) convertView.findViewById(R.id.txtOrderType);
        TextView pair = (TextView) convertView.findViewById(R.id.txtPair);
        TextView rate = (TextView) convertView.findViewById(R.id.txtRate);
        TextView quick_target = (TextView) convertView.findViewById(R.id.txtQuick_Target);
        TextView long_target = (TextView) convertView.findViewById(R.id.txtLong_Target);
        TextView stop_loss = (TextView) convertView.findViewById(R.id.txtStop_Loss);
        TextView break_even = (TextView) convertView.findViewById(R.id.txtBreak_Even);
        NetworkImageView profilePic = (NetworkImageView) convertView.findViewById(R.id.profilePic);
        FeedImageView feedImageView = (FeedImageView) convertView
                .findViewById(R.id.feedImage1);

        FeedItem item = feedItems.get(position);

        name.setText(item.getName());
        date.setText(item.getDate());
        order_type.setText(item.getOrder_type());
        pair.setText(item.getPair());
        rate.setText(item.getRate());
        quick_target.setText(item.getQuick_target());
        long_target.setText(item.getLong_target());
        stop_loss.setText(item.getStop_loss());
        break_even.setText(item.getBreak_Even());

        //Converting timestamp into x ago format - removed timeStamp - using date
        //CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(
                //Long.parseLong(item.getTimeStamp()),
                //System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
        //timestamp.setText(timeAgo);

        // Chcek for empty status message
        if (!TextUtils.isEmpty(item.getStatus())) {
            statusMsg.setText(item.getStatus());
            statusMsg.setVisibility(View.VISIBLE);
        } else {
            // status is empty, remove from view
            statusMsg.setVisibility(View.GONE);
        }

        // Checking for null feed url
        //if (item.getUrl() != null) {
            //url.setText(Html.fromHtml("<a href=\"" + item.getUrl() + "\">"
                    //+ item.getUrl() + "</a> "));

            // Making url clickable
            //url.setMovementMethod(LinkMovementMethod.getInstance());
            //url.setVisibility(View.VISIBLE);
        //} else {
            // url is null, remove from the view
            //url.setVisibility(View.GONE);
        //}
        // user profile pic
        profilePic.setImageUrl(item.getProfilePic(), imageLoader);

        // Feed image
        if (item.getImge() != null) {
            feedImageView.setImageUrl(item.getImge(), imageLoader);
            feedImageView.setVisibility(View.VISIBLE);
            feedImageView
                    .setResponseObserver(new FeedImageView.ResponseObserver() {
                        @Override
                        public void onError() {
                        }

                        @Override
                        public void onSuccess() {
                        }
                    });
        } else {
            feedImageView.setVisibility(View.GONE);
        }

        return convertView;
    }

}

feed_item.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/feed_bg"
    android:orientation="vertical"
    android:showDividers="end">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingLeft="@dimen/feed_item_padding_left_right"
        android:paddingRight="@dimen/feed_item_padding_left_right"
        android:background="#050505">

        <com.android.volley.toolbox.NetworkImageView
            android:id="@+id/profilePic"
            android:layout_width="@dimen/feed_item_profile_pic"
            android:layout_height="@dimen/feed_item_profile_pic"
            android:scaleType="fitCenter"
            android:layout_marginTop="15dp">
        </com.android.volley.toolbox.NetworkImageView>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingLeft="@dimen/feed_item_profile_info_padd" >

            <TextView
                android:id="@+id/txtname"
                android:layout_width="fill_parent"
                android:layout_height="25dp"
                android:textSize="@dimen/feed_item_profile_name"
                android:textStyle="bold"
                android:background="#3452aa"
                android:layout_marginTop="10dp"
                android:textColor="#ffffff"
                android:textAlignment="center" />

            <TextView
                android:id="@+id/txtdate"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#ffffff"
                android:textSize="@dimen/feed_item_date"
                android:layout_marginTop="10dp"
                android:gravity="right" />

            <TextView
                android:id="@+id/txtStatusMsg"
                android:layout_width="157dp"
                android:layout_height="wrap_content"
                android:paddingBottom="5dp"
                android:paddingLeft="@dimen/feed_item_status_pad_left_right"
                android:paddingRight="@dimen/feed_item_status_pad_left_right"
                android:paddingTop="@dimen/feed_item_status_pad_top"
                android:layout_marginTop="10dp"
                android:textColor="#ffffff"
                android:gravity="right"
                android:background="#3452aa"
                android:layout_gravity="right" />
        </LinearLayout>
    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/txtBreak_Even"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:paddingBottom="5dp"
            android:paddingLeft="@dimen/feed_item_status_pad_left_right"
            android:paddingRight="@dimen/feed_item_status_pad_left_right"
            android:paddingTop="@dimen/feed_item_status_pad_top"
            android:background="#f8fe5a"
            android:textColor="#000000"
            android:layout_alignBottom="@+id/textViewBreakEven"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_below="@+id/txtStop_Loss"
            android:layout_marginLeft="120dp"
            android:layout_marginTop="5dp"
            android:textAlignment="center"
            android:layout_marginRight="5dp"
            android:gravity="center_vertical"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/txtLong_Target"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:paddingBottom="5dp"
            android:paddingLeft="@dimen/feed_item_status_pad_left_right"
            android:paddingRight="@dimen/feed_item_status_pad_left_right"
            android:paddingTop="@dimen/feed_item_status_pad_top"
            android:background="#FF3CF14C"
            android:textColor="#000000"
            android:layout_below="@+id/txtQuick_Target"
            android:layout_alignLeft="@+id/txtQuick_Target"
            android:layout_alignStart="@+id/txtQuick_Target"
            android:layout_marginTop="5dp"
            android:textAlignment="center"
            android:layout_marginRight="5dp"
            android:gravity="center_vertical"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/txtQuick_Target"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:paddingBottom="5dp"
            android:paddingLeft="@dimen/feed_item_status_pad_left_right"
            android:paddingRight="@dimen/feed_item_status_pad_left_right"
            android:paddingTop="@dimen/feed_item_status_pad_top"
            android:background="#3cf14c"
            android:textColor="#000000"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="120dp"
            android:layout_marginTop="5dp"
            android:layout_below="@+id/txtRate"
            android:textAlignment="center"
            android:layout_marginRight="5dp"
            android:gravity="center_vertical"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/txtStop_Loss"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:paddingBottom="5dp"
            android:paddingLeft="@dimen/feed_item_status_pad_left_right"
            android:paddingRight="@dimen/feed_item_status_pad_left_right"
            android:paddingTop="@dimen/feed_item_status_pad_top"
            android:background="#FFFC5964"
            android:textColor="#000000"
            android:layout_below="@+id/txtLong_Target"
            android:layout_marginLeft="120dp"
            android:layout_marginTop="5dp"
            android:textAlignment="center"
            android:layout_marginRight="5dp"
            android:gravity="center_vertical"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/txtRate"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:paddingBottom="5dp"
            android:paddingLeft="@dimen/feed_item_status_pad_left_right"
            android:paddingRight="@dimen/feed_item_status_pad_left_right"
            android:paddingTop="@dimen/feed_item_status_pad_top"
            android:background="#FF6AC1F7"
            android:textColor="#000000"
            android:layout_below="@+id/txtPair"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="120dp"
            android:layout_marginTop="5dp"
            android:textAlignment="center"
            android:layout_marginRight="5dp"
            android:gravity="center_vertical"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/txtPair"
            android:layout_width="fill_parent"
            android:layout_height="40dp"
            android:paddingBottom="5dp"
            android:paddingLeft="@dimen/feed_item_status_pad_left_right"
            android:paddingRight="@dimen/feed_item_status_pad_left_right"
            android:paddingTop="@dimen/feed_item_status_pad_top"
            android:background="#FF6AC1F7"
            android:textColor="#000000"
            android:layout_below="@+id/txtOrderType"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="120dp"
            android:layout_marginTop="5dp"
            android:textAlignment="center"
            android:layout_marginRight="5dp"
            android:gravity="center_vertical"
            android:textSize="18sp" />

        <TextView
        android:id="@+id/txtOrderType"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:paddingBottom="5dp"
        android:paddingLeft="@dimen/feed_item_status_pad_left_right"
        android:paddingRight="@dimen/feed_item_status_pad_left_right"
        android:paddingTop="@dimen/feed_item_status_pad_top"
        android:background="#FF6AC1F7"
            android:textColor="#000000"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@+id/textViewOrder_Type"
            android:layout_marginLeft="120dp"
            android:textAlignment="center"
            android:layout_marginRight="5dp"
            android:gravity="center_vertical"
            android:textSize="18sp" />

        <TextView
            android:layout_width="110dp"
            android:layout_height="40dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="BreakEven"
            android:id="@+id/textViewBreakEven"
            android:background="#FFF8FE5A"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/txtStop_Loss"
            android:layout_marginTop="5dp"
            android:textColor="#000000"
            android:layout_marginLeft="5dp"
            android:gravity="center_vertical|right"
            android:textSize="18sp" />

        <TextView
            android:layout_width="110dp"
            android:layout_height="40dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="StopLoss"
            android:id="@+id/textViewStop_Loss"
            android:background="#fc5964"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/txtLong_Target"
            android:layout_marginTop="5dp"
            android:textColor="#000000"
            android:singleLine="false"
            android:layout_marginLeft="5dp"
            android:gravity="center_vertical|right"
            android:textSize="18sp" />

        <TextView
            android:layout_width="110dp"
            android:layout_height="40dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Long Target"
            android:id="@+id/textViewLong_Target"
            android:background="#FF3CF14C"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/txtQuick_Target"
            android:layout_marginTop="5dp"
            android:textColor="#000000"
            android:layout_marginLeft="5dp"
            android:gravity="center_vertical|right"
            android:textSize="18sp" />

        <TextView
            android:layout_width="110dp"
            android:layout_height="40dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Quick Target"
            android:background="#FF3CF14C"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/txtRate"
            android:layout_marginTop="5dp"
            android:textColor="#000000"
            android:id="@+id/textViewQuick_Target"
            android:layout_marginLeft="5dp"
            android:gravity="center_vertical|right"
            android:textSize="18sp" />

        <TextView
            android:layout_width="110dp"
            android:layout_height="40dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Rate"
            android:id="@+id/textViewRate"
            android:background="#FF6AC1F7"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/txtPair"
            android:layout_marginTop="5dp"
            android:textColor="#000000"
            android:layout_marginLeft="5dp"
            android:gravity="center_vertical|right"
            android:textSize="18sp" />

        <TextView
            android:layout_width="110dp"
            android:layout_height="40dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Pair"
            android:id="@+id/textViewPair"
            android:background="#FF6AC1F7"
            android:layout_below="@+id/txtOrderType"
            android:layout_alignParentStart="true"
            android:layout_marginTop="5dp"
            android:textColor="#000000"
            android:layout_marginLeft="5dp"
            android:gravity="center_vertical|right"
            android:textSize="18sp" />

        <TextView
            android:layout_width="110dp"
            android:layout_height="40dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Order Type"
            android:id="@+id/textViewOrder_Type"
            android:background="#6ac1f7"
            android:layout_alignTop="@+id/txtOrderType"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:textColor="#000000"
            android:layout_alignParentBottom="false"
            android:layout_marginLeft="5dp"
            android:gravity="center_vertical|right"
            android:textSize="18sp" />
    </RelativeLayout>


    <com.brasiltradefx.btfxalertsadmin.FeedImageView
            android:id="@+id/feedImage1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:scaleType="fitXY"
            android:visibility="visible" />
    </LinearLayout>

3 个答案:

答案 0 :(得分:1)

删除其他两个contructer&amp;给出构造函数中给出的大小。

public class FeedListAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private ArrayList<FeedItem> feedItems;

int size =0 ;
ImageLoader imageLoader = AppController.getInstance().getImageLoader();



    public FeedListAdapter(Activity activity, ArrayList<FeedItem> feedItems) {
        this.activity = activity;
        this.feedItems = feedItems;

    if(this.feedItems !=null && !this.feedItems.isEmpty()){
    size = this.feedItems.size();
    }
    }


    @Override
    public int getCount() {
        return size;
    }

    @Override
    public Object getItem(int location) {
        return feedItems.get(location);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (inflater == null)
            inflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (convertView == null)
            convertView = inflater.inflate(R.layout.feed_item, null);

        if (imageLoader == null)
            imageLoader = AppController.getInstance().getImageLoader();

        TextView name = (TextView) convertView.findViewById(R.id.txtname);
        TextView date = (TextView) convertView
                .findViewById(R.id.txtdate);
        TextView statusMsg = (TextView) convertView
                .findViewById(R.id.txtStatusMsg);


        TextView order_type = (TextView) convertView.findViewById(R.id.txtOrderType);
        TextView pair = (TextView) convertView.findViewById(R.id.txtPair);
        TextView rate = (TextView) convertView.findViewById(R.id.txtRate);
        TextView quick_target = (TextView) convertView.findViewById(R.id.txtQuick_Target);
        TextView long_target = (TextView) convertView.findViewById(R.id.txtLong_Target);
        TextView stop_loss = (TextView) convertView.findViewById(R.id.txtStop_Loss);
        TextView break_even = (TextView) convertView.findViewById(R.id.txtBreak_Even);
        NetworkImageView profilePic = (NetworkImageView) convertView.findViewById(R.id.profilePic);
        FeedImageView feedImageView = (FeedImageView) convertView
                .findViewById(R.id.feedImage1);

        FeedItem item = feedItems.get(position);

        name.setText(item.getName());
        date.setText(item.getDate());
        order_type.setText(item.getOrder_type());
        pair.setText(item.getPair());
        rate.setText(item.getRate());
        quick_target.setText(item.getQuick_target());
        long_target.setText(item.getLong_target());
        stop_loss.setText(item.getStop_loss());
        break_even.setText(item.getBreak_Even());

        //Converting timestamp into x ago format - removed timeStamp - using date
        //CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(
                //Long.parseLong(item.getTimeStamp()),
                //System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
        //timestamp.setText(timeAgo);

        // Chcek for empty status message
        if (!TextUtils.isEmpty(item.getStatus())) {
            statusMsg.setText(item.getStatus());
            statusMsg.setVisibility(View.VISIBLE);
        } else {
            // status is empty, remove from view
            statusMsg.setVisibility(View.GONE);
        }

        // Checking for null feed url
        //if (item.getUrl() != null) {
            //url.setText(Html.fromHtml("<a href=\"" + item.getUrl() + "\">"
                    //+ item.getUrl() + "</a> "));

            // Making url clickable
            //url.setMovementMethod(LinkMovementMethod.getInstance());
            //url.setVisibility(View.VISIBLE);
        //} else {
            // url is null, remove from the view
            //url.setVisibility(View.GONE);
        //}
        // user profile pic
        profilePic.setImageUrl(item.getProfilePic(), imageLoader);

        // Feed image
        if (item.getImge() != null) {
            feedImageView.setImageUrl(item.getImge(), imageLoader);
            feedImageView.setVisibility(View.VISIBLE);
            feedImageView
                    .setResponseObserver(new FeedImageView.ResponseObserver() {
                        @Override
                        public void onError() {
                        }

                        @Override
                        public void onSuccess() {
                        }
                    });
        } else {
            feedImageView.setVisibility(View.GONE);
        }

        return convertView;
    }

您还需要将数据设置为FeedItem&amp;在Arraylist中添加它

    private void MakeJsonArrayReq() {
        PD.show();

        JsonArrayRequest jreq = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {

            @Override
            public void onResponse(JSONArray response) {

                for (int i = 0; i < response.length(); i++) {
                    try {
                        JSONObject jo = response.getJSONObject(i);
                        String date = jo.getString("date");
                        String order = jo.getString("order");
                        String pair = jo.getString("pair");
                        String rate = jo.getString("rate");
                        String quick_target = jo.getString("quick_target");
                        String long_target = jo.getString("long_target");
                        String stop_loss = jo.getString("stop_loss");
                        String break_even = jo.getString("break_even");
                        String name = jo.getString("name");
                        String status = jo.getString("status");
                        String profilePic = jo.getString("profilePic");
                        String image = jo.isNull("image")? null : jo.getString("image");

    FeedItem  item = new FeedItem ();
item.setOrder(order);
item.setName(name);
//like this dont know about method name of item                      
                        feedItems.add(item);


                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                PD.dismiss();
// set adapter here
                 listadapter = new FeedListAdapter(this, feedItems);
    listView.setAdapter(listadapter);
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });

        AppController.getInstance().addToRequestQueue(jreq, "jreq");
    }

答案 1 :(得分:0)

因为您在feedItems

上没有任何内容

首先调用您的方法来填充您的Feeditems。

MakeJsonArrayReq(); 
listadapter = new FeedListAdapter(this, feedItems);
listView.setAdapter(listadapter);

答案 2 :(得分:0)

更改

public FeedListAdapter(Activity activity, ArrayList<FeedItem> feedItems) {
    this.activity = activity;
    this.feedItems = feedItems;
}

public FeedListAdapter(AlertMainActivity activity, ArrayList<String> feedItems) {

}  

public FeedListAdapter(Activity activity, ArrayList<FeedItem> feedItems) {

}

public FeedListAdapter(AlertMainActivity activity, ArrayList<String> feedItems) {
    this.activity = activity;
    this.feedItems = feedItems;
}