suchen

Heim  >  Fragen und Antworten  >  Hauptteil

android - ANR问题:IFrameworks.serviceManagerGetService报空指针异常该怎么处理?

1.错误日志:

11-25 10:29:26.583 10487-10515/myapplication.com.myblue I/ViewRootImpl: ANR Key Analyze: No Key event currently.
11-25 10:29:26.584 10487-10515/myapplication.com.myblue I/ViewRootImpl: ANR Key Analyze: Previeous Event null,finish at 1970-01-01 08:00:00.000
11-25 10:29:26.584 10487-10515/myapplication.com.myblue I/ViewRootImpl: ANR Motion Analyze: No motion event currently.
11-25 10:29:26.584 10487-10515/myapplication.com.myblue I/ViewRootImpl: ANR Motion Analyze: Previeous Event MotionEvent { action=ACTION_UP, id[0]=0, x[0]=1002.07983, y[0]=140.94196, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=224048681, downTime=224048339, deviceId=3, source=0x1002 },finish at 2016-11-25 10:26:21.164
11-25 10:29:26.706 10487-10698/myapplication.com.myblue W/Binder: Caught a RuntimeException from the binder stub implementation.
                                                                  java.lang.NullPointerException: Attempt to invoke interface method 'android.os.IBinder com.mediatek.anrappmanager.IFrameworks.serviceManagerGetService(java.lang.String)' on a null object reference
                                                                      at com.mediatek.anrappmanager.ANRManagerNative$1.b(SourceFile:77)
                                                                      at com.mediatek.anrappmanager.ANRManagerNative$1.c(SourceFile:75)
                                                                      at com.mediatek.anrappmanager.ANRManagerNative$a.get(SourceFile:97)
                                                                      at com.mediatek.anrappmanager.ANRManagerNative.getDefault(SourceFile:35)
                                                                      at com.mediatek.anrappmanager.ANRAppManager.dumpMessageHistory(SourceFile:59)
                                                                      at android.app.ActivityThread$ApplicationThread.dumpMessageHistory(ActivityThread.java:1315)
                                                                      at android.app.ApplicationThreadNative.onTransact(ApplicationThreadNative.java:687)
                                                                      at android.os.Binder.execTransact(Binder.java:454)
11-25 10:29:26.706 10487-10698/myapplication.com.myblue W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'android.os.IBinder com.mediatek.anrappmanager.IFrameworks.serviceManagerGetService(java.lang.String)' on a null object reference
11-25 10:29:26.706 10487-10698/myapplication.com.myblue W/System.err:     at com.mediatek.anrappmanager.ANRManagerNative$1.b(SourceFile:77)
11-25 10:29:26.706 10487-10698/myapplication.com.myblue W/System.err:     at com.mediatek.anrappmanager.ANRManagerNative$1.c(SourceFile:75)
11-25 10:29:26.706 10487-10698/myapplication.com.myblue W/System.err:     at com.mediatek.anrappmanager.ANRManagerNative$a.get(SourceFile:97)
11-25 10:29:26.706 10487-10698/myapplication.com.myblue W/System.err:     at com.mediatek.anrappmanager.ANRManagerNative.getDefault(SourceFile:35)
11-25 10:29:26.706 10487-10698/myapplication.com.myblue W/System.err:     at com.mediatek.anrappmanager.ANRAppManager.dumpMessageHistory(SourceFile:59)
11-25 10:29:26.706 10487-10698/myapplication.com.myblue W/System.err:     at android.app.ActivityThread$ApplicationThread.dumpMessageHistory(ActivityThread.java:1315)
11-25 10:29:26.706 10487-10698/myapplication.com.myblue W/System.err:     at android.app.ApplicationThreadNative.onTransact(ApplicationThreadNative.java:687)
11-25 10:29:26.706 10487-10698/myapplication.com.myblue W/System.err:     at android.os.Binder.execTransact(Binder.java:454)

2.代码:

package myapplication.com.myblue.activity;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;

import myapplication.com.myblue.R;

public class Zhuye_Activity extends AppCompatActivity {

    TextView textView1,textView_time,textView_lianjie;
    ImageView imageView1;
    EditText edittext;
    Button button_send;
    private BluetoothSocket btSocket = null;
    private OutputStream outStream = null;
    private InputStream inStream = null;
    private BluetoothAdapter BA;
    private  String address = "";
    private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhuye);
        Intent intent=getIntent();
        String mac=intent.getStringExtra("mac");
        String []a=mac.split("\\*");
        address=a[1].trim();

        initView();
        textView1.setText(mac);
    }
    public void initView(){
        BA = BluetoothAdapter.getDefaultAdapter();
        BA.enable();
        button_send= (Button) findViewById(R.id.button_send);
        edittext= (EditText) findViewById(R.id.edittext);
        textView1= (TextView) findViewById(R.id.textview1);
        textView_time= (TextView) findViewById(R.id.textView_time);
        SimpleDateFormat    sDateFormat   = new SimpleDateFormat("yyyy-MM-dd    hh:mm:ss");
        String    date    =    sDateFormat.format(new  java.util.Date());
        textView_time.setText(date);
        imageView1= (ImageView) findViewById(R.id.imageView1);
        textView_lianjie= (TextView) findViewById(R.id.textView_lianjie);
        textView_lianjie.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                connect();
            }
        });
        imageView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        button_send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s=edittext.getText().toString().trim();
                byte[] a=s.getBytes();
                try {
                    outStream.write(a);
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        });

        /**
         * 创建定时器,1000ms更新一次时间
         * **/
     //   Timer timer = new Timer();
       // timer.schedule(timerTask, 0, 10000);
    }

    /**
    * 连接蓝牙设备
    *
    * ***/

    public void connect(){

        BluetoothDevice device = BA.getRemoteDevice(address);
        try {
            btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
        } catch (IOException e) {
            System.out.println("**109"+e.toString());

        }
       // BA.cancelDiscovery();

                try {
                    btSocket.connect();
                    outStream = btSocket.getOutputStream();
                   outStream.write(0x61);
                  outStream.write(0x41);
                    inStream = btSocket.getInputStream();
                    System.out.println("**"+inStream.toString());
                   System.out.println("**"+inStream.read());
                   int x = inStream.read();
                   outStream.write(x + 1);
                } catch (IOException e) {
                    System.out.println("**124"+e.toString());
                }



        try {
            btSocket.close();
        } catch (Exception e2) {

            // Log .e(TAG,"ON RESUME: Unable to close socket during connection failure", e2);
        }
    }
//    public void connect(){
//        BA = BluetoothAdapter.getDefaultAdapter();
//        BluetoothDevice device = BA.getRemoteDevice(address);
//      // pairedDevices = BA.getBondedDevices();
//        try {
//
//            btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
//
//        } catch (IOException e) {
//
//            Log.d("T109",e.toString());
//        }
//     //  BA.cancelDiscovery();
//        try {
//
//       //     new Thread(new Runnable() {
//            //    @Override
//           //     public void run() {
//                  //  try {
//                        btSocket.connect();
//                        outStream = btSocket.getOutputStream();
//                        inStream = btSocket.getInputStream();
//                  //  } catch (IOException e) {
//                      //  e.printStackTrace();
//                  //  }
//            //    }
//          //  }).start();
//
////            outStream = btSocket.getOutputStream();
////            String s="guoxiwang";
////            byte by[]=s.getBytes();
////            outStream.write(12345566);
////            outStream.write(by);
////
////            outStream.write(0x61);
////            outStream.write(0x41);
////            inStream = btSocket.getInputStream();
////            System.out.println("**"+inStream.toString());
////            System.out.println("**"+inStream.read());
////            int x = inStream.read();
////            outStream.write(x + 1);
//
//        } catch (Exception e) {
//        }
//        try {
//            btSocket.close();
//        } catch (IOException e2) {
//
//            // Log .e(TAG,"ON RESUME: Unable to close socket during connection failure", e2);
//        }
//    }
    /***
     * handler+TimerTask 实现更新时间
     *
     * ***/
    Handler handler=new Handler(){
        public void handleMessage(android.os.Message msg) {
            switch (msg.what) {
                case 200:
                    SimpleDateFormat sDateFormat   = new SimpleDateFormat("yyyy-MM-dd    hh:mm:ss");
                    String    date    =    sDateFormat.format(new  java.util.Date());
                    textView_time.setText(date);
                    break;
            }

        }
    };
    TimerTask timerTask = new TimerTask() {

        @Override
        public void run() {
            Message message = new Message();
            message.what = 200;
            // message.obj = view;
            handler.sendMessage(message);
        }
    };



}
PHP中文网PHP中文网2813 Tage vor683

Antworte allen(0)Ich werde antworten

Keine Antwort
  • StornierenAntwort