Well, I’ve got an application that crashes on load up because of a setContentView line.
Now before you ask, its when I comment out the setContentView line on line 15 or so that I get a working app. But the moment I place it in, it errors. Now this is using 2.1-update1 android.
Java:
package com.clark.listview;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class listview extends ListActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
//setContentView(R.layout.main);
// Create an array of Strings, that will be put to our ListActivity
String[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse",
"Ubuntu", "Solaris", "Android", "iPhone", "ClarkPhone" };
// Use your own layout and point the adapter to the UI elements which
// contains the label
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.rowlayout,
R.id.label, names));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// Get the item that was clicked
Object o = this.getListAdapter().getItem(position);
String keyword = o.toString();
Toast.makeText(this, "You selected: " + keyword, Toast.LENGTH_LONG)
.show();
if (keyword.startsWith("Windows7") || keyword.startsWith("iPhone")
|| keyword.startsWith("Solaris")) {
launchTest();
}
}
protected void launchTest() {
Intent i = new Intent(this, home.class);
startActivity(i);
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:cacheColorHint="#00000000"
android:background="@drawable/bg">
</LinearLayout>
If your
Activityis extending theListActivityclass then ensure that your main layout file must contain aListViewelement as given below.your application is crashing because you are setting an adapter to ListView which is indeed not exist in your layout file.
See the documentation : http://developer.android.com/reference/android/app/ListActivity.html