Android Question NullPointerException while adding canvas to panel or changing panel's width or height

mevial

Member
Licensed User
Longtime User
I have tabhost in program with few panels in tabs. Some of panels has a canvas. But while I added new tab and new canvas to new tab, I received NullPointerException.

B4X:
Sub Globals
...
	Private DashBoardPanel As Panel
	Private BTMPanel As Panel
	Private BMSSPanel As Panel
	Private MnuPanel,MnSPanel As Panel
	Private ScanBtn As Button 
	Private SaveLogBtn As Button
	Private BtnResetRange As Button
	Private DBCanv,Canv1,BTMCanv As Canvas 
	Private Tabs As TabHost 
...
End Sub

Sub Activity_Create(FirstTime As Boolean)
...
	If DashBoardEnabled Then DashBoardPanelCreate	
...
	If BMSType=1 Then BTMPanelCreate
...
End Sub

Sub DashBoardPanelCreate
	DashBoardPanel.Initialize("DashBoard")
	DashBoardPanel.Color=Colors.ARGB(255,64,64,64)
	Tabs.AddTab2("  Dash" & Chr(10) & " Board",DashBoardPanel)

	DashBoardPanel.Width=PanelsWidth
	DashBoardPanel.Height=PanelsHeight
	DBCanv.Initialize(DashBoardPanel)
...
End Sub
...

Sub BTMPanelCreate
	BTMPanel.Initialize("BTMPanel")
	Tabs.AddTab2("T",BTMPanel)
'	BTMPanel.Width=PanelsWidth
'	BTMPanel.Height=PanelsHeight
	BTMCanv.Initialize(BTMPanel)
...
End Sub

First canvas works fine, but last canvas hangs on BTMCanv.Initialize(BTMPanel)
 

mevial

Member
Licensed User
Longtime User
Panel adds succesfully. I added label to panel instead canvas, and see the tab and label on tab at my phone.
 
Upvote 0

mevial

Member
Licensed User
Longtime User
I have workaround:
B4X:
Sub BTMPanelCreate
   Dim tmppanel As Panel

   tmppanel.Initialize("")
   Tabs.AddTab2("T",tmppanel)
   BTMPanel.Initialize("BTMPanel")
   tmppanel.AddView(BTMPanel,0,0,PanelsWidth,PanelsHeight)
   BTMCanv.Initialize(BTMPanel)
...
End Sub
This works fine, but why I need panel within panel?
 
Upvote 0

mevial

Member
Licensed User
Longtime User
Can you post the full error message from the logs?

Can you upload the project (File - Export as zip)?
B4X:
Installing file.
PackageAdded: package:ru.mevial.ozwizard
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_btmpanelcreate (B4A line: 987)
BTMCanv.Initialize(BTMPanel)
java.lang.NullPointerException
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper.Initialize(CanvasWrapper.java:76)
    at ru.mevial.ozwizard.main._btmpanelcreate(main.java:2171)
    at ru.mevial.ozwizard.main._activity_create(main.java:860)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
    at ru.mevial.ozwizard.main.afterFirstLayout(main.java:102)
    at ru.mevial.ozwizard.main.access$000(main.java:17)
    at ru.mevial.ozwizard.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:153)
    at android.app.ActivityThread.main(ActivityThread.java:5297)
    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:833)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
    at dalvik.system.NativeStart.main(Native Method)
Source too big and closed, I can't post it to public forum.
 
Upvote 0
Top