简体   繁体   中英

data not displaying in my listview

Actually i was trying JSON parsing and the data which is parsed not displaying in the listview. I was running using an emulator got the following error in logcat. I am not able to find the mistake.Can anyone help?

ListStartActivity

public class ListStartActivity extends Activity{

    int start =0;
    int limit =10;
    boolean loadingMore = false;

    ListView lv;
    SimpleAdapter adpt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.business);
        adpt = new SimpleAdapter(new ArrayList<Lists>(), this);

        lv = (ListView)findViewById(R.id.listView);
        lv.setAdapter(adpt);
        lv.setTextFilterEnabled(true);
        (new AsyncListViewLoader()).execute("http://10.0.2.2:8080/ListDetails/list_details/");
    }

    private class AsyncListViewLoader extends AsyncTask<String, Void, List<Lists>>{

        private final ProgressDialog dialog = new ProgressDialog(ListStartActivity.this);
        private String address;
        private String name;

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
            dialog.setMessage("Downloading details.....");
            dialog.show();
        }

        @Override
        protected void onPostExecute(List<Lists> result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            dialog.dismiss();
            adpt.setItemList(result);
            adpt.notifyDataSetChanged();
        }

        @Override
        protected List<Lists> doInBackground(String... params) {
            // TODO Auto-generated method stub
            List<Lists> result = new ArrayList<Lists>();

            try{
                URL u = new URL(params[0]);
                HttpURLConnection conn = (HttpURLConnection) u.openConnection();
                conn.setRequestMethod("POST");
                conn.connect();
                InputStream is = conn.getInputStream();
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                StringBuilder sb = new StringBuilder();
                String line = null;
                while((line = reader.readLine()) != null){
                    sb.append(line + "\n");
                }is.close();
                //result = sb.toString();
                JSONArray jArray = new JSONArray(result);
                for(int i=0; i<jArray.length(); i++){
                    JSONObject json_data = jArray.getJSONObject(i);

                    Lists ls = new Lists(name,address);
                    ls.setName(json_data.getString(name));
                    ls.setAddress(json_data.getString(address));
                    result.add(ls);

                }
                  return result;
            }catch(Throwable t){
                t.printStackTrace();
            }

            return null;
        }
    }
}

SimpleAdapter

public class SimpleAdapter extends ArrayAdapter<Lists>{

    private List<Lists> itemList;
    private Context context;

    public SimpleAdapter(List<Lists> itemList, Context ctx) {
        super(ctx, android.R.layout.simple_list_item_2, itemList);
        // TODO Auto-generated constructor stub
        this.itemList = itemList;
        this.context = ctx;
    }

    public int getCount(){
        if(itemList != null)
            return itemList.size();
        return 0;
    }

    public Lists getItem(int position){
        if(itemList != null)
            return itemList.get(position);
        return null;
    }

    public long getItemId(int position){
        if(itemList != null)
            return itemList.get(position).hashCode();
        return 0;
    }

    @SuppressLint("InflateParams")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        View v = convertView;
        if(v == null){
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = inflater.inflate(R.layout.lists, null);
        }
        Lists l = itemList.get(position);
        TextView text1 = (TextView)v.findViewById(R.id.name);
        text1.setText(l.getName());

        TextView text2 = (TextView)v.findViewById(R.id.address);
        text2.setText(l.getAddress());

        return v;
    }

    public List<Lists> getItemList(){
        return itemList;
    }

    public void setItemList(List<Lists> itemList){

        this.itemList = itemList;
        System.out.println("Set Items List: "+itemList);
    }
}

Logcat

10-24 10:44:02.323: A/NetworkStats(90): problem reading network stats
10-24 10:44:02.323: A/NetworkStats(90): java.lang.IllegalStateException: problem parsing line: null
10-24 10:44:02.323: A/NetworkStats(90):     at com.android.internal.net.NetworkStatsFactory.readNetworkStatsDetail(NetworkStatsFactory.java:313)
10-24 10:44:02.323: A/NetworkStats(90):     at com.android.server.NetworkManagementService.getNetworkStatsUidDetail(NetworkManagementService.java:1271)
10-24 10:44:02.323: A/NetworkStats(90):     at com.android.server.net.NetworkStatsService.performPollLocked(NetworkStatsService.java:810)
10-24 10:44:02.323: A/NetworkStats(90):     at com.android.server.net.NetworkStatsService.performPoll(NetworkStatsService.java:771)
10-24 10:44:02.323: A/NetworkStats(90):     at com.android.server.net.NetworkStatsService.access$100(NetworkStatsService.java:128)
10-24 10:44:02.323: A/NetworkStats(90):     at com.android.server.net.NetworkStatsService$3.onReceive(NetworkStatsService.java:610)
10-24 10:44:02.323: A/NetworkStats(90):     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
10-24 10:44:02.323: A/NetworkStats(90):     at android.os.Handler.handleCallback(Handler.java:605)
10-24 10:44:02.323: A/NetworkStats(90):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-24 10:44:02.323: A/NetworkStats(90):     at android.os.Looper.loop(Looper.java:137)
10-24 10:44:02.323: A/NetworkStats(90):     at android.os.HandlerThread.run(HandlerThread.java:60)
10-24 10:44:02.323: A/NetworkStats(90): Caused by: java.io.FileNotFoundException: /proc/net/xt_qtaguid/stats: open failed: ENOENT (No such file or directory)
10-24 10:44:02.323: A/NetworkStats(90):     at libcore.io.IoBridge.open(IoBridge.java:406)
10-24 10:44:02.323: A/NetworkStats(90):     at java.io.FileInputStream.<init>(FileInputStream.java:78)
10-24 10:44:02.323: A/NetworkStats(90):     at java.io.FileReader.<init>(FileReader.java:42)
10-24 10:44:02.323: A/NetworkStats(90):     at com.android.internal.net.NetworkStatsFactory.readNetworkStatsDetail(NetworkStatsFactory.java:272)
10-24 10:44:02.323: A/NetworkStats(90):     ... 10 more
10-24 10:44:02.323: A/NetworkStats(90): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
10-24 10:44:02.323: A/NetworkStats(90):     at libcore.io.Posix.open(Native Method)
10-24 10:44:02.323: A/NetworkStats(90):     at libcore.io.BlockGuardOs.open(BlockGuardOs.java:98)
10-24 10:44:02.323: A/NetworkStats(90):     at libcore.io.IoBridge.open(IoBridge.java:390)
10-24 10:44:02.323: A/NetworkStats(90):     ... 13 more

您可以尝试在清单中添加以下行吗?

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM