Android Question Load spinner data

chevita87

Member
Licensed User
Hello everyone, I am quite new in all this programming, I have very basic knowledge. I am trying to make an application that has 3 layout in a main, everything works perfect, except when I want to fill the spinner with data, if I fill the spinner with data the application stops working, if I leave them empty, the application works perfectly. I upload my application so you can see what I mean
 

Attachments

  • Con Datos.zip
    19.2 KB · Views: 253
  • Sin Datos.zip
    19 KB · Views: 259

klaus

Expert
Licensed User
Longtime User
That's normal!
You try to access the Spinner before having loaded the layout!

For your different layouts you should put them onto Panels and use the Panels.Visible property to show and hide them.
Instead of removing all views and reload the layouts.

For these codes:
B4X:
    If nLeyendaD.Text="1" Then txtLeyendaD.Text="1 AMERICAN GAS"
    If nLeyendaD.Text="2" Then txtLeyendaD.Text="2 ARGON S.A."
    If nLeyendaD.Text="3" Then txtLeyendaD.Text="3 CENTRAL GAS"
    If nLeyendaD.Text="4" Then txtLeyendaD.Text="4 ENERGAS"
    If nLeyendaD.Text="5" Then txtLeyendaD.Text="5 ESSO GAS"
You might consider using Lists, Maps or Arrays, this would make your code much easier.
 
Upvote 0

chevita87

Member
Licensed User
If the application crashes then you should see an error message in the logs.

Registo conectado a: motorola XT1058
--------- beginning of crash
--------- beginning of main
Copying updated assets files (5)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 137 (Main)
java.lang.RuntimeException: Object should first be initialized (Spinner).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.SpinnerWrapper.Add(SpinnerWrapper.java:100)
at b4a.totalgaz.main._activity_create(main.java:499)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:733)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:355)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.totalgaz.main.afterFirstLayout(main.java:104)
at b4a.totalgaz.main.access$000(main.java:17)
at b4a.totalgaz.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
** Activity (main) Resume **

This is what i get in the logs
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top