0

当我尝试运行我的应用程序时,启动画面正确出现,并且在它关闭后立即弹出一条消息,上面写着“不幸的是,第一个应用程序已停止工作”我尝试了很多不同的解决方案,但我发现我相信在我的情况下,在模拟器中测试新的“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编程真的很陌生,所以如果你在帮助我时能具体一点,将不胜感激。

4

5 回答 5

3

我相信它找不到您的主要活动,因为您在清单上的清单中拼写了错误的示例:

package="com.examle.firstapp"

应该:

package="com.example.firstapp"
于 2013-06-08T15:28:29.727 回答
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" /> 
于 2013-07-26T10:24:53.350 回答
1

在这种情况下,错误在于您的清单。包名必须是:

package="com.example.firstapp"

此外,对于 MainActivity,请尝试删除它:

<action android:name="android.intent.action.MAINACTIVTY"\>
于 2013-06-08T15:29:42.047 回答
0

假设 Splash 在默认的 main Activity 中被启动。你的清单应该是

你的包名应该是

 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

于 2013-06-08T15:30:39.193 回答
0

您可以按照以下两步进行: 1. 如果安装在您的 android 手机中,请卸载以前(相同)的应用程序。2. 删除 gen + bin 文件夹,然后在你的安卓手机上运行你的应用程序几次。谢谢

于 2014-12-13T07:57:22.060 回答