-1

我正在解决一个简单的待办事项应用程序的代码路径预处理问题。我创建了一个侦听器,这样当单击 Adapter Holder 时,它将打开另一个可以编辑项目的编辑活动,但问题是它显示 ActivityNotFoundException 错误

这是部分清单文件


    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.SimpleToDo"
        tools:ignore="ExtraText">
        <activity android:name=".EditActivity" >
            <intent-filter>
                    <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

单击监听器


 ItemsAdapter.OnClickListener onClickListener = new ItemsAdapter.OnClickListener() {
            @Override
            public void onItemClicked(int position) {
                Log.d("MainActivity","Single Click poistion :  " + position);
                // Create new activity
                Intent intent = new Intent(MainActivity.this, EditText.class);
                // pass the data being edited
                intent.putExtra(KEY_ITEM_TEXT, items.get(position));                
                intent.putExtra(KEY_ITEM_POSITION, position);
                // display the activity
                try {
                    /* your code */
                    startActivity(intent);
                } catch ( ActivityNotFoundException e) {
                    e.printStackTrace();
                }

            }
        };

日志文件

W/System.err: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.sam.simpletodo/android.widget.EditText}; have you declared this activity in your AndroidManifest.xml?
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1933)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1616)
        at android.app.Activity.startActivityForResult(Activity.java:4487)
        at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:597)
        at android.app.Activity.startActivityForResult(Activity.java:4445)
        at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:583)
        at android.app.Activity.startActivity(Activity.java:4806)
        at android.app.Activity.startActivity(Activity.java:4774)
        at com.sam.simpletodo.MainActivity$2.onItemClicked(MainActivity.java:72)
        at com.sam.simpletodo.ItemsAdapter$ViewHolder$1.onClick(ItemsAdapter.java:81)
        at android.view.View.performClick(View.java:6294)
W/System.err:     at android.view.View$PerformClick.run(View.java:24770)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

可以在这里找到我的完整仓库 https://github.com/amanTHEBreaker/Google-Search-Fetcher-using-serpapi

4

2 回答 2

1

你试图去EditText而不是EditActivity

代替

Intent intent = new Intent(MainActivity.this, EditText.class);

Intent intent = new Intent(MainActivity.this, EditActivity.class);
于 2021-08-22T07:09:43.563 回答
1

您的活动名称是“EditActivity”,但您正在为“EditText”创建 Intent。

于 2021-08-22T07:11:20.587 回答