i’m new at android development and have a question about a lst view.
I’m starting a new projekt and then open the main.xml and add a lied view.
the main activity looks like:
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ListView lv = (ListView)findViewById(R.id.listView1);
lv.setAdapter(ArrayAdapter.createFromResource(getBaseContext(), R.array.titles, R.layout.list_item));
setContentView(R.layout.main);
}
}
In R.array.titles i have the string array and in R.layout.list_item I have a single textview.
now everytime i start the app in debugging mode i get the following output:
01-06 09:39:17.193: W/dalvikvm(367): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
01-06 09:39:17.202: E/AndroidRuntime(367): Uncaught handler: thread main exiting due to uncaught exception
01-06 09:39:17.402: E/AndroidRuntime(367): java.lang.RuntimeException: Unable to start activity ComponentInfo{meine.app/meine.app.MainActivity}: java.lang.NullPointerException
01-06 09:39:17.402: E/AndroidRuntime(367): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
what is wrong here?
You must call the
setContent(R.layout.main);
prior to intanciating the listView.