【发布时间】:2014-07-07 15:18:33
【问题描述】:
我一直在关注此视频教程 here,为应用启动时发生的 5 秒启动活动(?)添加声音。在使用视频中详细介绍的新声音添加编辑应用程序之前,该应用程序运行良好并显示存储在 R.layout.splash xml 文件中的图像
我的应用程序正在运行,并且代码与开始时视频中的代码几乎完全相同。但是,在观看此视频并进行建议的更改后,应用程序在显示图像或声音之前崩溃(在任何错误消息中都没有给出重要信息,只是应用程序已经崩溃)。
添加音频文件后,我确实再次清理了项目。 音频文件确实以 pikachu.mp3 的形式存在于 res/raw 文件夹中(这是一个短 3 秒的声音)。 我还尝试在没有 onPause 部分代码的情况下运行该应用程序,但它仍然会立即崩溃。我正在运行的代码如下,如果你能看一下并给我一些关于为什么应用程序不断崩溃的建议,我将不胜感激。谢谢。
package com.example.thenewbonston;
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 TravisLoveBacon) {
// TODO Auto-generated method stub
super.onCreate(TravisLoveBacon);
setContentView(R.layout.splash);
ourSong = MediaPlayer.create(Splash.this, R.raw.pikachu);
ourSong.start();
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent openStartingPoint = new Intent("com.example.thenewbonston.STARTINGPOINT");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
ourSong.release();
finish();
}
}
【问题讨论】:
-
堆栈跟踪说明了什么
-
什么是堆栈跟踪?
-
假设它是 Eclipse 底部的一系列消息,这就是我所拥有的:[2014-07-07 18:02:57 - The New Bonston] 安装新 Bonston.apk.. . [2014-07-07 18:03:02 - 新邦斯顿] 成功! [2014-07-07 18:03:02 - The New Bonston] 在设备 emulator-5554 上启动活动 com.example.thenewbonston.Splash [2014-07-07 18:03:04 - The New Bonston] ActivityManager:开始:意图 { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.thenewbonston/.Splash }
-
它会告诉您问题所在,否则我们无法帮助您
-
查看 LogCat 输出的内容。这通常会为您提供一个有意义的例外,其中包含应该解释问题的详细信息。
标签: android eclipse audio android-activity crash