【问题标题】:My Android app splash screen launches in the android emulator, but then the actual app never shows我的 Android 应用程序启动画面在 android 模拟器中启动,但实际应用程序从未显示
【发布时间】:2013-06-04 18:08: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编程真的很陌生,所以如果你能在帮助我时具体一点,将不胜感激。

【问题讨论】:

  • 哇,好吧,我什至没有意识到我在示例中打错了字。另一个错误正在弹出。 Description Resource Path Location Type The project was not built due to "A resource exists with a different case: '/FirstApp/bin/classes/com/examle/firstapp'.". Fix the problem, then try refreshing this project and building it since it may be inconsistent FirstApp Unknown Java Problem
  • 你的 java 文件中的包名是什么?似乎是包名不匹配。是不是像package com.example.firstapp;
  • 包名中有大写字母,我现在刚刚修好了。现在该错误消失了,但是现在当我尝试运行该应用程序时,启动画面根本不显示,它告诉我它已停止工作。
  • 您是否尝试过我的回答中提到的编辑?发布崩溃的新 logcat 详细信息
  • 是的,我试过了,没有运气。

标签: android android-emulator android-manifest


【解决方案1】:

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

package="com.examle.firstapp"

应该是:

package="com.example.firstapp"

【讨论】:

  • 您还需要确保 Java 文件的第一行(也说明包)与清单中的包名称匹配。确保其一致。
  • 原来我实际上将实际的包文件命名为“examle”,而我什至没有意识到这一点。不过还是谢谢。
【解决方案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" /> 

【讨论】:

    【解决方案3】:

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

    package="com.example.firstapp"
    

    另外,对于 MainActivity,请尝试删除:

    <action android:name="android.intent.action.MAINACTIVTY"\>
    

    【讨论】:

      【解决方案4】:

      假设 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

      【讨论】:

        【解决方案5】:

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

        【讨论】:

          猜你喜欢
          • 2019-03-24
          • 1970-01-01
          • 1970-01-01
          • 2012-09-11
          • 1970-01-01
          • 2013-11-22
          • 1970-01-01
          • 1970-01-01
          • 2011-05-11
          相关资源
          最近更新 更多