开发者

How to troubleshoot a NullPointerException on Android?

My program is immediately crashing on my Android Emulator and I receive this in the Eclipse Console:

java.lang.NullPointerException
    at com.android.ddmlib.Client.sendAndConsume(Client.java:572)
    at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142)
    at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65)
    at com.android.ddmlib.Client.getJdwpPacket(Client.java:671)
    at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317)
    at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)

How can I troubleshoot what is throwing this message? I'm new to Eclipse and Android.

The program completely crashes when I try to launch a dialog with a button, and refers back here:

    @Override
    protected Dialog onCreateDialog(int id) {
        Dialog dialog;
        switch (id) {
        case TIME_DIALOG_ID:
            return new TimePickerDialog(this,
                    mTimeSetListener, mHour24, mMinute, false);


        case POWER_OFF_OPTIONS:
            AlertDialog.Builder builder;
            AlertDialog alertDialog;

            Context mContext = getApplicationContext();
            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.options,
                    (ViewGroup)findViewById(R.id.relativeLayout1));
            //Capture view elements
            mChkAudio = (CheckBox) findViewById(R.id.chkAudio);
            mChkBluetooth = (CheckBox) findViewById(R.id.chkBlueTooth);
            mChkNetwork = (CheckBox) findViewById(R.id.chkNetwork);
            mChkWifi = (CheckBox) findViewById(R.id.chkWifi);
            mBtnOK = (Button) findViewById(R.id.btnOK);
            mBtnOK.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                  DismissPowerOptions();
                    }
            }); 
     开发者_C百科       builder = new AlertDialog.Builder(mContext);
            builder.setView(layout);
            alertDialog = builder.create();
            //return alertDialog;
        default:
            dialog = null;
        }
        return dialog;
    }


The error is not coming from your program. It is a problem with an Eclipse plugin for Android: The "Dalvik Debug Monitor Server".

http://developer.android.com/guide/developing/debugging/ddms.html

Sometimes these things just get into a bad state and need to be restarted. Close the emulator and restart Eclipse. Start the emulator from the AVD Manager window using the button labelled "Start..". In the start dialog select the "WIPE ALL DATA" button to be sure you're getting a clean start.

If that doesn't solve it then try deleting your emulator in the AVD Manager and creating a new one.


Maybe you've not configured your AVD properly


i solved this problem by click on INVALIDATE CACHE AND RESTART.

file -> Invalidate cache and restart ->invalidate and restart

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜