Android Question java.lang.nullpointerexception

Tomas Petrus

Active Member
Licensed User
Longtime User
hi guys
another problem ... on all my devices everything works fine.

but google pre release testing and some testers from client end up with:
B4X:
[B]java.lang.NullPointerException[/B]:
at cz.esol.xxxxxxx.main._geocoder1_geocodedone (main.java:973)
at java.lang.reflect.Method.invoke (Native Method)
at anywheresoftware.b4a.BA.raiseEvent2 (BA.java:186)
at anywheresoftware.b4a.BA$2.run (BA.java:360)
at android.os.Handler.handleCallback (Handler.java:739)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:168)
at android.app.ActivityThread.main (ActivityThread.java:5885)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:687)

The code responsible for that is this:
B4X:
Sub Geocoder1_GeocodeDone(Results() As Address, Tag As Object)
    If Results <> Null Then 
        If Results.Length>0 Then
            Dim Address1 As Address
            Dim i As Int
            For i=0 To Results.Length-1
                Address1=Results(i)
....

I tried to handle it by "If Results <> Null Then" but it seems it doesnt work. the worst thing is that I cant simulate that on any of my devices.
So I cant play around and try different things because that hellish error never apear to me whatever I do.

Thanks for advices
 

Tomas Petrus

Active Member
Licensed User
Longtime User
EDIT: found out that this one with illegal state is from the old version of app. So it is solved by the new one. But anyway how to read / debug this ?

and another from google reports.. this one I even dont know where to start looking..for the prob.
adding view in job done ? Loading content of webview in job done ? no clue...

B4X:
java.lang.IllegalStateException:
at android.view.ViewGroup.addViewInner (ViewGroup.java:5122)
at android.view.ViewGroup.addView (ViewGroup.java:4953)
at android.view.ViewGroup.addView (ViewGroup.java:4925)
at anywheresoftware.b4a.objects.ActivityWrapper.AddView (ActivityWrapper.java:124)
at cz.esol.xxxxxxx.main._jobdone (main.java:541)
at java.lang.reflect.Method.invoke (Native Method)
at anywheresoftware.b4a.BA.raiseEvent2 (BA.java:169)
at anywheresoftware.b4a.keywords.Common$5.run (Common.java:996)
at android.os.Handler.handleCallback (Handler.java:789)
at android.os.Handler.dispatchMessage (Handler.java:98)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6938)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
 
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
from google prelease testing I got from some devices:

B4X:
FATAL EXCEPTION: main
Process: cz.esol.xxxxxxx.main, PID: 11487
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
   at cz.esol.xxxxxxx.main._geocoder1_geocodedone(main.java:973)
 
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
checked API key in manifest seems fine

B4X:
'************ Google API KEY ************
AddApplicationText(
<meta-data
  android:name="com.google.android.geo.API_KEY"
  android:value="AIza...."/>
)
 
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
geocoding is called like this

B4X:
If Starter.LastLocation.IsInitialized = True Then
        Geocoder1.GetFromLocation(Starter.LastLocation.Latitude, Starter.LastLocation.Longitude, 1, Null)
End If
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
could it be that I used some old geocode ?
Hard to say as you are not given enough informations....

Post a small project which shoes the issue.
 
Upvote 0

Tomas Petrus

Active Member
Licensed User
Longtime User
changed it to:
B4X:
If Starter.LastLocation.IsInitialized = True Then
       Dim GetAddressJob As HttpJob
       GetAddressJob.Initialize("GeoCoding", Me)
       GetAddressJob.Download2("https://maps.googleapis.com/maps/api/geocode/json", Array As String("latlng", Starter.LastLocation.Latitude & "," & Starter.LastLocation.Longitude, "key", Config.API_Key) )
   End If

and seems it helped
 
Upvote 0
Top