Android Question Get NullPointerException with label tag

Discussion in 'Android Questions' started by imgsimonebiliato, Apr 2, 2015.

  1. imgsimonebiliato

    imgsimonebiliato Well-Known Member Licensed User

    Hello,
    I want to check the value of the tag property of a label, but I get this error message:


    Code:
    If lb.Tag = bt.Text Then
    java.lang.NullPointerException

        at it.android.imgspa.and_Cons.main._btmac_click(main.java:
    427)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    511)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    175)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    163)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    159)
        at anywheresoftware.b4a.objects.ViewWrapper$
    1.onClick(ViewWrapper.java:66)
        at android.view.View.performClick(
    View.java:4209)
        at android.view.View$PerformClick.run(
    View.java:17431)
        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 dalvik.system.NativeStart.main(Native Method)
    java.lang.NullPointerException
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Change your code to:
    Code:
    If lb.Tag <> Null AND lb.Tag = bt.Text Then
     
    imgsimonebiliato likes this.
  3. imgsimonebiliato

    imgsimonebiliato Well-Known Member Licensed User

    Same problem
     
  4. NJDude

    NJDude Expert Licensed User

    Try assigning the value of the tag to a string variable and then query the variable instead of the tag directly. like:
    Code:
    Private myVar As String

    myVar = lb.Tag

    If myVar = bt.Text Then ...
     
    thedesolatesoul likes this.
  5. imgsimonebiliato

    imgsimonebiliato Well-Known Member Licensed User

    Yes, perfect!
     
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