Click here to Skip to main content
15,173,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir, I have created an android application with navigation drawer. When the user clicks the application should go for the new activity.For that I have coded this

if (id == {
            Intent intent = new Intent(Main.this, Mathematics.class);

and it shifts to the new activity successfully. I want to add a list view in my new activity for that I have coded like this, for the blank activity inorder to show the list view

public class Mathematics extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {
        String[] classes = {"A1","A2","A3","A4","A5","A6","A7","A8"};
        ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.content_mathematics, classes);

        ListView listView = (ListView) findViewById(;

I have also added list view in the xml file,
     android:layout_height="wrap_content" >

I have build-ed the application with zero warnings and zero errors but when I run the application the app crashes

Kindly help me with this sir

Thank you for your time sir

What I have tried:

I tried running my application using an emulator and the emulator shows black screen for hours. I referred tutorials point and modified the code but still the same case. I couldn't figure out since the application compiled with zero errors.
Updated 2-Jul-16 8:29am
Richard MacCutchan 1-Jul-16 5:19am
You need to use your debugger and the emulator logs to find out where it crashed, and why. We cannot guess what is missing or incorrect.
Richard MacCutchan 1-Jul-16 5:21am
It may be that your adapter variable is being cleaned up when it goes out of scope. Make it a class variable and see if that fixes it.
[no name] 2-Jul-16 13:30pm
Thank you sir I made it to work!

1 solution

Finally made it to work.

String[] topics = new String[]{"A1","A2","A3","A4","A5","A6","A7","A8"};
        ListAdapter adapt = new ArrayAdapter<string>(this,android.R.layout.simple_list_item_1,topics);
        ListView view = (ListView)findViewById(;


Declared String in alternate way(I know both are same)

As suggested by Richard MacCutchan I have Referred current tutorial from Android documentation and modified this line to this,
ArrayAdapter adapter = new ArrayAdapter<string>(this, R.layout.content_mathematics, classes);</string>


ListAdapter adapt = new ArrayAdapter<string>(this,android.R.layout.simple_list_item_1,topics);</string>

I don't need images in this list view so I've set the layout to its basic (simple_list_item_1)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900