Android Question StdActionBar Crashing

EduardoElias

Well-Known Member
Licensed User
Longtime User
Hi there!

I use StdActionBar successfully in one of my apps.

Now I am trying to use in another one and it causes an exception:

java.lang.NullPointerException
at anywheresoftware.b4a.objects.StdActionBar.setSubtitle(StdActionBar.java:218)
at yashar.yPainel.main._initappbar(main.java:1121)
at yashar.yPainel.main._doinicio(main.java:693)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
at anywheresoftware.b4a.keywords.Common$5.run(Common.java:996)
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:4446)
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)

it happens shen using subtitle in this line:

B4X:
    appbar.Initialize("appbar")
    If AppManager.IsInitialized Then
        Dim subtitle As String = s & "Versão " &AppManager.GetVersionCode
        appbar.Subtitle = subtitle
    End If

This is the same code from my other working app. This is part of a initialization sub that I call using CallSubDelayed to be executed AFTER the Activity_Create is executed. Basically I just set the title and the background color of the bar.

I removed everything possible and the problem continues

thanks
 

EduardoElias

Well-Known Member
Licensed User
Longtime User
I found out that this code also does not work causing an exception:

B4X:
Sub SetActionBarColor(Color As Int)
    Dim jo As JavaObject
    jo.InitializeContext
    Dim cd As ColorDrawable
    cd.Initialize(Color, 0)
    jo.RunMethodJO("getActionBar", Null).RunMethod("setBackgroundDrawable", Array(cd))
End Sub

It stop on the getActionBar

B4X:
main_setactionbarcolor (B4A line: 383)
jo.RunMethodJO("getActionBar", Null).RunMethod("s
java.lang.RuntimeException: Object should first be initialized (JavaObject).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4j.object.JavaObject.getCurrentClass(JavaObject.java:258)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:118)
    at yashar.yPainel.main._setactionbarcolor(main.java:1402)
    at yashar.yPainel.main._initappbar(main.java:1112)
    at yashar.yPainel.main._doinicio(main.java:690)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
    at anywheresoftware.b4a.keywords.Common$5.run(Common.java:996)
    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:4446)
    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)

So I am certanly missing something

Android 4.0.4 tablet
B4A 6.80
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
I dont understand this code ( AppManager ) :
B4X:
[CODE]    appbar.Initialize("appbar")
    If AppManager.IsInitialized Then '<--- Whats AppManager ?? 
        Dim subtitle As String = s & "Versão " &AppManager.GetVersionCode
        appbar.Subtitle = subtitle
    End If

For read VersionCode is:
B4X:
    'Get Version
    Dim pm As PackageManager
    Dim vedipackage As String
    vedipackage = "com.xxxxx"

    Dim valore as int = "XXXXXXX Rel." & pm.GetVersionCode(vedipackage)
.....

What's this AppManager ?
 
Upvote 0

EduardoElias

Well-Known Member
Licensed User
Longtime User
Can you upload the project?

Make sure that #IncludeTitle is set to True.

#IncludeTitle is set to true

I cant upload the project here, and it is big with many libraries.

Strange is that I have another project with the same libraries, just the Main.bas is written different due the user interface. It should work.

Both projects are sharing the same folder and both are working perfectly for more than a year.

Then I have added the StdActionBar to project "A" and it is working and already in production in many tablets and smartphones.

After that I tried the same thing on project "B" and it is not working as I described above. It fails (runtimeException) everytime I try to access the ActionBar.

Detail: Project A is using many layouts that are loaded while Project B is not using layouts at all.

Thanks
Eduardo
 
Upvote 0

EduardoElias

Well-Known Member
Licensed User
Longtime User
Are you using AppCompat? Or a custom theme (set in the manifest editor)?

I found the problem, for a mistake minSdkVersion was set 4, instead 14 from the other application. Once I changed it worked.

Thank you for the help, lesson learned.
 
Upvote 0
Top