Attempt to invoke virtual method 'void java.io.PrintWriter.print(int)' on a null object reference

Int_Crazy 发布于 2016/10/17 10:50
阅读 838
收藏 0
E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.mingle.myapplication, PID: 5507
                  java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.PrintWriter.print(int)' on a null object reference
                      at com.mingle.myapplication.CarControlFragment$4.onClick(CarControlFragment.java:90)
                      at android.view.View.performClick(View.java:5198)
                      at android.view.View$PerformClick.run(View.java:21147)
                      at android.os.Handler.handleCallback(Handler.java:739)
                      at android.os.Handler.dispatchMessage(Handler.java:95)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)

                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)




代码:

private Runnable mRunnable = new Runnable()
{ public void run()
    { try  { //连接服务器              mSocket = new Socket(wifiIP,Integer.parseInt(wifiPort)); //取得输入、输出流  mBufferedReader = new BufferedReader(new InputStreamReader(mSocket.getInputStream())); mPrintWriter = new PrintWriter(mSocket.getOutputStream(), true); //  recvMessageClient = "wifi成功连接";//消息换行  // Toast.makeText(getActivity(),"wifi连接成功",Toast.LENGTH_SHORT).show();  Message msg = new Message();
            msg.what = 1; mHandler.sendMessage(msg);
        } catch (Exception e)
        {           Message msg = new Message();
            msg.what = 1; mHandler.sendMessage(msg); return;
        } //setRecvMessage();  }
};
backward.setOnClickListener(new View.OnClickListener() {      @Override   public void onClick(View v) {      mPrintWriter.print("B");      mPrintWriter.flush();
        Toast.makeText(getActivity(), "后退", Toast.LENGTH_SHORT).show();
    }
});

加载中
返回顶部
顶部