0

Trying to parse data to establish a connection between a device and a test server. Except, I get a red line on (toParse) within String parsedMessage = (String)comm.parse(toParse).getPayload(); with the error parse(byte[]) in Communicator cannot be applied to (java.lang.String)

I have tried to change String toParse to byte[] toParse and it makes the red line go away for parse(toParse) but the byte[] toParse turns red instead with the error "required byte[], found java.lang.String"

Communicator comm = new 
Communicatior(InstrumentationRegistry.getTargetContext());
String toParse = "88819188181A7";
String parsedMessage = (String)comm.parse(toParse).getPayload();

1 Answer 1

1

Try to invoke the method getBytes() like this:

String parsedMessage = (String)comm.parse(toParse.getBytes()).getPayload();
Sign up to request clarification or add additional context in comments.

3 Comments

I ran a test and I got this error java.lang.ClassCastException: byte[] cannot be cast to java.lang.String for the line String parsedMessage = (String)comm.parse(toParse.getBytes()).getPayload();
Can you tell me what is the return type of the method getPayload()?
Sure, it is a String. String type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.