我是android開發新手。我正在嘗試製作一個簡單的鼓聲應用程序,當您點擊特定的鼓時,它會播放特定的聲音,但尚未完成,但我無法理解它爲什麼會一直崩潰。請幫幫我。下面的代碼:Android應用程序無故崩潰
package com.android.stiggpwnz.drumset;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
public class DrumSetActivity extends Activity {
/** Called when the activity is first created. */
MediaPlayer ridesound = MediaPlayer.create(this, R.raw.ridecymbal);
MediaPlayer hatsound = MediaPlayer.create(this, R.raw.highhat);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView ride=(ImageView)findViewById(R.id.upLeftPlate);
ride.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
ridesound.start();
}
});
ImageView highHat=(ImageView)findViewById(R.id.midLeftPlate);
highHat.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
hatsound.start();
}
});
}
}
這是我的佈局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/drumset" >
<ImageView
android:id="@+id/upLeftPlate"
android:layout_width="135dp"
android:layout_height="55dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="31dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/kh" />
<ImageView
android:id="@+id/midLeftPlate"
android:layout_width="117dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/upLeftPlate"
android:layout_marginLeft="10dp"
android:layout_marginTop="22dp"
android:src="@drawable/kh" />
</RelativeLayout>
這裏的logcat的說什麼:
11-17 20:55:56.349: E/AndroidRuntime(514): FATAL EXCEPTION: main
11-17 20:55:56.349: E/AndroidRuntime(514): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.android.stiggpwnz.drumset/com.android.stiggpwnz.drumset.DrumSetActivity}: java.lang.NullPointerException
11-17 20:55:56.349: E/AndroidRuntime(514): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
11-17 20:55:56.349: E/AndroidRuntime(514): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-17 20:55:56.349: E/AndroidRuntime(514): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-17 20:55:56.349: E/AndroidRuntime(514): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-17 20:55:56.349: E/AndroidRuntime(514): at android.os.Handler.dispatchMessage(Handler.java:99)
11-17 20:55:56.349: E/AndroidRuntime(514): at android.os.Looper.loop(Looper.java:123)
11-17 20:55:56.349: E/AndroidRuntime(514): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-17 20:55:56.349: E/AndroidRuntime(514): at java.lang.reflect.Method.invokeNative(Native Method)
11-17 20:55:56.349: E/AndroidRuntime(514): at java.lang.reflect.Method.invoke(Method.java:521)
11-17 20:55:56.349: E/AndroidRuntime(514): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-17 20:55:56.349: E/AndroidRuntime(514): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-17 20:55:56.349: E/AndroidRuntime(514): at dalvik.system.NativeStart.main(Native Method)
11-17 20:55:56.349: E/AndroidRuntime(514): Caused by: java.lang.NullPointerException
11-17 20:55:56.349: E/AndroidRuntime(514): at android.content.ContextWrapper.getResources(ContextWrapper.java:80)
11-17 20:55:56.349: E/AndroidRuntime(514): at android.media.MediaPlayer.create(MediaPlayer.java:641)
11-17 20:55:56.349: E/AndroidRuntime(514): at com.android.stiggpwnz.drumset.DrumSetActivity.<init>(DrumSetActivity.java:12)
11-17 20:55:56.349: E/AndroidRuntime(514): at java.lang.Class.newInstanceImpl(Native Method)
11-17 20:55:56.349: E/AndroidRuntime(514): at java.lang.Class.newInstance(Class.java:1429)
11-17 20:55:56.349: E/AndroidRuntime(514): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-17 20:55:56.349: E/AndroidRuntime(514): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
11-17 20:55:56.349: E/AndroidRuntime(514): ... 11 more
並能有人告訴我,爲什麼需要這麼長的時間上傳我的模擬器上的90KB應用程序?
[2011-11-17 21:10:36 - DrumSet] ------------------------------
[2011-11-17 21:10:36 - DrumSet] Android Launch!
[2011-11-17 21:10:36 - DrumSet] adb is running normally.
[2011-11-17 21:10:36 - DrumSet] Performing com.android.stiggpwnz.drumset.DrumSetActivity activity launch
[2011-11-17 21:10:36 - DrumSet] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'bulat'
[2011-11-17 21:10:36 - DrumSet] Uploading DrumSet.apk onto device 'emulator-5554'
[2011-11-17 21:13:37 - DrumSet] Installing DrumSet.apk...
[2011-11-17 21:13:51 - DrumSet] Success!
[2011-11-17 21:13:51 - DrumSet] Starting activity com.android.stiggpwnz.drumset.DrumSetActivity on device emulator-5554
[2011-11-17 21:13:54 - DrumSet] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.android.stiggpwnz.drumset/.DrumSetActivity }
上傳和安裝90KB的東西之間的3 minuts。爲什麼?
logcat說什麼? – 2011-11-17 17:39:36
它說很多東西,我沒有得到它,我怎麼能發送日誌給你? –
按紅色的'E'按鈕看紅色的文字,它實際上顯示類,方法和線條,甚至試圖說出什麼樣的錯誤發生,所以它是工具#1使用 – 2011-11-17 17:48:53