gpt4 book ai didi

Java-Android : Unable to find explicit activity class

转载 作者:行者123 更新时间:2023-12-02 02:50:00 25 4
gpt4 key购买 nike

我想打开所选卡片 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com