0

我有许多与此非常相似的活动,它们都可以工作,但是这个活动打开时,我在 logcat 中收到这些错误。除了日志猫之外,eclipse 中没有可见的错误,所以我不知道该怎么做。

    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

爪哇

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 发生错误的位置,将不胜感激。

4

1 回答 1

0

感谢 dmon、codeMagic 和 mango 回答我的问题。我从java中的不同布局中输入了一个按钮ID,这导致了错误。

于 2013-01-01T17:55:06.427 回答