Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] ClassCastException running Android example #92

Open
1 of 4 tasks
mauriziopinotti opened this issue Aug 30, 2024 · 0 comments
Open
1 of 4 tasks

[Bug] ClassCastException running Android example #92

mauriziopinotti opened this issue Aug 30, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@mauriziopinotti
Copy link

Describe the bug
Running the Android example causes a ClassCastException.

To Reproduce
Steps to reproduce the behavior:

  1. Clone the project
  2. Run flutter run on an Android device
  3. See error

Expected behavior
Android app should start.

Screenshots
N/A.

Logs

E/AndroidRuntime(28799): FATAL EXCEPTION: main
E/AndroidRuntime(28799): Process: de.mintware.example, PID: 28799
E/AndroidRuntime(28799): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{de.mintware.example/android.app.Application}: java.lang.ClassCastException: android.app.Application cannot be cast to android.app.Activity
E/AndroidRuntime(28799):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4047)
E/AndroidRuntime(28799):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4322)
E/AndroidRuntime(28799):        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
E/AndroidRuntime(28799):        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
E/AndroidRuntime(28799):        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
E/AndroidRuntime(28799):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2685)
E/AndroidRuntime(28799):        at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(28799):        at android.os.Looper.loopOnce(Looper.java:230)
E/AndroidRuntime(28799):        at android.os.Looper.loop(Looper.java:319)
E/AndroidRuntime(28799):        at android.app.ActivityThread.main(ActivityThread.java:8919)
E/AndroidRuntime(28799):        at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(28799):        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
E/AndroidRuntime(28799):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
E/AndroidRuntime(28799): Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to android.app.Activity
E/AndroidRuntime(28799):        at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
E/AndroidRuntime(28799):        at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:44)
E/AndroidRuntime(28799):        at android.app.Instrumentation.newActivity(Instrumentation.java:1378)
E/AndroidRuntime(28799):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4034)
E/AndroidRuntime(28799):        ... 12 more

Environment (please complete the following information):

  • iOS? Version: ...
  • Android? Version: any
  • Real Device? Which?: ...
  • Emulator/Simulator? Which?: ...
  • Version of barcode_scan
  • Output of flutter --version:
Flutter ...

Additional context
This commit broke it: c589b6f as android:name="${applicationName}" should be an attribute of <application>, not <activity>.

The correct syntax is:

diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml
index b14b12f..b320208 100644
--- a/example/android/app/src/main/AndroidManifest.xml
+++ b/example/android/app/src/main/AndroidManifest.xml
@@ -1,6 +1,6 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.mintware.example">
-  <application android:label="example" android:icon="@mipmap/ic_launcher">
-    <activity android:name="${applicationName}" android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
+  <application android:name="${applicationName}" android:label="example" android:icon="@mipmap/ic_launcher">
+    <activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
       <!-- Specifies an Android theme to apply to this Activity as soon as
                  the Android process has started. This theme is visible to the user
                  while the Flutter UI initializes. After that, this theme continues
@mauriziopinotti mauriziopinotti added the bug Something isn't working label Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant