Android Question Problem with panels

Reinierus

Member
Licensed User
Longtime User
Hello.
I have a problem like this: http://www.b4x.com/android/forum/threads/panel-width-nullpointerexception.19942/

My code is:
B4X:
Sub Globals
    'Another lines
    Dim Pan1 As Panel
    'More lines
End Sub


Sub Activity_Create(FirstTime As Boolean)
   'Lots of lines...
    Pan1.Initialize("")
    Pan1.Height =100%y
    Pan1.Width =100%x
    Pan1.LoadLayout("principal")
    Pan1.Color=Colors.ARGB(100,100,0,100)
    container.AddPage(Pan1,"Kilómetros")
   'More and more lines...

But I get this error:

LogCat connected to: 47900503891b10d0
--------- beginning of /dev/log/main


--------- beginning of /dev/log/system


** Activity (main) Create, isFirst = true **



java.lang.NullPointerException
at anywheresoftware.b4a.objects.ViewWrapper.setHeight(ViewWrapper.java:153)
at Kilometreador.reinier.main._activity_create(main.java:420)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
at Kilometreador.reinier.main.afterFirstLayout(main.java:98)
at Kilometreador.reinier.main.access$100(main.java:16)
at Kilometreador.reinier.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)


at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException


Someone can help me?

Thanks a lot
 

Reinierus

Member
Licensed User
Longtime User
So, this is the way:

B4X:
        Pan1.Initialize("")
    Pan1.LoadLayout("principal")
    Pan1.Color=Colors.ARGB(100,100,0,100)
    container.AddPage(Pan1,"Kilómetros")
    Pan1.Height =100%y
    Pan1.Width =100%x

But get the same error.

Please help.

Thanks
 
Upvote 0

Reinierus

Member
Licensed User
Longtime User
Ok. This is:

B4X:
Dim container As AHPageContainer
Dim pager As AHViewPager
'Optionally you can use an AHViewPagerTabs object as a page indicator
Dim fixedTabs As AHViewPagerFixedTabs

Thanks
 
Upvote 0

Reinierus

Member
Licensed User
Longtime User
No, if I don't set the height and width, the panel is smaller than the activity and cuts some others views like buttons. If I set the width and the height, even the error, sets the panel dimensions.
 
Upvote 0

Reinierus

Member
Licensed User
Longtime User
Thanks Klaus, I will make a project to you see the problem.

Maybe someone else can help me.

Best regards
 
Upvote 0

Reinierus

Member
Licensed User
Longtime User
Hello Klaus.
Here is the program.
I used the AHViewPagerFixed example with the line error.
Tell me if you need some else.

Thanks
 

Attachments

  • AHViewPager_Panel_Error.zip
    4.8 KB · Views: 200
Upvote 0

klaus

Expert
Licensed User
Longtime User
In the library Pan1 width and height fit the container.
It seems that you cannot access Pan1.Width and Pan1.Height in Activity_Create.
But in Activity_Resume you can get the values of Pan1.Width and Pan1.Height and the position the views inside of Pan1 according to it's dimensions.
Attached a modified version of your test program.

EDIT:
You can also add a DoEvents at the end of Activity_Create to make sure that the viewer is initialized and add the code to reposition the other views.
Attached a second version.
 

Attachments

  • AHViewPager_Panel_Error_1.zip
    9.8 KB · Views: 207
  • AHViewPager_Panel_Error_2.zip
    9.9 KB · Views: 209
Last edited:
Upvote 0

Reinierus

Member
Licensed User
Longtime User
Thanks Klaus.
I don't know why, but in my program doesn't works any of two solutions. I am testing my code and also I don't know why the panel don´t fit the container. I will try a while and then I will ask for help if I need it.

Best regards
 
Upvote 0
Top