Basic disclaimer; I am new to mobile app programming in general, and android in particular.
I have a button that, when clicked, should open the next activity:
bCustom.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent i = new Intent(ctx, DiceCustomList.class);
startActivity(i);
}
});
(where "private Context ctx = this;" because putting "this" where "ctx" is did not get the context when inside onClick)
The program crashes before the current activity is obscured (though I'm not sure how transitions affect this). After commenting out nearly everything, here's the activity it's calling:
public class DiceCustomList extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_list);
}
}
And custom_list.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:text="@string/rollText"
android:id="@+id/textRoll2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="11pt"
android:gravity="center"/>
<ListView android:layout_height="wrap_content"
android:id="@+id/listView1"
android:layout_width="fill_parent"/>
</LinearLayout>
I think the problem lies in the button code, but I can't seem to get closer to the answer than that.
Edit: The android manifest file does have:
<activity android:name=".DiceCustomList"></activity>
Edit 2: Ah, after finally finding where Eclipse hides the stacktrace, it told me this: "Your content must have a ListView whose id attribute is 'android.R.id.list'", by which they actually mean "@+id/android:list". Well, that was interesting. (Edit3: By which I mean, it was the answer. Thanks for the prompting.)
Check to make sure the DiceCustomList activity has an entry in the manifest XML file.
(where "private Context ctx = this;" because putting "this" where "ctx" is did not get the context when inside onClick)
You may use YourActivity.this to get the context. Simple 'this' does not work because inside this method it points to OnClickListener object.
Can you please give us a LogCat error logs?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With