java.lang.NoSuchMethodError:没有直接方法<init>(Ljava / lang / Object;)

时间:2017-06-26 11:32:08

标签: java android

我有一个应用程序,当我开始ping此设备时,我连接了一个通过USB连接的设备,我的应用程序崩溃了。该设备是RFID扫描仪,通过USB连接到手机。手机和我的应用程序通过此扫描仪查看连接的手机。 这是一个代码:

   @Override
    public synchronized void run() {
        if (context == null || usbDevice == null) {
            onStatusChanged(Status.NoContextOrUsbDeviceSpecified);
            return;
        }


        //l("Device -> " + usbDevice);

        UsbInterface usbInterface = null;
        UsbEndpoint usbEndpointIn = null;
        UsbEndpoint usbEndpointOut = null;
        for (int i = 0; i < usbDevice.getInterfaceCount(); i++) {
            usbInterface = usbDevice.getInterface(i);
            //l("Interface[" + i + "] -> " + usbInterface);
            if (usbInterface != null) {
                    for (int j = 0; j < usbInterface.getEndpointCount(); j++) {
                        UsbEndpoint usbEndpoint = usbInterface.getEndpoint(j);
                        //l("Endpoint[" + j + "] -> " + usbEndpoint);
                        if (usbEndpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
                            if (usbEndpoint.getDirection() == UsbConstants.USB_DIR_IN) {
                                l("Found input!");
                                usbEndpointIn = usbEndpoint;
                            }
                            else {
                                l("Found output!");
                                usbEndpointOut = usbEndpoint;
                            }
                            if (usbEndpointIn != null && usbEndpointOut != null) {
                                break;
                            }
                        }
                    }
                    if (usbEndpointIn != null && usbEndpointOut != null) {
                        break;
                    }
            }
            else {
                //l("Interface was null");
            }
        }

        if (usbEndpointIn == null || usbEndpointOut == null) {
            onStatusChanged(Status.NoEndpointsFoundOnUsbDevice);
            return;
        }

        UsbManager usbManager = (UsbManager)context.getSystemService(Context.USB_SERVICE);
        UsbDeviceConnection usbDeviceConnection = usbManager.openDevice(usbDevice);

        if (usbDeviceConnection == null) {
            onStatusChanged(Status.CouldntOpenUsbDeviceConnection);

            return;
        }

        if (!usbDeviceConnection.claimInterface(usbInterface, true)) {
            onStatusChanged(Status.CouldntClaimUsbDeviceInterface);

            return;
        }

        onStatusChanged(Status.ScanningInitializing);

        currentUsbDeviceConnection = usbDeviceConnection;
        currentUsbInterface = usbInterface;
        currentUsbEndpointIn = usbEndpointIn;
        currentUsbEndpointOut = usbEndpointOut;

//        Toast.makeText(context,send(PING) + " wysłane" , Toast.LENGTH_LONG).show();
        final String[] a = new String[1];
        pingingThread = new Thread(() -> {
            onStatusChanged(Status.PingStarted);
            String s = "";
            for (byte aPING : PING) {
                s = s + aPING;
            }
            Log.e("Ping " , s);
            String aa ="";
            for (byte aACK : ACK) {
                aa = aa + aACK;
            }
            Log.e("ACK " , aa);



            while (shouldPing && !Thread.interrupted()) {
                if (send(PING) >= 0) {
                    onStatusChanged(Status.PingSuccessful);
                } else {
                    onStatusChanged(Status.PingFailed);
                }
                SystemClock.sleep(PING_RECEIVE_TIMEOUT / 3);
            }
            onStatusChanged(Status.PingStopped);
            scheduleStopReceiving();
        });
        byte[] bytes = new byte[36];
        int result = currentUsbDeviceConnection.bulkTransfer(currentUsbEndpointIn, bytes, bytes.length, RECEIVE_TIMEOUT);
//        Toast.makeText(context, "result " + result , Toast.LENGTH_LONG ).show();
        receivingThread = new Thread(() -> {
            onStatusChanged(Status.ReceivingStarted);
            long lastTagTimestamp = 0;
            boolean wasInterrupted = false;
            while (shouldReceive) {
                byte[] received = receive(36);
                if (received != null) {
                    if (received[0] != (byte) 0xab ||
                            received[1] != (byte) 0xba ||
                            received[2] != (byte) 0xcd ||
                            received[3] != (byte) 0xdc) {
                        onStatusChanged(Status.ReceivedUnknown);
                    } else if (received[4] == 0x00) {
                        if (send(ACK) < 0) {
                            continue;
                        }
                        onStatusChanged(Status.ReceivedTag);
                        lastTagTimestamp = System.currentTimeMillis();
                        byte[] tag = new byte[8];
                        int index = 0;
                        while (index < tag.length) {
                            tag[index++] = received[8 + index];
                        }
                        long longValue = ByteBuffer.wrap(tag).getLong();
                        String hexValue = Long.toHexString(longValue).toUpperCase();
                        onScanCompleted(hexValue);
                    } else if (received[4] == 0x02) {
                        onStatusChanged(Status.ReceivedPing);
                    }
                }
                if (Thread.interrupted()) {
                    wasInterrupted = true;
                }
                if (wasInterrupted) {
                    if (lastTagTimestamp == 0) {
                        lastTagTimestamp = System.currentTimeMillis();
                    }
                    if (lastTagTimestamp + PING_RECEIVE_TIMEOUT < System.currentTimeMillis()) {
                        break;
                    }
                }
            }
            onStatusChanged(Status.ReceivingStopped);
            close();
        });

        shouldPing = true;
        shouldReceive = true;

        pingingThread.start();
        receivingThread.start();
    }

在这一行我有

  

java.lang.NoSuchMethodError:没有直接的方法   (Ljava / lang / Object;)V级   Lrest /你好/组织/ usbdevice / rfid2 / - $ LAMBDA $ 2;或者它的超级课程   ('rest.hello.org.usbdevice.rfid2 .- $ Lambda $ 2'的声明出现在   /data/app/rest.hello.org.usbdevice-2/base.apk)

pingingThread = new Thread(() -> {
        onStatusChanged(Status.PingStarted);
        String s = "";
        for (byte aPING : PING) {
            s = s + aPING;
        }
        Log.e("Ping " , s);
        String aa ="";
        for (byte aACK : ACK) {
            aa = aa + aACK;
        }
        Log.e("ACK " , aa);

0 个答案:

没有答案