我想要创建自己的记事本,类似于Android网站上的教程。当我尝试运行我的应用程序时,Eclipse打开新选项卡-“ activitythread.performlaunchactivity(activitythread $ activityclientrecord intent)行:2059”,并声明“找不到源。编辑源查找路径...”。有我的代码:

package com.notatnik;

import android.annotation.SuppressLint;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class MainActivity extends ListActivity {

    private NotesDB mDB;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mDB = new NotesDB(this);
        mDB.open();
        fillData();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    public void saveNote(View view) {
        TextView textField = (TextView) findViewById(R.id.editText1);
        String note = textField.getText().toString();
        mDB.createNote(note);
    }

    @SuppressLint("NewApi")
    private void fillData() {
        Cursor cursor = mDB.fetchAllNotes();
        startManagingCursor(cursor);

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item_list, cursor,
            new String[] {NotesDB.COLUMN_CONTENT}, new int[] {R.id.textView_content}, 0);
        ListView listView = (ListView) findViewById(R.id.list);
        listView.setAdapter(adapter);
    }
}


Logcat:

    02-07 17:28:40.622: D/AndroidRuntime(2600): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
02-07 17:28:40.622: D/AndroidRuntime(2600): CheckJNI is ON
02-07 17:28:40.662: D/dalvikvm(2600): Trying to load lib libjavacore.so 0x0
02-07 17:28:40.672: D/dalvikvm(2600): Added shared lib libjavacore.so 0x0
02-07 17:28:40.702: D/dalvikvm(2600): Trying to load lib libnativehelper.so 0x0
02-07 17:28:40.702: D/dalvikvm(2600): Added shared lib libnativehelper.so 0x0
02-07 17:28:41.463: D/AndroidRuntime(2600): Calling main entry com.android.commands.pm.Pm
02-07 17:28:41.513: D/AndroidRuntime(2600): Shutting down VM
02-07 17:28:41.523: D/dalvikvm(2600): GC_CONCURRENT freed 101K, 78% free 466K/2048K, paused 1ms+2ms, total 14ms
02-07 17:28:41.523: D/dalvikvm(2600): Debugger has detached; object registry had 1 entries
02-07 17:28:42.152: D/AndroidRuntime(2613): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
02-07 17:28:42.152: D/AndroidRuntime(2613): CheckJNI is ON
02-07 17:28:42.203: D/dalvikvm(2613): Trying to load lib libjavacore.so 0x0
02-07 17:28:42.212: D/dalvikvm(2613): Added shared lib libjavacore.so 0x0
02-07 17:28:42.242: D/dalvikvm(2613): Trying to load lib libnativehelper.so 0x0
02-07 17:28:42.242: D/dalvikvm(2613): Added shared lib libnativehelper.so 0x0
02-07 17:28:43.113: D/AndroidRuntime(2613): Calling main entry com.android.commands.am.Am
02-07 17:28:43.153: I/ActivityManager(148): Force stopping package com.notatnik uid=10044
02-07 17:28:43.153: I/ActivityManager(148): Killing proc 2260:com.notatnik/u0a44: force stop
02-07 17:28:43.203: I/ActivityManager(148): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.notatnik/.MainActivity u=0} from pid 2613
02-07 17:28:43.334: D/dalvikvm(148): GC_FOR_ALLOC freed 260K, 9% free 11697K/12743K, paused 89ms, total 99ms
02-07 17:28:43.334: W/InputMethodManagerService(148): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@415cb158 attribute=null
02-07 17:28:43.422: D/AndroidRuntime(2613): Shutting down VM
02-07 17:28:43.422: D/dalvikvm(2632): Not late-enabling CheckJNI (already on)
02-07 17:28:43.442: D/dalvikvm(2613): GC_CONCURRENT freed 102K, 76% free 492K/2048K, paused 1ms+2ms, total 15ms
02-07 17:28:43.442: D/jdwp(2613): Got wake-up signal, bailing out of select
02-07 17:28:43.442: D/dalvikvm(2613): Debugger has detached; object registry had 1 entries
02-07 17:28:43.453: I/AndroidRuntime(2613): NOTE: attach of thread 'Binder_3' failed
02-07 17:28:43.472: I/ActivityManager(148): Start proc com.notatnik for activity com.notatnik/.MainActivity: pid=2632 uid=10044 gids={1028}
02-07 17:28:43.843: E/Trace(2632): error opening trace file: No such file or directory (2)
02-07 17:28:43.872: W/ActivityThread(2632): Application com.notatnik is waiting for the debugger on port 8100...
02-07 17:28:43.892: I/System.out(2632): Sending WAIT chunk
02-07 17:28:43.902: I/dalvikvm(2632): Debugger is active
02-07 17:28:44.092: I/System.out(2632): Debugger has connected
02-07 17:28:44.092: I/System.out(2632): waiting for debugger to settle...
02-07 17:28:44.293: I/System.out(2632): waiting for debugger to settle...
02-07 17:28:44.503: I/System.out(2632): waiting for debugger to settle...
02-07 17:28:44.703: I/System.out(2632): waiting for debugger to settle...
02-07 17:28:44.915: I/System.out(2632): waiting for debugger to settle...
02-07 17:28:45.125: I/System.out(2632): waiting for debugger to settle...
02-07 17:28:45.325: I/System.out(2632): waiting for debugger to settle...
02-07 17:28:45.569: I/System.out(2632): waiting for debugger to settle...
02-07 17:28:45.785: I/System.out(2632): debugger has settled (1452)
02-07 17:28:53.385: W/ActivityManager(148): Launch timeout has expired, giving up wake lock!
02-07 17:28:53.814: W/ActivityManager(148): Activity idle timeout for ActivityRecord{413ede80 com.notatnik/.MainActivity}
02-07 17:29:00.092: D/dalvikvm(2632): Debugger has detached; object registry had 312 entries
02-07 17:29:00.092: D/AndroidRuntime(2632): Shutting down VM
02-07 17:29:00.102: W/dalvikvm(2632): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
02-07 17:29:00.152: E/AndroidRuntime(2632): FATAL EXCEPTION: main
02-07 17:29:00.152: E/AndroidRuntime(2632): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.notatnik/com.notatnik.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
02-07 17:29:00.152: E/AndroidRuntime(2632):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at android.os.Looper.loop(Looper.java:137)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at android.app.ActivityThread.main(ActivityThread.java:4745)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at java.lang.reflect.Method.invokeNative(Native Method)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at java.lang.reflect.Method.invoke(Method.java:511)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at dalvik.system.NativeStart.main(Native Method)
02-07 17:29:00.152: E/AndroidRuntime(2632): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
02-07 17:29:00.152: E/AndroidRuntime(2632):     at android.app.ListActivity.onContentChanged(ListActivity.java:243)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:259)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at android.app.Activity.setContentView(Activity.java:1867)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at com.notatnik.MainActivity.onCreate(MainActivity.java:20)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at android.app.Activity.performCreate(Activity.java:5008)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
02-07 17:29:00.152: E/AndroidRuntime(2632):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
02-07 17:29:00.152: E/AndroidRuntime(2632):     ... 11 more
02-07 17:29:00.232: W/ActivityManager(148):   Force finishing activity com.notatnik/.MainActivity
02-07 17:29:00.422: D/dalvikvm(148): GC_FOR_ALLOC freed 342K, 8% free 11758K/12743K, paused 100ms, total 115ms
02-07 17:29:00.986: W/ActivityManager(148): Activity pause timeout for ActivityRecord{413ede80 com.notatnik/.MainActivity}
02-07 17:29:01.263: W/EGL_emulation(279): eglSurfaceAttrib not implemented


我尚未完成,但是我认为应该编译此简单代码。我发现问题是fillData()方法中的SimpleCursorAdapter,但是我不知道出了什么问题。我乞求Android程式设计。对不起,我的英语不好...

最佳答案

从您的LogCat:

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


这意味着在res/layout/activity_main.xml中,您的ListView必须具有以下属性:

<ListView
    android:id="@android:id/list"
    ... />

07-27 13:57