Intent-swich XML

时间:2016-12-01 00:33:07

标签: android android-intent

我有一个问题,当我使用Intent来切换XML文件时,我的应用程序无效。这是主要的:

  public void Hit()
{
    if ( (alergator1Y - alergatorHigh <= alergator3Y && alergator1X == alergator3X) ||
            (alergator1Y - alergatorHigh <= alergator5Y && alergator1X == alergator5X))
    {
        crono.stop();
        timer.cancel();
        Intent intent = new Intent(getApplicationContext(), Result.class);
        startActivity(intent);
    }

}

以及我在Result类中的内容:

public class Result extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_results);

}

public void tryAgain(View view) {
    startActivity(new Intent(getApplicationContext(), Main.class));
}

}

和logcat说:

12-01 02:13:07.644 5233-5233/com.example.bogadan.runbabyrun E/AndroidRuntime: FATAL EXCEPTION: main
                                                                          Process: com.example.bogadan.runbabyrun, PID: 5233
                                                                          android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.bogadan.runbabyrun/com.example.bogadan.runbabyrun.Result}; 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:48)
                                                                              at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
                                                                              at android.app.Activity.startActivityForResult(Activity.java:4183)
                                                                              at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:856)
                                                                              at android.app.Activity.startActivity(Activity.java:4507)
                                                                              at android.app.Activity.startActivity(Activity.java:4475)
                                                                              at com.example.bogadan.runbabyrun.Main.Hit(Main.java:186)
                                                                              at com.example.bogadan.runbabyrun.Main$4$1.run(Main.java:332)
                                                                              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)
问题在哪里?我在互联网上搜索,我找不到问题...

1 个答案:

答案 0 :(得分:0)

只需将Result活动添加到AndroidManifest.xml

即可
<activity android:name=".your_activity" android:label="sample_name"/>