0
我有很多活動非常類似於此,他們都工作,但這一個當活動打開我得到這些錯誤在logcat。在日食中沒有可見的錯誤,除了在日誌貓,所以我不知道該怎麼做。運行時異常/空指針異常
01-01 17:18:00.033: W/dalvikvm(430): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-01 17:18:00.183: E/AndroidRuntime(430): FATAL EXCEPTION: main
01-01 17:18:00.183: E/AndroidRuntime(430): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.musicbynumbers.pianoscales/com.musicbynumbers.scales.minorMelodic}: java.lang.NullPointerException
01-01 17:18:00.183: E/AndroidRuntime(430): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-01 17:18:00.183: E/AndroidRuntime(430): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-01 17:18:00.183: E/AndroidRuntime(430): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-01 17:18:00.183: E/AndroidRuntime(430): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-01 17:18:00.183: E/AndroidRuntime(430): at android.os.Handler.dispatchMessage(Handler.java:99)
01-01 17:18:00.183: E/AndroidRuntime(430): at android.os.Looper.loop(Looper.java:123)
01-01 17:18:00.183: E/AndroidRuntime(430): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-01 17:18:00.183: E/AndroidRuntime(430): at java.lang.reflect.Method.invokeNative(Native Method)
01-01 17:18:00.183: E/AndroidRuntime(430): at java.lang.reflect.Method.invoke(Method.java:521)
01-01 17:18:00.183: E/AndroidRuntime(430): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-01 17:18:00.183: E/AndroidRuntime(430): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-01 17:18:00.183: E/AndroidRuntime(430): at dalvik.system.NativeStart.main(Native Method)
01-01 17:18:00.183: E/AndroidRuntime(430): Caused by: java.lang.NullPointerException
01-01 17:18:00.183: E/AndroidRuntime(430): at com.musicbynumbers.scales.minorMelodic.onCreate(minorMelodic.java:52)
01-01 17:18:00.183: E/AndroidRuntime(430): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-01 17:18:00.183: E/AndroidRuntime(430): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-01 17:18:00.183: E/AndroidRuntime(430): ... 11 more
01-01 17:23:00.463: I/Process(430): Sending signal. PID: 430 SIG: 9
的Java
package com.musicbynumbers.scales;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.view.Menu;
import android.view.View;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import com.musicbynumbers.pianoscales.R;
public class minorMelodic extends Activity implements View.OnClickListener {
Button aflatmin, amin, bflatmin, bmin, cmin, dflatmin, dmin, eflatmin, emin, fmin, fsharpmin, gmin;
ImageButton mainMenu;
Intent j;
String scaleName;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.RGBA_8888);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
setContentView(R.layout.minormelodic);
j = new Intent(this, display.class);
mainMenu = (ImageButton) findViewById(R.id.imagelogo);
aflatmin = (Button) findViewById(R.id.aflatmelb);
amin = (Button) findViewById(R.id.amelb);
bflatmin = (Button) findViewById(R.id.bflatmelb);
bmin = (Button) findViewById(R.id.bmelb);
cmin = (Button) findViewById(R.id.cmelb);
dflatmin = (Button) findViewById(R.id.dflatmelb);
dmin = (Button) findViewById(R.id.dharmb);
eflatmin = (Button) findViewById(R.id.eflatmelb);
emin = (Button) findViewById(R.id.emelb);
fmin = (Button) findViewById(R.id.fmelb);
fsharpmin = (Button) findViewById(R.id.fsharpmelb);
gmin = (Button) findViewById(R.id.gmelb);
mainMenu.setOnClickListener(this);
aflatmin.setOnClickListener(this);
amin.setOnClickListener(this);
bflatmin.setOnClickListener(this);
bmin.setOnClickListener(this);
cmin.setOnClickListener(this);
dflatmin.setOnClickListener(this);
dmin.setOnClickListener(this);
eflatmin.setOnClickListener(this);
emin.setOnClickListener(this);
fmin.setOnClickListener(this);
fsharpmin.setOnClickListener(this);
gmin.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.imagelogo:
Intent i = new Intent(minorMelodic.this, MainMenu.class);
startActivity(i);
break;
case R.id.aflatmelb:
scaleName = "aflatmelmin";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.amelb:
scaleName = "amelmin";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.bflatmelb:
scaleName = "bflatmelmin";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.bmelb:
scaleName = "bmelmin";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.cmelb:
scaleName = "cmelmin";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.dflatmelb:
scaleName = "dflatmelmin";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.dmelb:
scaleName = "dmelmin";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.eflatmelb:
scaleName = "eflatmelmin";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.emelb:
scaleName = "emelmin";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.fmelb:
scaleName = "fmelmin";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.fsharpmelb:
scaleName = "fsharpmelmin";
j.putExtra("key", scaleName);
startActivity(j);
break;
case R.id.gmelb:
scaleName = "gmelmin";
j.putExtra("key", scaleName);
startActivity(j);
break;
}
}
}
如果任何人都可以解釋如何發現,與該會大加讚賞的logcat發生錯誤。
好像你忘了在佈局中添加'R.id.dharmb'按鈕? – dmon
你知道這是一個'NullPointerException'已經引起了顯着** **由:**語句引起。你可以看看是什麼。右下方告訴你在相關順序的位置查找'... at com.musicbynumbers.scales.minorMelodic.onCreate(minorMelodic.java:52)'這裏的line ** 52 ** minorMelodic類的'onCreate'。 – mango
感謝它我把一個按鈕放在不同的佈局中,但是你怎麼知道問題出在哪裏,所以我不必在每次出現問題時都問這個問題,我解決不了? –