2011-07-11 8 views
1

はなく、:ここエラーアンドロイドデータベースは日食に誤りがない

Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 

LogCat出力

07-11 11:09:45.242: WARN/dalvikvm(590): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590): FATAL EXCEPTION: main 
07-11 11:09:45.303: ERROR/AndroidRuntime(590): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.example.events/org.example.events.Events}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at android.app.ActivityThread.access$2300(ActivityThread.java:125) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at android.os.Handler.dispatchMessage(Handler.java:99) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at android.os.Looper.loop(Looper.java:123) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at java.lang.reflect.Method.invokeNative(Native Method) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at java.lang.reflect.Method.invoke(Method.java:521) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at dalvik.system.NativeStart.main(Native Method) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at android.app.ListActivity.onContentChanged(ListActivity.java:245) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at android.app.Activity.setContentView(Activity.java:1647) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at org.example.events.Events.onCreate(Events.java:23) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 
07-11 11:09:45.303: ERROR/AndroidRuntime(590):  ... 11 more 

は、これは私のコードですeventsActivity

package org.example.events; 

//import android.app.Activity; 
import android.app.ListActivity; 
import android.os.Bundle; 
import static android.provider.BaseColumns._ID; 
import static org.example.events.Constants.TABLE_NAME; 
import static org.example.events.Constants.TIME; 
import static org.example.events.Constants.TITLE; 
//import android.app.Activity; 
import android.content.ContentValues; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
//import android.os.Bundle; 
import android.widget.TextView; 

public class Events extends ListActivity { 
    /** Called when the activity is first created. */ 
    private EventsData events; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     events = new EventsData(this); 
     try { 
      addEvent("Hello, Android!"); 
      Cursor cursor = getEvents(); 
      showEvents(cursor); 
     } finally { 
      events.close(); 
     } 
    } 

    private void addEvent(String string) { 
     // Insert a new record into the Events data source. 
     // You would do something similar for delete and update. 
     SQLiteDatabase db = events.getWritableDatabase(); 
     ContentValues values = new ContentValues(); 
     values.put(TIME, System.currentTimeMillis()); 
     values.put(TITLE, string); 
     db.insertOrThrow(TABLE_NAME, null, values); 
    } 

    private static String[] FROM = { _ID, TIME, TITLE, }; 
    private static String ORDER_BY = TIME + " DESC"; 
    private Cursor getEvents() { 
     // Perform a managed query. The Activity will handle closing 
     // and re-querying the cursor when needed. 
     SQLiteDatabase db = events.getReadableDatabase(); 
     Cursor cursor = db.query(TABLE_NAME, FROM, null, null, null, 
     null, ORDER_BY); 
     startManagingCursor(cursor); 
     return cursor; 
    } 

    private void showEvents(Cursor cursor) { 
     // Stuff them all into a big string 
     StringBuilder builder = new StringBuilder("Saved events:\n"); 
     while (cursor.moveToNext()) { 
      // Could use getColumnIndexOrThrow() to get indexes 
      long id = cursor.getLong(0); 
      long time = cursor.getLong(1); 
      String title = cursor.getString(2); 
      builder.append(id).append(": "); 
      builder.append(time).append(": "); 
      builder.append(title).append("\n"); 
     } 
     // Display on the screen 
     TextView text = (TextView) findViewById(R.id.text); 
     text.setText(builder); 
} 

    /*private static int[] TO = { R.id.rowid, R.id.time, R.id.title, }; 
    private void showEvents(Cursor cursor) { 
     // Set up data binding 
     SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item, cursor, FROM, TO); 
     setListAdapter(adapter); 
    }*/ 
} 

。ここ

012マニフェストイベントがありますここで
<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="org.example.events" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="8" /> 

    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".Events" 
       android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <activity android:name=".Constants" 
        android:label="@string/app_name"> 

     </activity> 

     <activity android:name=".EventsData" 
        android:label="@string/app_name"> 

     </activity> 

    </application> 
</manifest> 

は私のレイアウトmain.xml

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <TextView 
     android:id="@+id/text" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
</ScrollView> 
+1

コードなしで想像するとどう思いますか?いくつかのコードを提供してください... – barmaley

答えて

0

右はあなたのlogcatの最上部にある:

Unable to start activity ... 
Your content must have a ListView whose id attribute is 'android.R.id.list' 

あなたの活動は、そのIDでListViewコントロールを持っていますか?

+0

私はまだ私はあなたのコードを提供していないことを理解していないthx – sayvortana

+1

@sayvあなたの提供されたコードには、関連する部分は含まれていません。エラーをスローするアクティビティからレイアウトXMLを入力してください。 – Farray

+0

すべてはあなたの解決に役立ちます:) – sayvortana

0

IDが 'list'の要素に加えて、レイアウトXMLファイルにIDが 'empty'のものを含めることができます - すると、Android wilには、 'ListViewに何も表示されていないとき。