Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我的Android应用程序意外崩溃_Java_Android - Fatal编程技术网

Java 我的Android应用程序意外崩溃

Java 我的Android应用程序意外崩溃,java,android,Java,Android,我是Android编程的初学者。 我正在通过新的波士顿视频学习它。 但每次我启动应用程序时,它都会崩溃“不幸的是,应用程序停止工作” 但当我单击OK时,它会将我带到应用程序中的第二个活动。 我不知道为什么会发生这种事 下面是我的Android清单: <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> <uses-permission android:name="android

我是Android编程的初学者。 我正在通过新的波士顿视频学习它。 但每次我启动应用程序时,它都会崩溃“不幸的是,应用程序停止工作” 但当我单击OK时,它会将我带到应用程序中的第二个活动。 我不知道为什么会发生这种事

下面是我的Android清单:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.SET_WALLPAPER" />

<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="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".StartingPoint"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.skm.firstapp.STARTINGPOINT" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Menu"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.skm.firstapp.MENU" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
     <activity
        android:name=".Prefs"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.skm.firstapp.PREFS" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".TextPlay"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Email"
        android:label="@string/app_name" >
    </activity>
    <activity
        android:name=".Camera"
        android:label="Camera Application"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".Data"
        android:label="Data App"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".OpenedClass"
        android:label="Data App"
        android:screenOrientation="portrait" >
    </activity>
    <activity
        android:name=".AboutUs"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Dialog" >
        <intent-filter>
            <action android:name="com.skm.firstapp.ABOUT" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

</manifest>
下面是我的Splash.java文件:

package com.skm.firstapp;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;

public class Splash extends Activity {

MediaPlayer ourSong;
@Override
protected void onCreate(Bundle LW) {
    // TODO Auto-generated method stub
    super.onCreate(LW);
    setContentView(R.layout.splash);
    MediaPlayer ourSong = MediaPlayer.create(Splash.this, R.raw.drum);
    ourSong.start();
    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(1000);

            }catch(InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent ourIntent = new Intent("com.skm.firstapp.MENU");
                startActivity(ourIntent);
            }
        }
    };
    timer.start();
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    ourSong.release();
    finish();
}

根据您提供的日志cat:您将在以下位置获得“NullPointerException”:检查此行:

at com.skm.firstapp.Splash.onPause(Splash.java:38)
因此,我认为您应该在这条线上发布MediaPlayer资源。 但是如果它还没有初始化,那么您将得到NullPointerException

因此,在onCreate()方法上初始化资源

附言: 共享完整的logcat文件并 还可以共享Splash.java

:添加splash.java后:

MediaPlayer ourSong;
@Override
protected void onCreate(Bundle LW) {
    // TODO Auto-generated method stub
    super.onCreate(LW);
    setContentView(R.layout.splash);
    MediaPlayer ourSong = MediaPlayer.create(Splash.this, R.raw.drum);
    ourSong.start();
您需要将我们的歌曲声明为您已经完成的实例变量

但您也在onCreate()方法中声明为局部变量,如下行所示:

MediaPlayer ourSong = MediaPlayer.create(Splash.this, R.raw.drum);
因此,将其更改为:

ourSong = MediaPlayer.create(Splash.this, R.raw.drum);

现在向我们展示Spalsh.java的代码。特别是第38行(在方法
onPause
中的某个地方)。谢谢。@Tom我已经添加了splash.java。请看一下。谢谢你的回复。我添加了splash.java,你可以看看。我修改了答案,我在想为什么
onCreate
不会被称为:D.+1,因为你的好眼睛:)。