获取接收java.lang.RuntimeException:无法销毁活动{com.android.systemui / com.android.systemui.usb.UsbPermissionActivity}

时间:2014-12-09 09:37:47

标签: java android usb

获取接收java.lang.RuntimeException:无法销毁活动{com.android.systemui / com.android.systemui.usb.UsbPermissionActivity}

这是onClickListener之后的代码:

login.setOnClickListener(new View.OnClickListener() 
        {
            @Override
            public void onClick(View v)
            {

                String User_Name;
                User_Name=username.getText().toString();
                Device_Found=0;
                if(User_Name.toLowerCase().equals("medequip") && password.getText().toString().equals("medequip"))
                {
                    Communication_Ok=0; Permission_Error=0;
                    checkdeviceconnection();
                    if(Device_Found==1)
                    {
                        Data_Rx_Index=Data_Index=setTotal_Frame_Received(0);
                        if(Permission_Error==1)
                        checkdeviceconnection();
                        Receive.start();
                        long i,j;
                        for(i=0;i<1000;i++)
                        for(j=0;j<1000;j++);
                        if(Communication_Ok==1)
                            Toast.makeText(Medequiplogin.this, "Communication_Ok", 10000).show();
                        else
                            Toast.makeText(Medequiplogin.this, "Communication Failure", 10000).show();
                            Intent i3 = new Intent(Medequiplogin.this,Modes.class);
                            startActivity(i3);
                    }
                  else  
                  {   Toast.makeText(Medequiplogin.this, "Device Connection Problem", 10000).show();        
                    return;}
                }

                else
                {
                    Toast.makeText(Medequiplogin.this, "Plesae Enter valid Username and Password", 10000).show();
                }

            }

        });
        clear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                username.setText("");
                password.setText("");

            }
        }); 
    }



    protected void checkdeviceconnection() 
    {
        int i,j;
        String as[];
        UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
        HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
        i = deviceList.size();
        if(i==0)
        {
             return;
        }
        as = new String[i];
        deviceList.keySet().toArray(as);

        for(j=0;j<i;j++)
        {
            Device_Detials = (UsbDevice)deviceList.get(as[j]);
            if((Device_Detials.getVendorId()==targetVendorID) && (Device_Detials.getProductId()==targetProductID))
            {
                    break;
            }

        }


        if(Device_Detials!=null)
        {
        usbManager = (UsbManager)getSystemService(Context.USB_SERVICE);
            if(usbManager.hasPermission(Device_Detials)==true)
            {
            //  Toast.makeText(Medequiplogin.this, "Permission Granted", Toast.LENGTH_LONG).show(); 
                Device_Settings(Device_Detials,j);
            }
            else
            {
                //PendingIntent  intent = null;
          //    Toast.makeText(Medequiplogin.this, "No Permission", Toast.LENGTH_LONG).show(); 
                usbManager.requestPermission(Device_Detials, null); 
                Permission_Error=1;

                return;         
            }
        Device_Settings(Device_Detials,j);


        }       
    }   

UsbDeviceConnection Device_Settings(UsbDevice device,int Port_No)
{
    UsbEndpoint tOut = null;
    UsbEndpoint tIn = null;
    UsbInterface usbinterface = device.getInterface(Port_No);

    if (usbinterface == null) 
    {
        Toast.makeText(Medequiplogin.this, "Device Found But UnKnown Exception-1", 50000).show();  
        return null;
    }
    int tEndpointCnt = usbinterface.getEndpointCount();
    if (tEndpointCnt >= 2)
    {
        for (int j = 0; j < tEndpointCnt; j++)
        {
            if (usbinterface.getEndpoint(j).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK)
                {
                    if (usbinterface.getEndpoint(j).getDirection() == UsbConstants.USB_DIR_OUT) 
                    {
                        tOut = usbinterface.getEndpoint(j);
                    }   
                    else if (usbinterface.getEndpoint(j).getDirection() == UsbConstants.USB_DIR_IN)
                    {
                        tIn = usbinterface.getEndpoint(j);
                    }
                }
        }   
        if (tOut != null && tIn != null) 
        {
            usbInterfaceFound = usbinterface;   
            endpointOut = tOut;         
            endpointIn = tIn;
            deviceFound = device;
            if (device != null) 

            {

                Toast.makeText(Medequiplogin.this, device+" ", Toast.LENGTH_LONG).show(); 
                UsbDeviceConnection connection = usbManager.openDevice(device);
                if (connection != null && connection.claimInterface(usbInterfaceFound, true)) 
                {

                    connection.controlTransfer(0x21, 34, 0, 0, null, 0, 0);
                    connection.controlTransfer(0x21, 32, 0, 0, new byte[] { (byte) 0x80, 0x25, 0x00, 0x00, 0x00, 0x00, 0x08 }, 7, 0);
                    usbDeviceConnection = connection;
                    usbDeviceConnection_For_Transfer = connection;
                    Communication_Byte[0]='&';
                    usbDeviceConnection.bulkTransfer(endpointOut,Communication_Byte, 1, 0);
                    Device_Found=1;
                    return usbDeviceConnection;

                }

                else 
                {
                    Toast.makeText(Medequiplogin.this, "Device Found But Unable to Open Device(Exception-3)", 50000).show();
                    usbDeviceConnection = null;
                }

        }
    }
        else
        {
            Toast.makeText(Medequiplogin.this, "Device Found But No End Points(Exception-4)", 50000).show();
        }

    }
    else
    {
        Toast.makeText(Medequiplogin.this, "Device Found But No End Points(Exception-2)", 50000).show();  
        return null;

    }
    return null;
}

这是我的logcat:

FATAL EXCEPTION: main
 java.lang.RuntimeException: Unable to destroy activity {com.android.systemui/com.android.systemui.usb.UsbPermissionActivity}: java.lang.NullPointerException
     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3499)
     at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3517)
     at android.app.ActivityThread.access$1200(ActivityThread.java:141)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
     at android.os.Handler.dispatchMessage(Handler.java:99)
     at android.os.Looper.loop(Looper.java:137)
     at android.app.ActivityThread.main(ActivityThread.java:5103)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:525)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
     at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.NullPointerException
     at com.android.systemui.usb.UsbPermissionActivity.onDestroy(UsbPermissionActivity.java:148)
     at android.app.Activity.performDestroy(Activity.java:5302)
     at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1117)
     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3486)

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.medequip.irisandroid"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Home_Page"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".Medequiplogin"
            android:icon="@drawable/login"
            android:label="@string/title_activity_medequiplogin" >
        </activity>

        <intent-filter>
            <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
        </intent-filter>

        <meta-data
            android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
            android:resource="@xml/device_filter" />

        <activity
            android:name=".Modes"
            android:icon="@drawable/mode"
            android:label="@string/title_activity_modes" >
        </activity>
        <activity
            android:name=".ManualMode"
            android:icon="@drawable/manual"
            android:label="@string/title_activity_manual_mode" >
        </activity>
        <activity
            android:name=".Tablelayout"
            android:label="@string/title_activity_tablelayout" >
        </activity>
        <activity
            android:name=".AutoMode"
            android:icon="@drawable/auto"
            android:label="@string/title_activity_auto_mode" >
        </activity>
        <activity
            android:name=".Graph_Demo_val"
            android:icon="@drawable/line"
            android:label="@string/title_activity_Graph_Demo" >
        </activity>

    </application>

</manifest>

0 个答案:

没有答案