Java-Android : Unable to find explicit activity class

标签 java android

我想打开所选卡片 View 的详细信息,我尝试接受 onlcick 并打开一个新 Intent ,但 Android Studio 抛出下一个异常:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: es.laramira.atellez.moroninfo, PID: 5200
android.content.ActivityNotFoundException: Unable to find explicit activity class {es.laramira.atellez.moroninfo/es.laramira.atellez.moroninfo.Fragments.DetalleFragment}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1523)
at android.app.Activity.startActivityForResult(Activity.java:4224)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:4183)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:4507)
at android.app.Activity.startActivity(Activity.java:4475)
at es.laramira.atellez.moroninfo.Models.NewsViewHolder$1.onClick(NewsViewHolder.java:32)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

这是我的 ViewHolder 的代码:

public class NewsViewHolder extends RecyclerView.ViewHolder {

    View mView;
    Context context;

    public NewsViewHolder(final View itemView) {
        super(itemView);
        mView = itemView;
        itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent intent = new Intent(view.getContext(), DetalleFragment.class);
                view.getContext().startActivity(intent);
            }
        });
    }

    public void setTitular(String titular) {
        TextView post_titular = (TextView) mView.findViewById(R.id.titleText);
        post_titular.setText(titular);
    }

    public void setImage(Context ctx, String image){
        ImageView post_image = (ImageView) mView.findViewById(R.id.imageView);
        Picasso.with(ctx).load(image).into(post_image);
    }
}

这是我的DetalleFragment.java

public class DetalleFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_detalle, container, false);
    }
}

这是我的fragment_detalle.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="es.laramira.atellez.moroninfo.Fragments.DetalleFragment">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Hello from detail"
        android:textSize="24dp"/>

</FrameLayout>

最佳答案

DetalleFragment 是一个 fragment 。您需要 Activity 类来膨胀 fragment 。 您不能直接调用 DetalleFragment 的 startActivity()。

创建一个 Activity 类并膨胀 DetalleFragment,然后为该 Activity 类调用 startActivity()。

关于Java-Android : Unable to find explicit activity class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44007997/

相关文章:

java - Android MediaPlayer seekTo 方法在 JellyBean 设备上不起作用,但在 Gingerbread、Froyo 上运行良好

java - Apache beam write 转换写入多个文件?

java - JAXB 解码未知问题

java.net.URISyntaxException : Illegal character in path at index 75

java - Android加密 "pad block corrupted"异常

android - 如何更改 drawableLeft 图标的大小?

java - 如何向警报框添加图标?

java - 弃用方法是什么意思,我该如何解决由此产生的错误?

java - Android 应用程序- 没有此类方法异常

Android:我无法删除工具栏上的高程/阴影