Android Question [PROBLEM FOUND] Errors after change Http for OkHttp

Walter Adriano da Silva

Member
Licensed User
Longtime User
Hello

Once I changed HttpUtils2 with Http to OkHttp the application began to show some errors that were not displayed.

Errors like:

(Line: 145) If Not(res.EqualsIgnoreCase("1")) Then
java.lang.NullPointerException

"res" is the result from a Single Result Query.

I think that maybe the change from one library to another isn't the cause for this, but the errors started just after that I made the change.

Note: If I try use res in log, it's shown normally
 

Walter Adriano da Silva

Member
Licensed User
Longtime User
The problem here was incompatibility between OkHttp and Picasso Lib to B4A.

Follow the stack:
E/AndroidRuntime( 8423): FATAL EXCEPTION: main
E/AndroidRuntime( 8423): Process: my.package.name, PID: 8423
E/AndroidRuntime( 8423): java.lang.NoClassDefFoundError: com.squareup.okhttp.HttpResponseCache
E/AndroidRuntime( 8423): at com.squareup.picasso_OkHttpLoader.<init>(OkHttpLoader.java:58)
E/AndroidRuntime( 8423): at com.squareup.picasso_OkHttpLoader.<init>(OkHttpLoader.java:35)
E/AndroidRuntime( 8423): at com.squareup.picasso_OkHttpLoader.<init>(OkHttpLoader.java:25)
E/AndroidRuntime( 8423): at com.squareup.picasso.Utils$OkHttpLoaderCreator.create(Utils.java:287)
E/AndroidRuntime( 8423): at com.squareup.picasso.Utils.createDefaultLoader(Utils.java:199)
E/AndroidRuntime( 8423): at com.squareup.picasso.Picasso$Builder.build(Picasso.java:617)
E/AndroidRuntime( 8423): at com.squareup.picasso.Picasso.with(Picasso.java:542)
E/AndroidRuntime( 8423): at uk.co.martinpearman.b4a.squareup.picasso.Picasso.Initialize(Picasso.java:51)
E/AndroidRuntime( 8423): at my.package.name.main._activity_create(main.java:410)
E/AndroidRuntime( 8423): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 8423): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 8423): at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
E/AndroidRuntime( 8423): at my.package.name.main.afterFirstLayout(main.java:105)
E/AndroidRuntime( 8423): at my.package.name.main.access$000(main.java:20)
E/AndroidRuntime( 8423): at my.package.name.main$WaitForLayout.run(main.java:83)
E/AndroidRuntime( 8423): at android.os.Handler.handleCallback(Handler.java:733)
E/AndroidRuntime( 8423): at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime( 8423): at android.os.Looper.loop(Looper.java:149)
E/AndroidRuntime( 8423): at android.app.ActivityThread.main(ActivityThread.java:5257)
E/AndroidRuntime( 8423): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 8423): at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 8423): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime( 8423): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
E/AndroidRuntime( 8423): at dalvik.system.NativeStart.main(Native Method)
 
Upvote 0

KY Leng

Active Member
Licensed User
Longtime User
URL="http://www.open-electronics.org/celltrack/celltxt.php?hex=0&mcc=456&mnc=1&lac=60102&cid=66011439"
Job1.Download(URL)

And I got error as follow:

> Url: http://www.open-electronics.org/celltrack/celltxt.php?hex=0&mcc=456&mnc=1&lac=60102&cid=66011499
Error occurred on line: 120 (HttpJob)
java.lang.NullPointerException: Attempt to invoke virtual method 'void anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest.InitializeGet(java.lang.String)' on a null object reference
at MPTC.CID.Test.httpjob._download(httpjob.java:100)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:697)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:336)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5253)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)

When I pass the URL directly to browser, it work fine.
So, could you tell me what is the problem ?

Looking forward to hearing from you soon.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Looking forward to hearing from you soon.
1. You should start a new thread for your question
2. You should provide more information. Example project which shows the problem.
 
Upvote 0
Top