安卓:onBack pressed()会导致应用程序崩溃 [英] Android: onBackPressed() causes application to crash

查看:152
本文介绍了安卓:onBack pressed()会导致应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用onBack pressed()方法,以提供机器人为

I am attempting to use the onBackPressed() method provided by android in order to

这是我现在用的是 onBack pressed()方法的类:

The class that I am using the onBackPressed() method:

import com.interviewme.R;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class Preparing extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_preparation);

    }

    @Override
    public void onBackPressed() {
        Intent t = new Intent(this, Menu.class);
        startActivity(t);

    }

}

清单文件,其中我想回去的一部分:

The part of the manifest file where I am trying to go back to:

                                     

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

该应用程序的完整清单文件:

The full manifest file of the app:

 <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.interviewme"
        android:versionCode="1"
        android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.interviewme.Splash"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.interviewme.Play"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.PLAY" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.interviewme.Result"
            android:label="@string/title_activity_result" >
        </activity>
        <activity
            android:name=".Menu" 
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.interviewme.menu" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.interviewme.About"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name="com.interviewme.InterviewTips"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name="com.interviewme.Preparing"
            android:label="@string/app_name" >
        </activity>
    </application>

</manifest>

这是logcat的错误日志:

The error log from logcat:

05-09 08:09:43.420: E/AndroidRuntime(1741): FATAL EXCEPTION: main
05-09 08:09:43.420: E/AndroidRuntime(1741): Process: com.interviewme, PID: 1741
05-09 08:09:43.420: E/AndroidRuntime(1741): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.interviewme/android.view.Menu}; have you declared this activity in your AndroidManifest.xml?
05-09 08:09:43.420: E/AndroidRuntime(1741):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
05-09 08:09:43.420: E/AndroidRuntime(1741):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
http://androidmanifest.xml/
androidmanifest.xml

我注意到,它规定 ActivityNotFound ,然而,这活动肯定是在我的应用程序,它是正确命名的清单?

I notice that It states ActivityNotFound, however this Activity is definitely within my app, is it named incorrectly in manifest?

推荐答案

它的采摘机器人默认菜单

its picking android default Menu

删除此行

import android.view.Menu;

和进口类或者改变你的类名菜单到另一个名称(例如,菜单1)

and import your class or change your class name Menu to another name(eg. Menu1)

这篇关于安卓:onBack pressed()会导致应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆