Android Question Appcompact with toolbar- error

StarinschiAndrei

Active Member
Licensed User
Longtime User
Hi everyone,
Based on Erel -AppCompat with ToolBar - minimal example, I'm trying to implement in my app, but i receive the following error.
B4X:
Error occurred on line: 27 (ChatActivity)
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 anywheresoftware.b4a.samples.bluetooth.chatactivity._activity_create(chatactivity.java:371)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
   at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
   at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
   at anywheresoftware.b4a.samples.bluetooth.chatactivity.afterFirstLayout(chatactivity.java:104)
   at anywheresoftware.b4a.samples.bluetooth.chatactivity.access$000(chatactivity.java:17)
   at anywheresoftware.b4a.samples.bluetooth.chatactivity$WaitForLayout.run(chatactivity.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:158)
   at android.app.ActivityThread.main(ActivityThread.java:7225)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
** Activity (chatactivity) Resume **

Manifest :

B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="21"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.
SetApplicationAttribute(android:theme, "@style/MyAppTheme")
CreateResource(values, theme.xml,
<resources>
    <style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">#0098FF</item>
        <item name="colorPrimaryDark">#007CF5</item>
        <item name="colorAccent">#AAAA00</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
    </style>
</resources>
)
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("2")
   ToolbarHelper.Initialize
   ToolbarHelper.ShowUpIndicator = False 'set to true to show the up arrow
   Dim bd As BitmapDrawable
   bd.Initialize(LoadBitmap(File.DirAssets, "hamburger.png"))
   ToolbarHelper.UpIndicatorDrawable =  bd
   ACToolBarLight1.InitMenuListener
   sm.Initialize("sm")
   Dim offset As Int = 100dip
   sm.BehindOffset = offset
   sm.Mode = sm.LEFT
   Dim lftMenu As Panel
   lftMenu.Initialize("")
   sm.Menu.AddView(lftMenu, 0, 0, 100%x - offset, 100%y)
   lftMenu.LoadLayout("Left")
   For i = 1 To 30
       ListView1.AddSingleLine("Item " & i)
   Next
End Sub
 

Attachments

  • Libraries.png
    Libraries.png
    4.7 KB · Views: 121
  • Untitled.png
    Untitled.png
    4 KB · Views: 114

StarinschiAndrei

Active Member
Licensed User
Longtime User
1. You should remove this line:
B4X:
CreateResourceFromFile(Macro, Themes.LightTheme)

2. Does the example work for you?
3. Have you added the #Extends line?

Hi Erel , Your exemple work fine.
I removed you mentioned line from manifest, and the error is the same.
Yes i added Extends line (#1 attachement):
B4X:
#Extends:android.support.v7.app.AppCompatActivity
 
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
1. Compare your project to the example project.
2. If you don't find the cause of this error then please upload the project.
Hi Erel, i attached the test project. The idea is that i would like to have a sliding menu in 2-nd screen if the BT connection is established.
 

Attachments

  • SlidingMenu-BTapp-Test.zip
    14.9 KB · Views: 119
Upvote 0

StarinschiAndrei

Active Member
Licensed User
Longtime User
THANK YOU
Hi Erel, i found the missing line from manifest but i receviced below error. I attached the corected test project.
B4X:
** Activity (chatactivity) Create, isFirst = true **
Error occurred on line: 23 (ChatActivity)
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 java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
   at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
   at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
   at anywheresoftware.b4a.samples.bluetooth.chatactivity.afterFirstLayout(chatactivity.java:104)
   at anywheresoftware.b4a.samples.bluetooth.chatactivity.access$000(chatactivity.java:17)
   at anywheresoftware.b4a.samples.bluetooth.chatactivity$WaitForLayout.run(chatactivity.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:158)
   at android.app.ActivityThread.main(ActivityThread.java:7225)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Error occurred on line: 23 (ChatActivity)
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 java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
   at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
   at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
   at anywheresoftware.b4a.samples.bluetooth.chatactivity.afterFirstLayout(chatactivity.java:104)
   at anywheresoftware.b4a.samples.bluetooth.chatactivity.access$000(chatactivity.java:17)
   at anywheresoftware.b4a.samples.bluetooth.chatactivity$WaitForLayout.run(chatactivity.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:158)
   at android.app.ActivityThread.main(ActivityThread.java:7225)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
** Activity (chatactivity) Resume **
 

Attachments

  • SlidingMenu-BTapp-Test.zip
    14.9 KB · Views: 105
Upvote 0
Top