java 无法找到明确的活动类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16047340/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to find explicit activity class
提问by hmir
I just began android development, and I'm stuck on this issue. When the application runs, I'm greeted with the following:
我刚开始 android 开发,我被困在这个问题上。当应用程序运行时,我收到以下信息:
(In case the link is broken or the image can't be seen, it is simply a menu in landscape mode with three buttons.)
(如果链接断开或无法看到图像,它只是一个带有三个按钮的横向模式菜单。)
This is what I want to see. However, when I click "Start Playing" which should cause the android emulator to go to a blank screen, the emulator quits our of the app and says, "Unfortunately, MainMenu has been stopped."
这就是我想看到的。但是,当我单击“开始播放”时,这会导致 android 模拟器进入空白屏幕,模拟器退出我们的应用程序并说:“不幸的是,MainMenu 已停止。”
This is the error I get in LogCat:
这是我在 LogCat 中得到的错误:
04-15 21:49:08.779: W/dalvikvm(985): threadid=1: thread exiting with uncaught exception
(group=0x409961f8)
04-15 17:56:24.539: E/AndroidRuntime(739): FATAL EXCEPTION: main
04-15 17:56:24.539: E/AndroidRuntime(739):
android.content.ActivityNotFoundException: Unable to find explicit activity class
{com.example.quote.board/android.inputmethodservice.Keyboard}; have you declared this
activity in your AndroidManifest.xml?
04-15 17:56:24.539: E/AndroidRuntime(739): at
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
04-15 17:56:24.539: E/AndroidRuntime(739): at
android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
04-15 17:56:24.539: E/AndroidRuntime(739): at
android.app.Activity.startActivityForResult(Activity.java:3190)
04-15 17:56:24.539: E/AndroidRuntime(739): at
android.app.Activity.startActivity(Activity.java:3297)
04-15 17:56:24.539: E/AndroidRuntime(739): at
com.example.quote.board.MainMenu.onClick(MainMenu.java:30)
04-15 17:56:24.539: E/AndroidRuntime(739): at
android.view.View.performClick(View.java:3480)
04-15 17:56:24.539: E/AndroidRuntime(739): at
android.view.View$PerformClick.run(View.java:13983)
04-15 17:56:24.539: E/AndroidRuntime(739): at
android.os.Handler.handleCallback(Handler.java:605)
04-15 17:56:24.539: E/AndroidRuntime(739): at
android.os.Handler.dispatchMessage(Handler.java:92)
04-15 17:56:24.539: E/AndroidRuntime(739): at android.os.Looper.loop(Looper.java:137)
04-15 17:56:24.539: E/AndroidRuntime(739): at
android.app.ActivityThread.main(ActivityThread.java:4340)
04-15 17:56:24.539: E/AndroidRuntime(739): at
java.lang.reflect.Method.invokeNative(Native Method)
04-15 17:56:24.539: E/AndroidRuntime(739): at
java.lang.reflect.Method.invoke(Method.java:511)
04-15 17:56:24.539: E/AndroidRuntime(739): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-15 17:56:24.539: E/AndroidRuntime(739): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-15 17:56:24.539: E/AndroidRuntime(739): at
dalvik.system.NativeStart.main(NativeMethod)
I currently have two classes. Here is my first class, called MainMenu:
我目前有两个班级。这是我的第一堂课,叫做 MainMenu:
package com.example.quote.board;
import android.inputmethodservice.Keyboard;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainMenu extends Activity {
@SuppressLint({ "NewApi", "NewApi", "NewApi" })
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu);
ActionBar action= getActionBar();
action.hide();
Button startPlaying = (Button) findViewById(R.id.startPlaying);
Button specialKeyboard = (Button) findViewById(R.id.specialKeyboards);
Button info = (Button) findViewById(R.id.info);
startPlaying.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Intent intent = new Intent(getApplicationContext(), Keyboard.class);
startActivity(intent);
}
});
}
}
My other class is called Keyboard:
我的另一门课叫做键盘:
package com.example.quote.board;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
public class Keyboard extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.keyboard);
ActionBar action = getActionBar();
action.hide();
}
}
Here is my AndroidManifest.xml file:
这是我的 AndroidManifest.xml 文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.quote.board"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
>
<activity
android:name=".MainMenu"
android:screenOrientation="landscape"
android:label="@string/title_activity_main_menu" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.quote.board.Keyboard"
android:screenOrientation="landscape"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
By the way, I had been making this with my friend, who works on a windows computer. We used git to transfer the files to me. Also, this application works the perfectly the way it should for him.
顺便说一下,我一直在和我的朋友一起做这个,他在 Windows 计算机上工作。我们使用 git 将文件传输给我。此外,这个应用程序的工作方式对他来说应该是完美的。
回答by Lele
Solution " have you declared this activity in your AndroidManifest.xml? " write on manifest.xml
解决方案“您是否在 AndroidManifest.xml 中声明了此活动?”写在 manifest.xml 上
<activity android:name=".nameOfYourActivity"> </activity>
回答by mkderin
Fix imports: Your import in the MainMenu source is not correct. You wrote: import android.inputmethodservice.Keyboard; But you need: com.example.quote.board.Keyboard
修复导入:您在 MainMenu 源中的导入不正确。你写道: import android.inputmethodservice.Keyboard; 但你需要:com.example.quote.board.Keyboard