Android Question Java Null Pointer Exception

PFlores81

Active Member
Licensed User
Longtime User
This is just a snippet, this is the code that worked perfectly fine in my last build 3 weeks ago, however upon running it now, it does not work at all. nothing has changed with the exception of some images within the app. I had fixed my layout issues and now I have an issue with this. Any input is appreciated

B4X:
Sub Timer1_tick

Container.initialize
               
     
               
                Pan(0).LoadLayout("main1")
 

PFlores81

Active Member
Licensed User
Longtime User
nothing has changed as far as layout names. Erel i will try to get a log to you asap. Been really busy with things lately.
 
Upvote 0

PFlores81

Active Member
Licensed User
Longtime User
I know it took some time, work has been killing me lately, but here is the log file. What is funny about this log as nothing has been changed besides some button code. the only button code added was Longhold actions. and I added a new image but not to the main activity. It could also be that I am running 4.4.2. Any input helps greatly

B4X:
LogCat connected to: c2178c2e--------- beginning of /dev/log/system


--------- beginning of /dev/log/main


Fatal signal 13 (SIGPIPE) at 0x00007356 (code=0), thread 29526 (sh)


** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
AppKey:Not installed
AppKey:Not installed
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
AppKey:Not installed
(Main, 161) Panel.LoadLayout should only be called after the panel was added to its parent. (warning #1001)
Error occurred on line: 161 (main)


java.lang.RuntimeException: java.lang.NullPointerException


    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:161)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:112)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:485)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:232)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:174)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
    at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5050)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:395)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:141)
    ... 20 more
** Activity (main) Pause, UserClosed = true **
 
Upvote 0

PFlores81

Active Member
Licensed User
Longtime User
the exact code has remained unchanged in the last 3 updates to the app. after the splash fades it loads the panels. Below is the code.

B4X:
Sub Activity_Create(FirstTime As Boolean)
  Activity.AddView(MyPan, 0, 0, Activity.Width, Activity.Height) : MyPan.Color = Colors.Black 


  If FirstTime Then
      MyFade.Initialize(Activity, Me, "SplashScreen.png", Gravity.FILL,  10000,  70, "")
  End If
  MP.Initialize2("MP")
MP.Load(File.DirAssets, "splashscreen.mp3")
MP.Play
     
Timer1.Initialize("Timer1", 6000)
Timer1.Enabled=True


                Pan(0).initialize("")
                Pan(1).initialize("")
                Pan(2).initialize("")
                Pan(3).initialize("")
             

             
AdBox.Initialize("Ad", "a15262e11b9a158")

         
    ak.Initialize("ak","83")
         
    ak.Check4AppKey
    Activity.AddMenuItem("Unlock Premium Features", "Unlock")
 
End Sub

Sub Activity_Resume
ak.Check4AppKey
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub Ad_FailedToReceiveAd (ErrorCode As String)
    Log("failed: " & ErrorCode)
End Sub
Sub Ad_ReceiveAd
    Log("received")
End Sub
Sub Ad_AdScreenDismissed
  Log("screen dismissed")
End Sub
Sub Timer1_tick
Timer1.Enabled=False
Container.initialize
             
   
             
            Pan(0).LoadLayout("main1")
                Container.AddPageAt(Pan(0), "Zombies", 0)
                Pan(1).LoadLayout("zombies1")
                Container.AddPageAt(Pan(1), "Black Ops", 1)
                Pan(2).LoadLayout("zombies2")
                Container.AddPageAt(Pan(2), "Black Ops2", 2)
                Pan(3).LoadLayout("origins")
                Container.AddPageAt(Pan(3), "Origins", 3)

        Pager.Initialize(Container, "Pager")

      Pager.Enabled=True
     
      Tabs.Initialize(Pager)
      Tabs.LineHeight = 3dip
                Tabs.LineColorCenter = Colors.Gray 
                Tabs.TextColor = Colors.Gray
                Tabs.TextColorCenter = Colors.Red
Tabs.Visible=True
                Activity.AddView(Tabs, 0dip, 0dip, 100%x, 100%y)
             
     
Dim Col As ColorDrawable
 
      Col.Initialize(Colors.Black, 0)
 
      Line.Initialize("")
      Line.Background = Col
 
      Activity.AddView(Line, 0dip, 35dip, Activity.Width, 2dip)             
 
     
      Activity.AddView(Pager, 0dip, 35dip + 2dip, Activity.Width, Activity.height - 35dip - 2dip)

         


    Activity.AddView(AdBox, 0dip, 100%y - 50dip, 320dip, 50dip)

    AdBox.LoadAd
    AdBox.Visible=True


End Sub
 
Last edited:
Upvote 0

PFlores81

Active Member
Licensed User
Longtime User
Yes I am using 3.2... like I said, it is possible that it is because I am running 4.4.2

Ok so changing a few things around got rid of the error, but now this app is loading in a tablet gui instead of the variation that was made for its display. not sure why but i still say its 442 that is causing the issue.
 
Last edited:
Upvote 0

PFlores81

Active Member
Licensed User
Longtime User
I'm stumped then, I even went as far as using per app specifications to make it run properly. Oh well, as long as it displays properly on all other devices.

It could also be the build I am running. I'll flash a different build later on today and go from there. As far as the java issue, I just used the google play services tut to fix that. It was very informative and I thank you for taking the time to help out Erel. much appreciated.

After flashing 2 other 442 builds, they all displayed the same way. Not sure how I feel about this.
 
Last edited:
Upvote 0