Click here to Skip to main content
15,894,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Following code is throwing the Exception Length = 0 index = 0

Java
try
{
    UsbDeviceConnection connection = manager.openDevice(device);
    UsbInterface intf = device.getInterface(0);
    UsbEndpoint endpoint = intf.getEndpoint(0);
    int direction = endpoint.getDirection();
    Toast.makeText(StartActivity.this,"Direction Of Data Transfer :"+direction,Toast.LENGTH_SHORT).show();
    ByteBuffer recvBuffer = ByteBuffer.allocate(endpoint.getMaxPacketSize());
    recvBuffer.clear();
    UsbRequest request = new UsbRequest();
    request.initialize(connection, endpoint);
    UsbRequest finishReq;
    while ((finishReq = connection.requestWait()) != request) {
        if (finishReq == null)
            throw new IOException("Request failed.");
        int res  = connection.bulkTransfer(endpoint,b,"Hello".length(), 100);
        if(res==1)
            Toast.makeText(this, "Failed :" , Toast.LENGTH_LONG).show();
        
        Thread.sleep(100);
    }
}
catch(Exception e)
{
    Toast.makeTest(this,"Exception :"+e.getMessagage,Toast.LENGTH_LONG).show();
}

what could be the problem??
Posted
Updated 6-Jan-15 0:21am
v6
Comments
Richard MacCutchan 6-Jan-15 5:28am    
What is the problem?
Could be any one of a million things, but without more information it's anyone's guess. Please edit your question and show exactly where the exception occurs and what are the values of the variables involved.
CHill60 6-Jan-15 5:54am    
Please follow the advice from Richard MacCutchan - exactly where does the exception occur and what are the values of the variables at that point - use the debugger to get this information
Sarita S 6-Jan-15 5:54am    
I think Its throwing the exception on following sentence.
UsbInterface intf = device.getInterface(0);
UsbEndpoint endpoint = intf.getEndpoint(0);
Richard MacCutchan 6-Jan-15 6:22am    
You think? Would it not be better to use your debugger and find out exactly?
Sergey Alexandrovich Kryukov 6-Jan-15 13:13pm    
Just one advice: always output also the full type name of the exception, at the very least. For debugging purpose, you may also need more: exception stack, inner exception, etc... This additional information may also be important when you ask questions here.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900