0

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
2
  • 1
    Any exception in logcat?
    – laalto
    Mar 4, 2014 at 12:15
  • 1
    Why you set activity_main layout in adapter here ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.activity_main, listIdJson);
    – M D
    Mar 4, 2014 at 12:16

3 Answers 3

2

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);
1
  • @Vlad161 :) np, happens sometimes
    – Pararth
    Mar 4, 2014 at 12:49
2

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

1

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.