我对整个Android编程工作都很陌生,而且我在构建应用程序后退出应用程序时出现了问题。几秒钟后,它退出应用程序,显示一条消息,显示,"不幸的是,该应用程序已停止。"除此之外,LogCat在此之后吓坏了,并打印出一个看似无穷无尽的问题列表,我将在此处发布。我在stackoverflow上看到了一些关于这个的帖子,但我找不到解决我问题的帖子。非常感谢任何帮助 - 非常感谢你!
07-02 08:51:33.208: D/AndroidRuntime(2639): Shutting down VM
07-02 08:51:33.208: W/dalvikvm(2639): threadid=1: thread exiting with uncaught exception (group=0x411b4ac8)
07-02 08:51:33.208: E/AndroidRuntime(2639): FATAL EXCEPTION: main
07-02 08:51:33.208: E/AndroidRuntime(2639): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.helloworldtaketwo/com.example.helloworldtaketwo.main}: java.lang.ClassNotFoundException: Didn't find class "com.example.helloworldtaketwo.main" on path: /data/app/com.example.helloworldtaketwo-2.apk
07-02 08:51:33.208: E/AndroidRuntime(2639): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
07-02 08:51:33.208: E/AndroidRuntime(2639): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
07-02 08:51:33.208: E/AndroidRuntime(2639): at android.app.ActivityThread.access$700(ActivityThread.java:154)
07-02 08:51:33.208: E/AndroidRuntime(2639): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
07-02 08:51:33.208: E/AndroidRuntime(2639): at android.os.Handler.dispatchMessage(Handler.java:99)
07-02 08:51:33.208: E/AndroidRuntime(2639): at android.os.Looper.loop(Looper.java:137)
07-02 08:51:33.208: E/AndroidRuntime(2639): at android.app.ActivityThread.main(ActivityThread.java:5306)
07-02 08:51:33.208: E/AndroidRuntime(2639): at java.lang.reflect.Method.invokeNative(Native Method)
07-02 08:51:33.208: E/AndroidRuntime(2639): at java.lang.reflect.Method.invoke(Method.java:511)
07-02 08:51:33.208: E/AndroidRuntime(2639): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
07-02 08:51:33.208: E/AndroidRuntime(2639): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
07-02 08:51:33.208: E/AndroidRuntime(2639): at dalvik.system.NativeStart.main(Native Method)
07-02 08:51:33.208: E/AndroidRuntime(2639): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.helloworldtaketwo.main" on path: /data/app/com.example.helloworldtaketwo-2.apk
07-02 08:51:33.208: E/AndroidRuntime(2639): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
07-02 08:51:33.208: E/AndroidRuntime(2639): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-02 08:51:33.208: E/AndroidRuntime(2639): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-02 08:51:33.208: E/AndroidRuntime(2639): at android.app.Instrumentation.newActivity(Instrumentation.java:1071)
07-02 08:51:33.208: E/AndroidRuntime(2639): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2166)
07-02 08:51:33.208: E/AndroidRuntime(2639): ... 11 more
07-02 08:51:42.127: I/Process(2639): Sending signal. PID: 2639 SIG: 9
我的 Android Manifest 看起来像这样:
<?xml version = "1.0" encoding = "utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworldtaketwo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="20" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".main"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
package thatpackage;
import com.example.helloworldtaketwo.R;
import android.app.Activity;
import android.os.Bundle;
public class main extends Activity{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
答案 0 :(得分:1)
你的&#34;主要&#34;活动必须位于&#34; com.example.helloworldtaketwo&#34;包。不是子包,不是在不同的地方。
这里的问题是您的活动未被发现。通过将其放置在正确的包装中,或者将清单更正为指向正确的包装,确保它正确链接。
答案 1 :(得分:0)
您尚未在清单中声明该类。使用此:
<?xml version = "1.0" encoding = "utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworldtaketwo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="20" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".main"
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.example.MyActivity2"></activity>
</application>
</manifest>
了解更多信息研究这些来源