Android应用程序错误“;不幸的是,应用程序已停止;
我正在学习android开发,我正在youtube上学习一个教程,我正在尝试运行此代码,我不断收到“不幸的是,应用程序已停止”,问题似乎是当我开始活动“startActivity(menuIntent);”这是MainActivity.java:Android应用程序错误“;不幸的是,应用程序已停止;,android,android-intent,Android,Android Intent,我正在学习android开发,我正在youtube上学习一个教程,我正在尝试运行此代码,我不断收到“不幸的是,应用程序已停止”,问题似乎是当我开始活动“startActivity(menuIntent);”这是MainActivity.java: package com.example.thebasicseries; import android.media.MediaPlayer; import android.os.Bundle; import android.app.Activity; i
package com.example.thebasicseries;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
public class MainActivity extends Activity {
MediaPlayer logoMusic;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
logoMusic = MediaPlayer.create(MainActivity.this, R.raw.sound);
logoMusic.start();
Thread logoTimer = new Thread(){
public void run(){
try {
sleep(5000);
Intent menuIntent = new Intent("com.example.thebasicseries.menu");
startActivity(menuIntent);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
finish();
}
}
};
logoTimer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
logoMusic.release();
}
}
这是menu.java
package com.example.thebasicseries;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class menu extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Button sound
final MediaPlayer buttonSound = MediaPlayer.create(menu.this, R.raw.button);
//Setting up the button references
Button tut1 = (Button) findViewById(R.id.tutorial1);
Button tut2 = (Button) findViewById(R.id.tutorial2);
tut1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
buttonSound.start();
startActivity(new Intent("com.example.thebasicseries.TutorialOne"));
}
});
tut2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
buttonSound.start();
startActivity(new Intent("com.example.thebasicseries.TutorialOne"));
}
});
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
}
这是舱单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.thebasicseries"
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="com.example.thebasicseries.MainActivity"
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.thebasicseries.menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.thebasicseries.menu" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.thebasicseries.TutorialOne"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.thebasicseries.TutorialOne" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
谢谢!!
`问题在于:
com.example.thebasicseries.menu.onCreate(menu.java:35)
你得到了一个NullPointerException
布局XML中似乎没有教程2按钮。问题在于:
com.example.thebasicseries.menu.onCreate(menu.java:35)
你得到了一个NullPointerException
布局XML中似乎没有教程2按钮。请从logcat完成stacktrace?发布你的清单文件代码。发布stacktrace,它是“红色突出显示的”,这可能是你的错误。作为学习的一部分,你应该弄清楚这一点嘿,Alex,如果我来问这个问题是因为我花了很长时间才找到答案……你能格式化你的logcat代码吗?请从logcat中完成stacktrace?发布你的清单文件代码。发布stacktrace,它是“红色突出显示的”,这可能是你的错误。作为学习的一部分,你应该弄清楚这一点嘿,Alex,如果我来问这个问题是因为我花了很长时间才找到答案……你能格式化你的logcat代码吗?