0

我在 X.class 中有这些方法:

    public void sendMessage(String message) {
    // Check that we're actually connected before trying anything
    if (mChatService.getState() != BluetoothChatService.STATE_CONNECTED) {
        Toast.makeText(this, R.string.not_connected, Toast.LENGTH_SHORT).show();
        return;
    }

    // Check that there's actually something to send
    if (message.length() > 0) {
        // Get the message bytes and tell the BluetoothChatService to write
        byte[] send = message.getBytes();
        mChatService.write(send);

        // Reset out string buffer to zero and clear the edit text field
        mOutStringBuffer.setLength(0);
        //mOutEditText.setText(mOutStringBuffer);
    }
}

public static void sendMessage1(String message1){

    call1.sendMessage(message1);
}

我有以下toggleSwitch,我从另一个活动即Y.class单击它:

tb3.setOnClickListener(new OnClickListener() {
        public void onClick(View v){
            if (tb3.isChecked()){
                String message = "u";
                X.sendMessage1(message);
                //clearer();
            } else if (!tb3.isChecked()){
                String message = "y";
                //clearer();
            }
        }
    });

虽然我在编码时没有收到任何错误,但是当我在 Android 上加载应用程序然后单击此切换开关时,我的应用程序会死掉吗?

日志:

E/AndroidRuntime( 4866): java.lang.NullPointerException
E/AndroidRuntime( 4866):    at com.winacro.andRHOME.andRHOME.sendMessage1(andRHOME.java:282)
E/AndroidRuntime( 4866):    at com.winacro.andRHOME.EECA2$1.onClick(EECA2.java:57)
E/AndroidRuntime( 4866):    at android.view.View.performClick(View.java:3534)
E/AndroidRuntime( 4866):    at android.widget.CompoundButton.performClick(CompoundButton.java:104)
E/AndroidRuntime( 4866):    at android.view.View$PerformClick.run(View.java:14263)
E/AndroidRuntime( 4866):    at android.os.Handler.handleCallback(Handler.java:605)
E/AndroidRuntime( 4866):    at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 4866):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 4866):    at android.app.ActivityThread.main(ActivityThread.java:4441)
E/AndroidRuntime( 4866):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 4866):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 4866):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime( 4866):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime( 4866):    at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager(  273):   Force finishing activity com.winacro.andRHOME/.EECA2
4

0 回答 0