我的程序包含一个用于检索数据库数据的列表视图。但代码不起作用。下面给出了 xml 文件和 logcat。请帮助我。我的程序包含一个用于检索数据库数据的列表视图。但代码不起作用。下面给出了xml文件和logcat。请帮助我
package example.showevent1;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.widget.ListView;
class Getclicker extends ListActivity {
Intent intent = getIntent();
String datevalue = intent.getStringExtra(FirstActivity.EXTRA_MESSAGE);
String Userselectvalue = intent.getStringExtra(FirstActivity.EXTRA_MESSAGE1);
classdbOpenHelper eventsData1;
Cursor cursor1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first); /*String datevalue = date.getText().toString();
String Userselectvalue = userSelection.getText().toString();
String showevent = eventsData.getContact(datevalue,Userselectvalue);
show.setText(showevent);*/
cursor1 = eventsData1.getContact(datevalue,Userselectvalue);
String[] fromColumns = {classdbOpenHelper.KEY_EVENT};
int[] toViews = {R.id.event};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.events, cursor1, fromColumns, toViews,0 );
ListView listView = (ListView) findViewById(android.R.id.list);
listView.setAdapter(adapter);
}
public void onDestroy() {
eventsData1.close();
}
}
activity_first.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@color/color_1"
tools:context=".FirstActivity" >
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_alignParentRight="true"
android:text="@string/_add" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button1"
android:layout_alignTop="@+id/button2"
android:text="Add Event" />
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="22dp"
android:background="#ffffff"
android:text="" />
<Button
android:id="@+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView5"
android:layout_alignLeft="@+id/textView5"
android:layout_marginBottom="22dp"
android:text="ShowEvent" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button3"
android:layout_alignLeft="@+id/button3"
android:layout_marginBottom="17dp"
android:background="#ffffff"
android:ems="10" >
<requestFocus />
</EditText>
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="16dp"
android:background="#ffffff"
android:textColor="#b22924" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_marginBottom="28dp"
android:text="@string/select"
android:textAlignment="gravity"
android:textColor="#b22924"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_alignRight="@+id/button2"
android:background="#ffffff"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/spinner1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:text="Select A Place" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView4"
android:layout_alignLeft="@+id/textView1"
android:layout_marginBottom="38dp"
android:text="@string/dt" />
<ListView android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
事件.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="6dip" >
<TextView
android:id="@+id/event"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</RelativeLayout>
日志猫
08-07 06:46:14.565: E/AndroidRuntime(3633): FATAL EXCEPTION: main
08-07 06:46:14.565: E/AndroidRuntime(3633): java.lang.RuntimeException: Unable to start activity ComponentInfo{example.showevent1/example.showevent1.FirstActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
08-07 06:46:14.565: E/AndroidRuntime(3633): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
08-07 06:46:14.565: E/AndroidRuntime(3633): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-07 06:46:14.565: E/AndroidRuntime(3633): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-07 06:46:14.565: E/AndroidRuntime(3633): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-07 06:46:14.565: E/AndroidRuntime(3633): at android.os.Handler.dispatchMessage(Handler.java:99)
08-07 06:46:14.565: E/AndroidRuntime(3633): at android.os.Looper.loop(Looper.java:137)
08-07 06:46:14.565: E/AndroidRuntime(3633): at android.app.ActivityThread.main(ActivityThread.java:5041)
08-07 06:46:14.565: E/AndroidRuntime(3633): at java.lang.reflect.Method.invokeNative(Native Method)
08-07 06:46:14.565: E/AndroidRuntime(3633): at java.lang.reflect.Method.invoke(Method.java:511)
08-07 06:46:14.565: E/AndroidRuntime(3633): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-07 06:46:14.565: E/AndroidRuntime(3633): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-07 06:46:14.565: E/AndroidRuntime(3633): at dalvik.system.NativeStart.main(Native Method)
08-07 06:46:14.565: E/AndroidRuntime(3633): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
08-07 06:46:14.565: E/AndroidRuntime(3633): at android.app.ListActivity.onContentChanged(ListActivity.java:243)
08-07 06:46:14.565: E/AndroidRuntime(3633): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)
08-07 06:46:14.565: E/AndroidRuntime(3633): at android.app.Activity.setContentView(Activity.java:1881)
08-07 06:46:14.565: E/AndroidRuntime(3633): at example.showevent1.FirstActivity.onCreate(FirstActivity.java:56)
08-07 06:46:14.565: E/AndroidRuntime(3633): at android.app.Activity.performCreate(Activity.java:5104)
08-07 06:46:14.565: E/AndroidRuntime(3633): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-07 06:46:14.565: E/AndroidRuntime(3633): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
08-07 06:46:14.565: E/AndroidRuntime(3633): ... 11 more