Android Question AppCompat Bar won't work

Dianzoa

Active Member
Licensed User
Can't use it on my project. Got this.
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference

I copy the examples on the AppCompat project from Erel. The example works, but when added the reference and use it on my project, fails.
Any tips? I use b4a 8.50 This is my manifest.
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:networkSecurityConfig, @xml/network_security_config)
SetApplicationAttribute(android:theme, "@android:style/Theme.Material.Light")
SetApplicationAttribute(android:theme, "@style/MyAppTheme")
CreateResource(xml, network_security_config.xml,
<network-security-config>
<base-config cleartextTrafficPermitted="true">
    <trust-anchors>
        <certificates src="system" />
    </trust-anchors>
</base-config>
</network-security-config>

)

SetApplicationAttribute(android:theme, "@style/MyAppTheme")

CreateResource(values, theme.xml,
<resources>
    <style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">#ff039be5</item>
        <item name="colorPrimaryDark">#ff039be5</item>
        <item name="colorAccent">#AAAA00</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">true</item>
    </style>
</resources>
)


CreateResource(values, dimen.xml,
<resources>
<dimen name="action_button_padding">10dp</dimen>
</resources>
)
CreateResource(values, colors.xml,
<resources>
    <color name="actionbar">#ff039be5</color>
    <color name="statusbar">#ff006db3</color>
    <color name="textColorPrimary">#ffffffff</color>
    <color name="navigationBar">#ff006db3</color>
</resources>
)
 

Erel

Administrator
Staff member
Licensed User
Please post the full error message from the logs.

Compare your code to the "minimal example". Also make sure to add an ACToolBarLight with the designer.
 

Dianzoa

Active Member
Licensed User
Please post the full error message from the logs.

Compare your code to the "minimal example". Also make sure to add an ACToolBarLight with the designer.
I copy the same code from this example
upload_2019-6-2_5-38-17.png


The toolbarhelper added by code, I could not find it in the designer.
 

Dianzoa

Active Member
Licensed User
Please post the full error message from the logs.

Compare your code to the "minimal example". Also make sure to add an ACToolBarLight with the designer.
Here is the full log

Registo conectado a: HUAWEI DRA-LX3
--------- beginning of crash
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
25
%
A
Santa Clara Catholic College,asuncion
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (menu_principal) Create, isFirst = true **
Error occurred on line: 0 (menu_principal)
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
at de.amberhome.objects.appcompat.ACActionBar.setShowUpIndicator(ACActionBar.java:116)
at com.anzoategui.enviapycliente.menu_principal._activity_create(menu_principal.java:384)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:738)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at com.anzoategui.enviapycliente.menu_principal.afterFirstLayout(menu_principal.java:104)
at com.anzoategui.enviapycliente.menu_principal.access$000(menu_principal.java:17)
at com.anzoategui.enviapycliente.menu_principal$WaitForLayout.run(menu_principal.java:82)
at android.os.Handler.handleCallback(Handler.java:795)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:6861)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:450)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
** Activity (menu_principal) Resume **
 

Erel

Administrator
Staff member
Licensed User


You have a small working example. Compare it to your project.
 

Dianzoa

Active Member
Licensed User


You have a small working example. Compare it to your project.
Thanks, I think I compare it already, not seem to be any differences, for the time being I just will keep using the action bar, since so far I found that won't need features of the AC bar. I will come to it again if I need it.
 
Top