android studio:找不到显式活动类,但活动已在androidmanifest.xml中声明

k7fdbhmy  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(414)

这里是android studio的新手。
我试着这样做,当我在一个循环视图中点击一个viewholder中的图像时,它会打开另一个活动,从而打开另一个布局。
然而,我得到这个错误,即使我已经在我的清单中声明了活动。
试图创建启动新活动的意图的代码称为类 StaggeredView 内部 app/core/StaggeredView . 调用活动处理程序时 ImageView 内部 app/ImageView .
错误

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.image_chan/android.widget.ImageView}; have you declared this activity in your AndroidManifest.xml?
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2065)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1727)
        at android.app.Activity.startActivityForResult(Activity.java:5320)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:675)
        at android.app.Activity.startActivityForResult(Activity.java:5278)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:662)
        at android.app.Activity.startActivity(Activity.java:5664)
        at android.app.Activity.startActivity(Activity.java:5617)
        at com.example.image_chan.core.StaggeredAdapter$1.onClick(StaggeredAdapter.java:63)
        at android.view.View.performClick(View.java:7448)
        at android.view.View.performClickInternal(View.java:7425)
        at android.view.View.access$3600(View.java:810)
        at android.view.View$PerformClick.run(View.java:28305)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

代码
onbindviewholder(它重写 class StaggeredAdapter which extends RecyclerView.Adapter<StaggeredAdapter.ViewHolder> )

public class StaggeredAdapter extends RecyclerView.Adapter<StaggeredAdapter.ViewHolder> {
    /*...*/
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        RequestOptions requestOptions = new RequestOptions()
                .error(R.drawable.error)
                .placeholder(R.drawable.loader);

        Glide.with(Context)
                .load(urls.get(position))
                .apply(requestOptions)
                .into(holder.image);

        holder.name.setText("SCORE: " + imgNames.get(position));
        holder.image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Context viewContext = (Context) view.getContext();

                Intent toView = new Intent(viewContext, ImageView.class);
                viewContext.startActivity(toView);
            }
        });
    }
    /*...*/
}

androidmanifest.xml文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.image_chan">
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:networkSecurityConfig="@xml/netconfig"
        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.Image_chan">
        <provider android:name=".core.Suggestions"
            android:authorities="com.example.image_chan.core.Suggestions"/>

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.Image_chan.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".ImageView"
            android:label="image_chan"
            android:theme="@style/Theme.Image_chan.NoActionBar">
        </activity>

        <activity
            android:name=".Main"
            android:label="image_chan"
            android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.SEARCH"/>
            </intent-filter>
            <meta-data android:name="android.app.searchable"
                android:resource="@xml/searchable" />
        </activity>
     </application>

</manifest>
vs3odd8k

vs3odd8k1#

请遵循以下步骤。
1.应该将imageview类重命名为imageviewactivity或其他任何东西。
2.确保此活动扩展activity或appcompatactivity。
3.确保此活动位于app\src\main目录下。
这应该能解决你的问题。

相关问题