Android Question Load spinner data

Discussion in 'Android Questions' started by chevita87, Oct 9, 2018.

Tags:
  1. chevita87

    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
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    If the application crashes then you should see an error message in the logs.
     
  3. klaus

    klaus Expert Licensed 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:
    Code:
    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.
     
  4. chevita87

    chevita87 Member Licensed User

    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
     
  5. DonManfred

    DonManfred Expert Licensed User

    The spinner is not initialized
     
  6. klaus

    klaus Expert Licensed User

    As I wrote in post #3, you try to access the Spinner before having loaded the layout.
    Therefore it is not initialized!
    You must load the layout before using any view.
     
  7. chevita87

    chevita87 Member Licensed User

    thanks to all, can already solve the problem, I do not know how to get it resolved
     
  8. klaus

    klaus Expert Licensed User

    Attached a modified project.
    I did what I suggested you in post #3!
     

    Attached Files:

    Erel, Johan Hormaza and chevita87 like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice