单击 View Holder 时出现 ActivityNotFoundException 错误

ActivityNotFoundException Error while single click on View Holder

我正在解决一个 Simple todo 应用程序的代码路径准备工作问题。我创建了一个侦听器,这样当单击 Adapter Holder 时,它将打开另一个编辑 activity,可以在其中编辑项目,但问题是它显示 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.onItemClicked(MainActivity.java:72)
        at com.sam.simpletodo.ItemsAdapter$ViewHolder.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

您正在尝试前往 EditText 而不是 EditActivity

替换

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

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

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