Android Question AppCompat

RUNO

Active Member
Licensed User
Longtime User
Why this error ?

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 355)
java.lang.ClassCastException: b4a.example.main cannot be cast to androidx.appcompat.app.AppCompatActivity
at de.amberhome.objects.appcompat.ACActionBar.Initialize(ACActionBar.java:29)
at b4a.example.main._activity_create(main.java:355)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at b4a.example.main.afterFirstLayout(main.java:104)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

code
B4X:
Sub Process_Globals
    Private cartBitmap As Bitmap
End Sub

Sub Globals
    Private ToolbarHelper As ACActionBar
    Private ACToolBL1 As ACToolBarLight
    Private CLV1 As CustomListView
End Sub

Sub Activity_Create(FirstTime As Boolean)

    Activity.LoadLayout("1")
    If FirstTime Then
        cartBitmap = LoadBitmap(File.DirAssets, "menu.png")
    End If

    ToolbarHelper.Initialize
    ToolbarHelper.ShowUpIndicator = True 'set to true to show the up arrow
    ToolbarHelper.UpIndicatorDrawable = BitmapToBitmapDrawable(LoadBitmap(File.DirAssets, "cart.png"))
    ACToolBL1.InitMenuListener
'.........'
 

DonManfred

Expert
Licensed User
Longtime User
Follow the AppCompat tutorial on how to setup AppCompat in your App

You are missing something in your code. Compare it with the tutorial

To use the AppCompat library your activities MUST extend android.support.v7.app.AppCompatActivity (extending the old android.support.v7.app.ActionBarActivity still works.)

B4X:
 #Extends: android.support.v7.app.AppCompatActivity
 
Last edited:
Upvote 0

RUNO

Active Member
Licensed User
Longtime User
Follow the AppCompat tutorial on how to setup AppCompat in your App

You are missing something in your code. Compare it with the tutorial

What about this error ?

java.lang.RuntimeException: Unable to start activity ComponentInfo{b4a.example/b4a.example.main}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:659)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:543)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:166)
at b4a.example.main.onCreate(main.java:61)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
... 11 more
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
What about this error ?
You are NOT reading the AppCompat Tutorial at all it seems.

Go over the Tutorial AGAIN. As often until you understand how to configure your app. Everything needed is described clearly in the tutorial!
 
Last edited:
Upvote 0

RUNO

Active Member
Licensed User
Longtime User
What now ?
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 348)
java.lang.RuntimeException: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
at b4a.example.main._activity_create(main.java:348)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at b4a.example.main.afterFirstLayout(main.java:104)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at androidx.appcompat.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:421)
at androidx.appcompat.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:150)
at de.amberhome.objects.appcompat.ACToolBarWrapper.DesignerCreateView(ACToolBarWrapper.java:119)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:70)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
... 14 more
 
Upvote 0

Mehrzad238

Member
You need to add A theme in your manifest, like this:
B4X:
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>
)

As @DonManfred said You are NOT reading the AppCompat Tutorial at all

open this Link:
 
Upvote 0

RUNO

Active Member
Licensed User
Longtime User
what about this ?

** Activity (list_all) Create, isFirst = true **
list_all_activity_create (java line: 392)
java.lang.ClassCastException: b4a.example.list_all cannot be cast to androidx.appcompat.app.AppCompatActivity
at de.amberhome.objects.appcompat.ACActionBar.Initialize(ACActionBar.java:29)
at b4a.example.list_all._activity_create(list_all.java:392)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at b4a.example.list_all.afterFirstLayout(list_all.java:104)
at b4a.example.list_all.access$000(list_all.java:17)
at b4a.example.list_all$WaitForLayout.run(list_all.java:82)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
 
Upvote 0

RUNO

Active Member
Licensed User
Longtime User
In Main activity it work but another I got this error

** Activity (list_all) Create, isFirst = true **
list_all_activity_create (java line: 385)
java.lang.RuntimeException: java.lang.ClassCastException: b4a.example.list_all cannot be cast to androidx.appcompat.app.AppCompatActivity
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
at b4a.example.list_all._activity_create(list_all.java:385)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at b4a.example.list_all.afterFirstLayout(list_all.java:104)
at b4a.example.list_all.access$000(list_all.java:17)
at b4a.example.list_all$WaitForLayout.run(list_all.java:82)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
java.lang.RuntimeException: java.lang.ClassCastException: b4a.example.list_all cannot be cast to androidx.appcompat.app.AppCompatActivity
Again i suggest to read AND UNDERSTAND the AppCompat Tutorial.

As a help

Add this to your Activity list_all
B4X:
#Extends: android.support.v7.app.AppCompatActivity

Note that you need it to add in ALL activities where you are using AppCompat
 
Upvote 0

RUNO

Active Member
Licensed User
Longtime User
Again i suggest to read AND UNDERSTAND the AppCompat Tutorial.

As a help

Add this to your Activity list_all
B4X:
#Extends: android.support.v7.app.AppCompatActivity

Note that you need it to add in ALL activities where you are using AppCompat

Thanks @DonManfred
You always give me the solution .
 
Upvote 0
Top