运行时异常必须包括列表视图与属性android.R.id.list视图、属性、异常、列表

2023-09-04 03:41:52 作者:偏执狂

我的程序包含一个ListView用于检索数据库中的数据。但是code不工作。在XML文件和logcat中给出below.pls帮助我。   我的程序包含一个ListView用于检索数据库中的数据。但是code不工作。在XML文件和logcat中给出below.pls帮我

 包example.showevent1;

进口android.app.ListActivity;
进口android.content.Intent;
进口android.database.Cursor;
进口android.os.Bundle;
进口android.support.v4.widget.SimpleCursorAdapter;
进口android.widget.ListView;

类Getclicker扩展ListActivity {
    意向意图= getIntent();
    字符串DATEVALUE = intent.getStringExtra(FirstActivity.EXTRA_MESSAGE);
    字符串Userselectvalue = intent.getStringExtra(FirstActivity.EXTRA_MESSAGE1);
    classdbOpenHelper eventsData1;
    光标光标1;

    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_first); / *串DATEVALUE = date.getText()的toString();
        字符串Userselectvalue = userSelection.getText()的toString()。

        字符串showevent = eventsData.getContact(DATEVALUE,Userselectvalue);
        show.setText(showevent); * /

         光标1 = eventsData1.getContact(DATEVALUE,Userselectvalue);
         的String [] fromColumns = {classdbOpenHelper.KEY_EVENT};
         INT [] toViews = {R.id.event};
         SimpleCursorAdapter适配器=新SimpleCursorAdapter(此,R.layout.events,光标1,fromColumns,toViews,0);
         ListView控件的ListView =(ListView控件)findViewById(android.R.id.list);
         listView.setAdapter(适配器);
        }

    公共无效的onDestroy(){
        eventsData1.close();
      }

}
 

  

activity_first.xml

 < RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:paddingBottom会=@扪/ activity_vertical_margin
    机器人:以下属性来=@扪/ activity_horizo​​ntal_margin
    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
    机器人:paddingTop =@扪/ activity_vertical_margin
    机器人:背景=@色/ color_1
    工具:上下文=FirstActivity。>

    <按钮
        机器人:ID =@ + ID /按钮2
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignBaseline =@ + ID / editText1
        机器人:layout_alignBottom =@ + ID / editText1
        机器人:layout_alignParentRight =真
        机器人:文本=@字符串/ _add/>

    <的TextView
        机器人:ID =@ + ID / textView4
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignRight =@ + ID /按钮1
        机器人:layout_alignTop =@ + ID /按钮2
        机器人:文本=添加事件/>

    <的TextView
        机器人:ID =@ + ID / textView5
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentBottom =真
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_marginBottom =22dp
        机器人:后台=#FFFFFF
        机器人:文本=/>

    <按钮
        机器人:ID =@ + ID /按钮3
        风格=机器人:ATTR / buttonStyleSmall
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_above =@ + ID / textView5
        机器人:layout_alignLeft =@ + ID / textView5
        机器人:layout_marginBottom =22dp
        机器人:文本=ShowEvent/>

    <的EditText
        机器人:ID =@ + ID / editText1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_above =@ + ID /按钮3
        机器人:layout_alignLeft =@ + ID /按钮3
        机器人:layout_marginBottom =17dp
        机器人:后台=#FFFFFF
        机器人:EMS =10>

        <不是requestFocus />
    < /的EditText>

    <微调
        机器人:ID =@ + ID / spinner1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_above =@ + ID / textView1
        机器人:layout_alignParentLeft =真
        机器人:layout_marginBottom =16DP
        机器人:后台=#FFFFFF
        机器人:文字颜色=#b22924/>

    <的TextView
        机器人:ID =@ + ID / textView1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_above =@ + ID /按钮1
        机器人:layout_marginBottom =28dp
        机器人:文本=@字符串/选择
        机器人:textAlignment =万有引力
        机器人:文字颜色=#b22924
        机器人:TEXTSIZE =20SP
        机器人:TEXTSTYLE =黑体/>

    <的TextView
        机器人:ID =@ + ID / textView2
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignBaseline =@ + ID /按钮1
        机器人:layout_alignBottom =@ + ID /按钮1
        机器人:layout_alignRight =@ + ID /按钮2
        机器人:后台=#FFFFFF
        机器人:文本=中文字
        机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceLarge?

    <的TextView
        机器人:ID =@ + ID / textView3
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_above =@ + ID / spinner1
        机器人:layout_alignParentLeft =真
        机器人:layout_marginBottom =22dp
        机器人:文本=选择一个地方/>

    <按钮
        机器人:ID =@ + ID /按钮1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_above =@ + ID / textView4
        机器人:layout_alignLeft =@ + ID / textView1
        机器人:layout_marginBottom =38dp
        机器人:文本=@字符串/ DT/>
  < ListView的机器人:ID =@ + ID /列表
         机器人:layout_width =FILL_PARENT
         机器人:layout_height =FILL_PARENT/>

< / RelativeLayout的>
 

  

events.xml

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:方向=垂直
    机器人:填充=6dip>

    <的TextView
        机器人:ID =@ + ID /事件
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文本=TextView的/>
< / RelativeLayout的>
 
如何设置新建Android默认linearlayout

  

logcat的

  6月八日至7日:46:14.565:E / AndroidRuntime(3633):致命异常:主要
6月8日至7日:46:14.565:E / AndroidRuntime(3633):java.lang.RuntimeException的:无法启动的活动ComponentInfo {example.showevent1 / example.showevent1.FirstActivity}:java.lang.RuntimeException的:你的内容必须有一个ListView控件的ID属性为'android.R.id.list
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在android.app.ActivityThread.access $ 600(ActivityThread.java:141)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1234)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在android.os.Handler.dispatchMessage(Handler.java:99)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在android.os.Looper.loop(Looper.java:137)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在android.app.ActivityThread.main(ActivityThread.java:5041)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在java.lang.reflect.Method.invokeNative(本机方法)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在java.lang.reflect.Method.invoke(Method.java:511)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在dalvik.system.NativeStart.main(本机方法)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):java.lang.RuntimeException的:你的内容必须有一个ListView,其id属性是'android.R.id.list产生的原因
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在android.app.ListActivity.onContentChanged(ListActivity.java:243)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在android.app.Activity.setContentView(Activity.java:1881)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在example.showevent1.FirstActivity.onCreate(FirstActivity.java:56)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在android.app.Activity.performCreate(Activity.java:5104)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
6月8日至7日:46:14.565:E / AndroidRuntime(3633):11 ...更多
 

解决方案

每一个ListActivity需要一个默认的ListView ID它是你的ListView ID的布局定义,以便来代替:

 < ListView的机器人:ID =@ + ID /列表
     机器人:layout_width =FILL_PARENT
     机器人:layout_height =FILL_PARENT/>
 

使用:

 < ListView的机器人:ID =@机器人:ID /列表
     机器人:layout_width =FILL_PARENT
     机器人:layout_height =FILL_PARENT/>
 

my program contains a listview for retrieving database data . but the code is not working. the xml files and logcat are given below.pls help me. my program contains a listview for retrieving database data . but the code is not working. the xml files and logcat are given below.pls help me

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>

events.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>

logcat

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

解决方案

Every ListActivity needs a default ListView id in it's layout definition so instead of your ListView id :

<ListView android:id="@+id/list"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"/>

use :

<ListView android:id="@android:id/list"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"/>