启动屏幕后应用程序强制关闭

Posted

技术标签:

【中文标题】启动屏幕后应用程序强制关闭【英文标题】:Application force closes after splash screen 【发布时间】:2013-10-01 18:47:15 【问题描述】:

您好,我在主课之前实现了启动画面。令我惊讶的是,在我的启动画面加载后,它会强制关闭我的应用程序并显示 logcat 错误:说找不到类,如果我确定我已经在我的清单中声明了它,我已经完成了。我不确定我哪里出错了,还有我错过了什么。请帮忙 。

清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="hellog.diwesh.NugaBest"
    android:versionCode="1"
    android:versionName="1.0"
    android:hardwareAccelerated="true" >

    <uses-sdk android:minSdkVersion="11" />

    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:name="helog.diwesh.NugaBest.MyApplication"
        android:debuggable="true"
        android:icon="@drawable/nuga"
        android:label="@string/app_name" >
        <activity
            android:name="helog.diwesh.NugaBest.SplashScreen"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        // 4. Layout Management

        <activity
            android:name="helog.diwesh.NUGA_HealthCareActivity_Intro"
            android:label="NUGA_HealthCareActivity_Intro" />

        <activity
            android:name="helog.diwesh.NugaBest.FileSiganlDisplay"
            android:label="FileSiganlDisplay" />
        <activity
            android:name="helog.diwesh.NugaBest.NUGA_WebJoinActivity"
            android:label="NUGA_WebJoinActivity"
            android:windowSoftInputMode="stateHidden" />
        <activity
            android:name="helog.diwesh.NugaBest.NUGA_MainMenuActivity"
            android:label="NUGA_MainMenuActivity" />
        <activity
            android:name="helog.diwesh.NugaBest.BTSmartSlavemodule"
            android:configChanges="orientation|keyboardHidden"
            android:label="SmartSlavemodule" />
        <activity
            android:name="helog.diwesh.NugaBest.BTDeviceListActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/select_device"
            android:theme="@android:style/Theme.Dialog" />
        <activity
            android:name="helog.diwesh.NugaBest.SnapActivity"
            android:label="@string/title_activity_snap" >
        </activity>
        <activity
            android:name="helog.diwesh.NugaBest.ImagesActivity"
            android:label="@string/title_activity_images" >
        </activity>
        <activity
            android:name="helog.diwesh.NugaBest.HelpActivity"
            android:label="@string/Help" >
        </activity>
        <activity
            android:name="helog.diwesh.NugaBest.AboutDevice"
            android:label="@string/aboutus" >
        </activity>
        <activity
            android:name="helog.diwesh.NugaBest.Savenotes"
            android:label="@string/savenotes" >
        </activity>


        //Notepad

        <activity
            android:name="helog.diwesh.NugaBest.NotepadActivity">
            </activity>

    <activity 
         android:name="helog.diwesh.NugaBest.NotesListActivity">
        </activity>

     <activity 
         android:name="helog.diwesh.NugaBest.NotesDbAdapter">
        </activity>


    </application>

</manifest>

LogCat 错误

09-25 20:29:37.272: D/dalvikvm(781): GC_FOR_ALLOC freed 89K, 8% free 2654K/2864K, paused 43ms, total 58ms
09-25 20:29:37.292: I/dalvikvm-heap(781): Grow heap (frag case) to 5.563MB for 2998216-byte allocation
09-25 20:29:37.362: D/dalvikvm(781): GC_FOR_ALLOC freed 2K, 4% free 5579K/5792K, paused 65ms, total 65ms
09-25 20:29:38.592: D/gralloc_goldfish(781): Emulator without GPU emulation detected.
09-25 20:29:41.934: W/dalvikvm(781): threadid=11: thread exiting with uncaught exception (group=0x41465700)
09-25 20:29:41.953: E/AndroidRuntime(781): FATAL EXCEPTION: Thread-72
09-25 20:29:41.953: E/AndroidRuntime(781): android.content.ActivityNotFoundException: Unable to find explicit activity class hellog.diwesh.NugaBest/helog.diwesh.NugaBest.NUGA_HealthCareActivity_Intro; have you declared this activity in your AndroidManifest.xml?
09-25 20:29:41.953: E/AndroidRuntime(781):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
09-25 20:29:41.953: E/AndroidRuntime(781):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
09-25 20:29:41.953: E/AndroidRuntime(781):  at android.app.Activity.startActivityForResult(Activity.java:3390)
09-25 20:29:41.953: E/AndroidRuntime(781):  at android.app.Activity.startActivityForResult(Activity.java:3351)
09-25 20:29:41.953: E/AndroidRuntime(781):  at android.app.Activity.startActivity(Activity.java:3587)
09-25 20:29:41.953: E/AndroidRuntime(781):  at android.app.Activity.startActivity(Activity.java:3555)
09-25 20:29:41.953: E/AndroidRuntime(781):  at helog.diwesh.NugaBest.SplashScreen$1.run(SplashScreen.java:34)
09-25 20:30:20.892: I/Process(781): Sending signal. PID: 781 SIG: 9

SplashScreen.java

public class SplashScreen extends Activity 
    protected boolean _active = true;
    protected int _splashTime = 3000; // time to display the splash screen in Ms



    @Override
    public void onCreate(Bundle savedInstanceState) 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);

        Thread splashTread = new Thread() 
            @Override
            public void run() 
                try 
                    int waited = 0;
                    while (_active && (waited < _splashTime)) 
                        sleep(100);
                        if (_active) 
                            waited += 100;
                        
                    
                 catch (Exception e) 

                 finally 

                    startActivity(new Intent(SplashScreen.this,
                            NUGA_HealthCareActivity_Intro.class));
                    finish();
                
            ;
                 ;
        splashTread.start();
    
     

【问题讨论】:

【参考方案1】:

您错误地定义了 INTRO 活动(您忘记了 NugaBest 包)。 试试这个:

<activity
            android:name="helog.diwesh.NugaBest.NUGA_HealthCareActivity_Intro"
            android:label="NUGA_HealthCareActivity_Intro" />

希望这会有所帮助!

【讨论】:

呵呵,谢谢!很高兴我能帮助你!不要忘记标记为正确:)

以上是关于启动屏幕后应用程序强制关闭的主要内容,如果未能解决你的问题,请参考以下文章

关闭应用程序并在 Android 上启动主屏幕

启动 ListView 类时应用程序强制关闭

iOS 启动屏幕过早关闭

Ipad 锁定/关闭后重新启动 ios 应用程序

怎么强制关闭电脑程序 Win7强制关闭电脑程序的方法

应用程序强制退出和应用程序重新启动后如何恢复 NSURLSession 下载过程?