.ActivityNotFoundException:无法找到显式活动类

时间:2016-05-07 02:54:15

标签: android

  

我想在textview中单击活动类开始片段活动,但我得到以下异常。我是新来的android请帮忙。这是我的代码

 Intent intent=new Intent(this,ThreeFragment.class);
    startActivity(intent);
  

并得到以下异常。

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.siluni.myapplication/com.example.siluni.myapplication.ThreeFragment}; have you declared this activity in your AndroidManifest.xml?
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1791)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1513)
        at android.app.Activity.startActivityForResult(Activity.java:3933)
        at android.app.Activity.startActivityForResult(Activity.java:3881)
        at android.app.Activity.startActivity(Activity.java:4204)
        at android.app.Activity.startActivity(Activity.java:4172)
        at com.example.siluni.myapplication.SheduleActivity.SaveShedule(SheduleActivity.java:178)
        at com.example.siluni.myapplication.SheduleActivity$5.onClick(SheduleActivity.java:150)
        at android.view.View.performClick(View.java:5076)
        at android.view.View$PerformClick.run(View.java:20279)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5930)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)

1 个答案:

答案 0 :(得分:3)

如果WM_SETTEXT扩展了Fragment,那么你应该像这样初始化它

ThreeFragment

<强>更新

FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Fragment fragment = new ThreeFragment(); fragmentTransaction.replace(R.id.fragment_container, fragment); fragmentTransaction.commit(); R.id.fragment_container,其中包含您的片段。

在活动布局的底部包含此内容,您要在其中初始化片段

FrameLayout

如果<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent"/> 扩展ThreeFragmentAppCompatActivity您的清单,则需要将其包含在内

Activity