Closed adonnini closed 6 years ago
Hi,
I realize that there may not be a problem with my configuration, and that I just need to move the network access code off to an async task. I'll do that and see if there is any problem afterward.
Thanks,
Alex Donnini
Hi,
I'm all set. After moving all network related operations to async tasks, everything seems to work.
Alex Donnini
Hi,
I was finally able to set up a transaction in my Android application. See my code below.
(I think) it fails to access the test network. Here is the relevant code:
I am using the URL taken for node.js from here
https://testnet.bigchaindb.com/
Am I using the right URL for the test network?
Thanks,
Alex Donnini
CODE
// TODO Auto-generated catch block e6.printStackTrace(); }
// prepare your keys
// Set up your transaction
String[][] assetData = new String [4][2];
String assetDataString = ""; StringBuilder s = new StringBuilder();
assetData[0][0] = "mobile_user_information"; assetData[0][1] = ""; assetData[1][0] = "first_name"; assetData[1][1] = "John"; assetData[2][0] = "last_name"; assetData[2][1] = "Smith"; assetData[3][0] = "mobile_profile"; assetData[3][1] = userLocationInformationDatabaseExtract;
for(int i = 0; i < 3; ++i) { s.append(assetData[i][0]); s.append(" : "); s.append(assetData[i][1]); s.append(" -- "); }
assetDataString = s.toString();
try { Transaction transaction0 = BigchainDbTransactionBuilder.init() .addAssets(assetDataString, String.class) .addMetaData("what - "+"My first BigchainDB transaction") .addMetaData("this - "+"My 1st metadata BigchainDB transaction") .operation(Operations.CREATE) .buildOnly((EdDSAPublicKey) keyPair.getPublic()); // .buildOnly((EdDSAPublicKey) keyPair.getPublic(), (EdDSAPrivateKey) keyPair.getPrivate()); } catch (Exception e5) { // TODO Auto-generated catch block e5.printStackTrace(); }
//try { // Transaction transaction0 = BigchainDbTransactionBuilder.init() // .addAsset("firstname", "John") // .addAsset("lastname", "Smith") // .addAsset("My mobile profile", userLocationInformationDatabaseExtract) // .addMetaData("what", "My first BigchainDB transaction") // .addMetaData("this", "My 1st metadata BigchainDB transaction") // .operation(Operations.CREATE) // .buildOnly((EdDSAPublicKey) keyPair.getPublic()); //// .buildOnly((EdDSAPublicKey) keyPair.getPublic(), (EdDSAPrivateKey) keyPair.getPrivate()); //} catch (Exception e5) { //// TODO Auto-generated catch block // e5.printStackTrace(); //}
// .addAsset("firstname", "John") // .addAsset("lastname", "Smith") // .addAsset("My mobile profile", userLocationInformationDatabaseExtract) .addMetaData("what - "+"My first BigchainDB transaction") .addMetaData("this - "+"My 1st metadata BigchainDB transaction") // .addMetaData("what", "My second BigchainDB transaction") // .addMetaData("this", "My 2nd metadata BigchainDB transaction") .operation(Operations.CREATE) // .buildAndSign((EdDSAPublicKey) keyPair.getPublic(), (EdDSAPrivateKey) keyPair.getPrivate()); // .buildOnly((EdDSAPublicKey) keyPair.getPublic()); .buildAndSignOnly((EdDSAPublicKey) keyPair.getPublic(), (EdDSAPrivateKey) keyPair.getPrivate()); // .sendTransaction(); } catch (Exception e4) { // TODO Auto-generated catch block e4.printStackTrace(); }
// .addAsset("firstname", "John") // .addAsset("lastname", "Smith") // .addAsset("My mobile profile", userLocationInformationDatabaseExtract) .addMetaData("what - "+"My first BigchainDB transaction") .addMetaData("this - "+"My 1st metadata BigchainDB transaction") // .addMetaData("what", "My third BigchainDB transaction") // .addMetaData("this", "My 3rd metadata BigchainDB transaction") .operation(Operations.CREATE) .buildAndSign((EdDSAPublicKey) keyPair.getPublic(), (EdDSAPrivateKey) keyPair.getPrivate()) .sendTransaction(); } catch (IOException e3) { // TODO Auto-generated catch block e3.printStackTrace(); }
ERROR LOG
02-23 23:39:19.901: I/BigchainDbConfigBuilder(22244): https://test.bigchaindb.com/api/v1/ 02-23 23:39:19.909: D/NetworkSecurityConfig(22244): No Network Security Config specified, using platform default 02-23 23:39:19.914: W/System.err(22244): android.os.NetworkOnMainThreadException 02-23 23:39:19.915: W/System.err(22244): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1448) 02-23 23:39:19.915: W/System.err(22244): at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:102) 02-23 23:39:19.915: W/System.err(22244): at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:90) 02-23 23:39:19.915: W/System.err(22244): at java.net.InetAddress.getAllByName(InetAddress.java:787) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.Dns$1.lookup(Dns.java:40) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:185) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.java:149) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:84) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:213) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 02-23 23:39:19.915: W/System.err(22244): at src.main.java.com.authenteq.builders.BigchainDbConfigBuilder$Builder$2.intercept(BigchainDbConfigBuilder.java:190) 02-23 23:39:19.915: W/System.err(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) 02-23 23:39:19.916: W/System.err(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) 02-23 23:39:19.916: W/System.err(22244): at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200) 02-23 23:39:19.916: W/System.err(22244): at okhttp3.RealCall.execute(RealCall.java:77) 02-23 23:39:19.916: W/System.err(22244): at src.main.java.com.authenteq.util.NetworkUtils.sendGetRequest(NetworkUtils.java:79) 02-23 23:39:19.916: W/System.err(22244): at src.main.java.com.authenteq.builders.BigchainDbConfigBuilder$Builder.setup(BigchainDbConfigBuilder.java:139) 02-23 23:39:19.916: W/System.err(22244): at com.android.commmanager.continuouslocationtrackingservice.UserAndPoiProcessing.(UserAndPoiProcessing.java:854)
02-23 23:39:19.916: W/System.err(22244): at com.android.commmanager.ApLocationCowPaths.onCreate(ApLocationCowPaths.java:894)
02-23 23:39:19.916: W/System.err(22244): at android.app.Activity.performCreate(Activity.java:6975)
02-23 23:39:19.916: W/System.err(22244): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
02-23 23:39:19.916: W/System.err(22244): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2779)
02-23 23:39:19.916: W/System.err(22244): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2904)
02-23 23:39:19.916: W/System.err(22244): at android.app.ActivityThread.-wrap11(Unknown Source:0)
02-23 23:39:19.916: W/System.err(22244): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1596)
02-23 23:39:19.916: W/System.err(22244): at android.os.Handler.dispatchMessage(Handler.java:105)
02-23 23:39:19.916: W/System.err(22244): at android.os.Looper.loop(Looper.java:164)
02-23 23:39:19.916: W/System.err(22244): at android.app.ActivityThread.main(ActivityThread.java:6600)
02-23 23:39:19.916: W/System.err(22244): at java.lang.reflect.Method.invoke(Native Method)
02-23 23:39:19.916: W/System.err(22244): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
02-23 23:39:19.916: W/System.err(22244): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:772)
02-23 23:39:20.544: I/zygote64(22244): Do full code cache collection, code=250KB, data=160KB
02-23 23:39:20.544: I/zygote64(22244): After code cache collection, code=235KB, data=119KB
02-23 23:39:20.560: I/ainDbTransactionBuilder(22244): TO BE HASHED ---->
02-23 23:39:20.560: I/ainDbTransactionBuilder(22244): {"asset":{"data":"mobile_user_information : -- first_name : John -- last_name : Smith -- "},"inputs":[{"fulfills":null,"fulfillment":null,"owners_before":["8yKGtBJqNa8yFk6C5gj5rxrPTr9XovALifnKZj1jVxGA"]}],"metadata":"this - My 1st metadata BigchainDB transaction","operation":"CREATE","outputs":[{"amount":"1","condition":{"details":{"public_key":"8yKGtBJqNa8yFk6C5gj5rxrPTr9XovALifnKZj1jVxGA","type":"ed25519-sha-256"},"uri":"ni:///sha-256;V60F5fjnugBZDWo3YSvYDonuz3FvNnLLTQu1P1tRwos?fpt=ed25519-sha-256&cost=131072"},"public_keys":["8yKGtBJqNa8yFk6C5gj5rxrPTr9XovALifnKZj1jVxGA"]}],"version":"1.0"}
02-23 23:39:20.560: I/ainDbTransactionBuilder(22244): <
02-23 23:39:20.577: I/zygote64(22244): Do partial code cache collection, code=251KB, data=133KB
02-23 23:39:20.577: I/zygote64(22244): After code cache collection, code=251KB, data=133KB
02-23 23:39:20.577: I/zygote64(22244): Increasing code cache capacity to 1024KB
02-23 23:39:20.579: I/ainDbTransactionBuilder(22244): TO BE HASHED ---->
02-23 23:39:20.579: I/ainDbTransactionBuilder(22244): {"asset":{"data":"mobile_user_information : -- first_name : John -- last_name : Smith -- "},"inputs":[{"fulfills":null,"fulfillment":null,"owners_before":["8yKGtBJqNa8yFk6C5gj5rxrPTr9XovALifnKZj1jVxGA"]}],"metadata":"this - My 1st metadata BigchainDB transaction","operation":"CREATE","outputs":[{"amount":"1","condition":{"details":{"public_key":"8yKGtBJqNa8yFk6C5gj5rxrPTr9XovALifnKZj1jVxGA","type":"ed25519-sha-256"},"uri":"ni:///sha-256;V60F5fjnugBZDWo3YSvYDonuz3FvNnLLTQu1P1tRwos?fpt=ed25519-sha-256&cost=131072"},"public_keys":["8yKGtBJqNa8yFk6C5gj5rxrPTr9XovALifnKZj1jVxGA"]}],"version":"1.0"}
02-23 23:39:20.579: I/ainDbTransactionBuilder(22244): <
02-23 23:39:20.625: I/ainDbTransactionBuilder(22244): TO BE HASHED ---->
02-23 23:39:20.625: I/ainDbTransactionBuilder(22244): {"asset":{"data":"mobile_user_information : -- first_name : John -- last_name : Smith -- "},"inputs":[{"fulfills":null,"fulfillment":null,"owners_before":["8yKGtBJqNa8yFk6C5gj5rxrPTr9XovALifnKZj1jVxGA"]}],"metadata":"this - My 1st metadata BigchainDB transaction","operation":"CREATE","outputs":[{"amount":"1","condition":{"details":{"public_key":"8yKGtBJqNa8yFk6C5gj5rxrPTr9XovALifnKZj1jVxGA","type":"ed25519-sha-256"},"uri":"ni:///sha-256;V60F5fjnugBZDWo3YSvYDonuz3FvNnLLTQu1P1tRwos?fpt=ed25519-sha-256&cost=131072"},"public_keys":["8yKGtBJqNa8yFk6C5gj5rxrPTr9XovALifnKZj1jVxGA"]}],"version":"1.0"}
02-23 23:39:20.625: I/ainDbTransactionBuilder(22244): <
02-23 23:39:20.668: I/TransactionsApi(22244): sendTransaction Call :{"asset":{"data":"mobile_user_information : -- first_name : John -- last_name : Smith -- "},"id":"c3f1885f22ff6d1c7a4dfa0114169048230a0ab3dc4ce0e422aea7745685679e","inputs":[{"fulfills":null,"fulfillment":"pGSAIHZu_v9Geiify5gRdc7eyXEBUeX-4-njpDIGV3i3d8GrgUC-05NEpjumOfF5uAU5me2np_3Qka8bvUCcRG0vNy_C9Mh7ZK7Q4JK8oHJyci8IKCnZIWlK3lBol4l6vm1qQ9cP","owners_before":["8yKGtBJqNa8yFk6C5gj5rxrPTr9XovALifnKZj1jVxGA"]}],"metadata":"this - My 1st metadata BigchainDB transaction","operation":"CREATE","outputs":[{"amount":"1","condition":{"details":{"public_key":"8yKGtBJqNa8yFk6C5gj5rxrPTr9XovALifnKZj1jVxGA","type":"ed25519-sha-256"},"uri":"ni:///sha-256;V60F5fjnugBZDWo3YSvYDonuz3FvNnLLTQu1P1tRwos?fpt=ed25519-sha-256&cost=131072"},"public_keys":["8yKGtBJqNa8yFk6C5gj5rxrPTr9XovALifnKZj1jVxGA"]}],"version":"1.0"}
02-23 23:39:20.678: D/AndroidRuntime(22244): Shutting down VM
02-23 23:39:20.680: E/AndroidRuntime(22244): FATAL EXCEPTION: main
02-23 23:39:20.680: E/AndroidRuntime(22244): Process: com.android.commmanager, PID: 22244
02-23 23:39:20.680: E/AndroidRuntime(22244): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.commmanager/com.android.commmanager.ApLocationCowPaths}: android.os.NetworkOnMainThreadException
02-23 23:39:20.680: E/AndroidRuntime(22244): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2826)
02-23 23:39:20.680: E/AndroidRuntime(22244): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2904)
02-23 23:39:20.680: E/AndroidRuntime(22244): at android.app.ActivityThread.-wrap11(Unknown Source:0)
02-23 23:39:20.680: E/AndroidRuntime(22244): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1596)
02-23 23:39:20.680: E/AndroidRuntime(22244): at android.os.Handler.dispatchMessage(Handler.java:105)
02-23 23:39:20.680: E/AndroidRuntime(22244): at android.os.Looper.loop(Looper.java:164)
02-23 23:39:20.680: E/AndroidRuntime(22244): at android.app.ActivityThread.main(ActivityThread.java:6600)
02-23 23:39:20.680: E/AndroidRuntime(22244): at java.lang.reflect.Method.invoke(Native Method)
02-23 23:39:20.680: E/AndroidRuntime(22244): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
02-23 23:39:20.680: E/AndroidRuntime(22244): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:772)
02-23 23:39:20.680: E/AndroidRuntime(22244): Caused by: android.os.NetworkOnMainThreadException
02-23 23:39:20.680: E/AndroidRuntime(22244): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1448)
02-23 23:39:20.680: E/AndroidRuntime(22244): at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:102)
02-23 23:39:20.680: E/AndroidRuntime(22244): at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:90)
02-23 23:39:20.680: E/AndroidRuntime(22244): at java.net.InetAddress.getAllByName(InetAddress.java:787)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.Dns$1.lookup(Dns.java:40)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:185)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.java:149)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:84)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:213)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
02-23 23:39:20.680: E/AndroidRuntime(22244): at src.main.java.com.authenteq.builders.BigchainDbConfigBuilder$Builder$2.intercept(BigchainDbConfigBuilder.java:190)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
02-23 23:39:20.680: E/AndroidRuntime(22244): at okhttp3.RealCall.execute(RealCall.java:77)
02-23 23:39:20.680: E/AndroidRuntime(22244): at src.main.java.com.authenteq.util.NetworkUtils.sendPostRequest(NetworkUtils.java:67)
02-23 23:39:20.680: E/AndroidRuntime(22244): at src.main.java.com.authenteq.api.TransactionsApi.sendTransaction(TransactionsApi.java:49)
02-23 23:39:20.680: E/AndroidRuntime(22244): at src.main.java.com.authenteq.builders.BigchainDbTransactionBuilder$Builder.sendTransaction(BigchainDbTransactionBuilder.java:470)
02-23 23:39:20.680: E/AndroidRuntime(22244): at com.android.commmanager.continuouslocationtrackingservice.UserAndPoiProcessing.(UserAndPoiProcessing.java:956)
02-23 23:39:20.680: E/AndroidRuntime(22244): at com.android.commmanager.ApLocationCowPaths.onCreate(ApLocationCowPaths.java:894)
02-23 23:39:20.680: E/AndroidRuntime(22244): at android.app.Activity.performCreate(Activity.java:6975)
02-23 23:39:20.680: E/AndroidRuntime(22244): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
02-23 23:39:20.680: E/AndroidRuntime(22244): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2779)
02-23 23:39:20.680: E/AndroidRuntime(22244): ... 9 more
02-23 23:39:20.682: W/ActivityManager(1161): Force finishing activity com.android.commmanager/.ApLocationCowPaths
02-23 23:39:20.684: W/ActivityManager(1161): Force finishing activity com.android.commmanager/.CommManager
02-23 23:39:20.686: I/ActivityManager(1161): Showing crash dialog for package com.android.commmanager u0