Question

I make programm, parse JSON text and output to ListView, but the app crash after the execution all code, why?

 @TargetApi(Build.VERSION_CODES.GINGERBREAD)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d(TAG, "Make app");

        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);

        ListView lv = (ListView) findViewById(R.id.listView);
        ArrayList<String> listIdJson = idJsonList();  //get ArrayList          

        Log.d(TAG, "oN1");
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                    R.layout.activity_main, listIdJson);
        lv.setAdapter(adapter);

        Log.d(TAG, "oN exit");

    }

Log output:

03-04 06:30:50.056    1484-1484/ru.vlad.pbj D/myLogs﹕ Make app
03-04 06:30:51.826    1484-1484/ru.vlad.pbj D/myLogs﹕ oN1
03-04 06:30:51.826    1484-1484/ru.vlad.pbj D/myLogs﹕ oN exit
Was it helpful?

Solution

You are passing the same layout to:

setContentView(R.layout.activity_main);  

And,

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                    R.layout.activity_main, listIdJson);

OTHER TIPS

Change this

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                R.layout.activity_main, listIdJson);

to

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, listIdJson);

For more information to go: http://www.vogella.com/tutorials/AndroidListView/article.html

You cannot set content view for Array Adapter you may change it as follows.

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, listIdJson);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top