Android Studio:无法找到明确的 activity class 但 activity 已在 AndroidManifest.xml 中声明
Android Studio: Unable to find explicit activity class but activity already declared in AndroidManifest.xml
这里是 Android Studio 的新手。
我正在努力做到这一点,因此当我在 RecyclerView 中单击来自 ViewHolder 的图像时,它会打开另一个 activity,从而打开另一个布局。
但是,即使我已经在我的清单中声明了 activity,我仍然收到此错误。
试图创建 Intent 以启动新 activity 的代码是 class,在 app/core/StaggeredView
中调用了 StaggeredView
。虽然 activity 处理程序在 app/ImageView
.
中被称为 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.onClick(StaggeredAdapter.java:63)
at android.view.View.performClick(View.java:7448)
at android.view.View.performClickInternal(View.java:7425)
at android.view.View.access00(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>
请按照以下步骤操作。
1.You 应该将 ImageView class 重命名为 ImageViewActivity 之类的其他名称。
2.Make 确保此 activity 扩展 Activity 或 AppCompatActivity.
3.Make 确定这个 activity 在目录 app\src\main.
下
这应该可以解决您的问题。
这里是 Android Studio 的新手。
我正在努力做到这一点,因此当我在 RecyclerView 中单击来自 ViewHolder 的图像时,它会打开另一个 activity,从而打开另一个布局。
但是,即使我已经在我的清单中声明了 activity,我仍然收到此错误。
试图创建 Intent 以启动新 activity 的代码是 class,在 app/core/StaggeredView
中调用了 StaggeredView
。虽然 activity 处理程序在 app/ImageView
.
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.onClick(StaggeredAdapter.java:63)
at android.view.View.performClick(View.java:7448)
at android.view.View.performClickInternal(View.java:7425)
at android.view.View.access00(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>
请按照以下步骤操作。
1.You 应该将 ImageView class 重命名为 ImageViewActivity 之类的其他名称。
2.Make 确保此 activity 扩展 Activity 或 AppCompatActivity.
3.Make 确定这个 activity 在目录 app\src\main.
下这应该可以解决您的问题。