I'm creating a series of buttons in run time. The code is below:
I inserted a lot of "logs" because I wanted to know the exact location of the problem. The error seems to be in the line b.left = 5dip. The log is the follow:
B4X:
Sub HTTP_ResponseSuccess (Response As HttpResponse, TaskId As Int)
Dim esq As Boolean
Dim w, h As Int
Dim sep As Int
Log("ResponseSuccess")
ProgressDialogHide()
Log("1")
If (Funcoes.PreparaResposta(Response.GetString("UTF8")) = "OK") Then
Log("2")
esq = True
sep = 10dip
w = (90%x / 2)
h = 10%y
For i = 0 To Funcoes.g_resposta.Size - 1
Log("3")
Dim b As Button
b.Initialize("btnAgrupamento")
Log("4")
If (esq = True) Then
b.Left = 5dip
Else
b.Left = w + sep + sep
End If
Log("6")
b.Height = h
b.Width = w
Log("7")
b.Text = Funcoes.g_resposta.Get(i)
Log("8")
If (esq) Then
esq = False
Else
esq = True
End If
Log("9")
Next
Else
Funcoes.Erro(Funcoes.g_ultimo_erro)
Activity.Finish()
End If
End Sub
Sub btnAgrupamento_Click
End Sub
Please, I cannot figure out why this error is happening. Any help?** Activity (main) Pause, UserClosed = false **
** Activity (selecionagarcon) Create, isFirst = true **
** Activity (selecionagarcon) Resume **
ResponseSuccess
** Activity (selecionagarcon) Pause, UserClosed = false **
** Activity (selecionacomanda) Create, isFirst = true **
** Activity (selecionacomanda) Resume **
** Activity (selecionacomanda) Pause, UserClosed = false **
** Activity (selecionaagrupamento) Create, isFirst = true **
** Activity (selecionaagrupamento) Resume **
ResponseSuccess
1
2
3
4
selecionaagrupamento_http_responsesuccess (java line: 333)
java.lang.NullPointerException
at anywheresoftware.b4a.objects.ViewWrapper.setLeft(ViewWrapper.java:139)
at xcreator.com.selecionaagrupamento._http_responsesuccess(selecionaagrupamento.java:333)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
at anywheresoftware.b4a.BA$3.run(BA.java:301)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException