Unable to understand an error from extension

Hello everyone, i’m trying to get an advice or something from a extension developer or knowledged programmer. I’m trying to make an extension for a personal project that is able to create a socket for sending bytes to a device via its ip address. This is my code.

The code is working as i tested it on netbeans and the device recieves the data.
But now trying to covert it as an extension, it doesnt work.
The extensions is succesfully compiled using rush. But when i try to test it crashes.
The problem is, i’ve tried to trace the error using:

e.printStackTrace();
Log.e(ACRA.LOG_TAG, “IOException”, (Throwable) e);
Toast.makeText(this.context, e.toString(), 0).show();

but i only get this:
undefined_error

I also tried via adb using

adb logcat | findstr io.makeroid.companion

But i only see a “System.err” with no information.

Maybe i can get some help for tracing the error, thanks.

You should really do adb logcat -d > C:\users\username\desktop\logcat.txt and then search either the companions package name, or your extensions package name. This should give a better error to look at.

1 Like

Make sure that code is not being executed on main thread.

1 Like

Thanks, now my code is like this:
image

But it’s not working either.

@mmnettime Anything that doesn’t update the UI can run perfectly fine on the main thread. No need to add additional code if you don’t need it!

@mmnettime bytes should be a final variable.
Also you should add an event for success or failure.

You mean including network related operations or excluding?

1 Like

@vknow360 From Android documentation

“Specifically, if everything is happening in the UI thread, performing long operations such as network access or database queries will block the whole UI.”

The UI thread is meant to be used for UI modifications (an addition, a change, or a removal of a “widget”). For example, setting text on a label would require that to be done on the UI thread. Sending data from one device to another, shouldn’t be done on the UI thread.

@vknow360 @hammerhai
Finally i was able to log the error, and i got this line on logcat:

07-06 03:08:02.798 15900 15900 W System.err: at mmnettime.socket.Socket.SendData(Unknown Source)

So the problem now is the YailList conversion to byte array. I’ve tried this:
image

And it throws:

java.lang.Object[] cannot be cast to java.util.ArrayList

Your list variable is a YailList. When you use this method list.toArray(); then it returns a Object[ ] not an array list and you can’t cast Object[ ] to a array list. In your code you’re using array list to convert it’s item to byte. You can do this same with Object[ ] by replacing your Array List to Object[ ] then why are you casting Object[ ] to an ArrayList?

1 Like

Object[] can’t be converted to ArrayList.

1 Like

@iamwsumit @vknow360
I’ve solved it like this:

i don’t know if it’s the best on performance. But now it’s working and the device received the data successfully