当我尝试运行我的应用程序时,启动画面正确显示,关闭后,会弹出一条消息,说“不幸的是,第一个应用程序已停止工作”#34;我已经尝试了很多不同的解决方案,但我相信在我的情况下,在测试一个新的" Hello World"之后,我的代码出了问题。模拟器中的应用程序。这是我的androidmanifest.xml
的副本<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.examle.firstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Splash" android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.firstapp.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity" android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAINACTIVTY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
以下是尝试了一些解决方案后log cat中出现的内容
06-08 16:12:06.849: E/AndroidRuntime(2821): FATAL EXCEPTION: main
06-08 16:12:06.849: E/AndroidRuntime(2821): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.firstapp/com.example.firstapp.Splash}: java.lang.ClassNotFoundException: Didn't find class "com.example.firstapp.Splash" on path: /data/app/com.example.firstapp-1.apk
06-08 16:12:06.849: E/AndroidRuntime(2821): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
06-08 16:12:06.849: E/AndroidRuntime(2821): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-08 16:12:06.849: E/AndroidRuntime(2821): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-08 16:12:06.849: E/AndroidRuntime(2821): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-08 16:12:06.849: E/AndroidRuntime(2821): at android.os.Handler.dispatchMessage(Handler.java:99)
06-08 16:12:06.849: E/AndroidRuntime(2821): at android.os.Looper.loop(Looper.java:137)
06-08 16:12:06.849: E/AndroidRuntime(2821): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-08 16:12:06.849: E/AndroidRuntime(2821): at java.lang.reflect.Method.invokeNative(Native Method)
06-08 16:12:06.849: E/AndroidRuntime(2821): at java.lang.reflect.Method.invoke(Method.java:511)
06-08 16:12:06.849: E/AndroidRuntime(2821): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-08 16:12:06.849: E/AndroidRuntime(2821): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-08 16:12:06.849: E/AndroidRuntime(2821): at dalvik.system.NativeStart.main(Native Method)
06-08 16:12:06.849: E/AndroidRuntime(2821): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.firstapp.Splash" on path: /data/app/com.example.firstapp-1.apk
06-08 16:12:06.849: E/AndroidRuntime(2821): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
06-08 16:12:06.849: E/AndroidRuntime(2821): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-08 16:12:06.849: E/AndroidRuntime(2821): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-08 16:12:06.849: E/AndroidRuntime(2821): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
06-08 16:12:06.849: E/AndroidRuntime(2821): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
06-08 16:12:06.849: E/AndroidRuntime(2821): ... 11 more
我对Android编程非常陌生,所以如果你能在具体帮助我的时候,我将非常感激。
答案 0 :(得分:2)
我认为它无法找到您的主要活动,因为您在清单上拼写错误的示例:
package="com.examle.firstapp"
应该是:
package="com.example.firstapp"
答案 1 :(得分:2)
public class SplashScreenActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Timer timer=new Timer();
timer.schedule(new MyTask(), 5000);
}
class MyTask extends TimerTask{
@Override
public void run() {
Intent intent=new Intent(SplashScreenActivity.this,SecondActivity.class);
finish();
startActivity(intent);
}
}
}
清单中的
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>`enter code here`
</activity>
<activity android:name=".SecondActivity" />
答案 2 :(得分:0)
在这种情况下,错误在于您的清单。包名必须是:
package="com.example.firstapp"
另外,对于MainActivity,请尝试删除它:
<action android:name="android.intent.action.MAINACTIVTY"\>
从类似的项目开始查看此Manifest,该项目也以Splash屏幕开头:https://github.com/SCS-hackers-group/Concordia-Shuttle-Bus-App/blob/master/AndroidManifest.xml
答案 3 :(得分:0)
假设启动默认主要活动中的Splash。你的清单应该是
您的包名称应为
package="com.example.firstapp"
活动
<activity
android:name="com.example.firstapp.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.example.firstapp.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.firstapp.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
如果您有明确的意图,则可以跳过意图过滤器
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
</activity>
有关详情,请查看以下链接
http://developer.android.com/guide/topics/manifest/manifest-intro.html
http://developer.android.com/guide/topics/manifest/manifest-element.html
答案 4 :(得分:0)
您可以按以下两步操作: 1.如果安装在Android手机中,请卸载以前(相同)的应用程序。 2.删除gen + bin文件夹 然后在你的Android手机中运行你的应用程序几次后再次。 感谢