0

I am trying to use the balanceOf function after the generation of our smart contract (pakoin) function wrappers in Java with Web3j. Despite trying different ways, I get plenty of errors and I don't know how to solve them.

First of all, I tried doing this way:

BigInteger balance = pakoin.balanceOf(publicKeyUser).send();

result= balance.toString();

However, instead of printing the balance, the app suddenly closes and I have the following error on the console:

12-30 10:47:55.215 29089-29105/com.daedasan.sgssi_pakos E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.daedasan.sgssi_pakos, PID: 29089
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:318)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354) at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761)
Caused by: java.lang.NoSuchMethodError: No interface method getTypeName()Ljava/lang/String; in class Ljava/lang/reflect/Type; or its super classes (declaration of 'java.lang.reflect.Type' appears in /system/framework/core-oj.jar)
at org.web3j.abi.TypeReference.getClassType(TypeReference.java:54)
at org.web3j.abi.FunctionReturnDecoder.build(FunctionReturnDecoder.java:99) at org.web3j.abi.FunctionReturnDecoder.decode(FunctionReturnDecoder.java:42) at org.web3j.tx.Contract.executeCall(Contract.java:159)
at org.web3j.tx.Contract.executeCallSingleValueReturn(Contract.java:165) at org.web3j.tx.Contract.executeCallSingleValueReturn(Contract.java:176) at org.web3j.tx.Contract.lambda$executeRemoteCallSingleValueReturn$1$Contract(Contract.java:232) at org.web3j.tx.Contract$$Lambda$1.call(Unknown Source)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)
at com.daedasan.sgssi_pakos.MainActivity$ReadTask.doInBackground(MainActivity.java:199) at com.daedasan.sgssi_pakos.MainActivity$ReadTask.doInBackground(MainActivity.java:181) at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761)
Enviado en: 11:49 Enviado en: 11:49

Afterwards, based on an example I found online, I tried this way:

BigInteger balance = pakoin.balanceOf(publicKeyUser).sendAsync().get();

result= balance.toString();

This doesn't work either. I get the following exception: exception

Q: Do you know how to solve this problem or another way to do it?
Thank you in advance!

0

You might find useful information in the following project.

https://github.com/web3j/web3j/tree/master/integration-tests/src/test

0

I think that the problem is probably that you're not running a local ethereum node (which you could never do on android anyway) using most of the web3 functionality requires an ethereum node to connect to. Often this is a local instance of Geth or parity but you could also us a service like infura. Then using somthing like web3.setProvider(...)(I haven't used Web3j, only web3.js so you'll have to read docs for details but if you search for 'provider' it should get you on the right track) Getting ethereum/web3 running on mobile can be pretty tricky

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.