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

NoSuchMethodError: the method 'toRawHandle' was called on null. #81

Closed
JCKodel opened this issue Sep 28, 2019 · 3 comments
Closed

NoSuchMethodError: the method 'toRawHandle' was called on null. #81

JCKodel opened this issue Sep 28, 2019 · 3 comments
Labels
question Further information is requested

Comments

@JCKodel
Copy link

JCKodel commented Sep 28, 2019

image

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="br.art.code.xxx" 
    xmlns:tools="http://schemas.android.com/tools">
    <application tools:replace="android:label,android:icon,android:name" android:name=".App" android:label="xxx"
        android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/icon_round" android:fullBackupContent="@xml/backup_rules">
        <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"></action>
            </intent-filter>
        </receiver>

        <receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />

        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
        <meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-xxx~xxx"/>

        <activity android:name="com.yalantis.ucrop.UCropActivity" android:screenOrientation="portrait" 
            android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>

        <activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:label="@string/app_name" />

        <activity android:name="com.facebook.CustomTabActivity" android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="@string/fb_login_protocol_scheme" />
            </intent-filter>
        </activity>

        <activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" 
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
            <meta-data android:name="io.flutter.app.android.SplashScreenUntilFirstFrame" android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
</manifest>

App.kt as documentation suggests.

[√] Flutter (Channel master, v1.10.7-pre.37, on Microsoft Windows [Version 10.0.18362.356], locale en-GB)
    • Flutter version 1.10.7-pre.37 at C:\flutter
    • Framework revision 56d68a9071 (30 hours ago), 2019-09-26 14:01:57 -0700
    • Engine revision b126ba7585
    • Dart version 2.6.0 (build 2.6.0-dev.3.0 6ff8d2199d)

 
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at C:\Users\jckod\Android\SDK
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.2
    • ANDROID_HOME = C:\Users\jckod\Android\SDK
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 3.5)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 39.0.3
    • Dart plugin version 191.8423
    • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] VS Code (version 1.38.1)
    • VS Code at C:\Users\jckod\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.4.1

[√] Connected device (3 available)
    • Android SDK built for x86 • emulator-5554 • android-x86    • Android 7.0 (API 24) (emulator)
    • Chrome                    • chrome        • web-javascript • Google Chrome 77.0.3865.90
    • Server                    • web           • web-javascript • Flutter Tools

• No issues found!
@JCKodel
Copy link
Author

JCKodel commented Sep 28, 2019

Note: This happens only on VSCode.
Android Studio starts the app (but my task is never triggered).

Continuing after the first error:

Exception has occurred.
PlatformException (PlatformException(1, You have not properly initialized the Flutter WorkManager Package. You should ensure you have called the 'initialize' function first! Example: 

`Workmanager.initialize(
  callbackDispatcher,
 )`

The `callbackDispatcher` is a top level function. See example in repository., null))

BTW, I've inserted this on my App.kt file: Log.d("WorkmanagerPlugin", "WorkmanagerPlugin is initializing") and this log appears on catlog when the app is initialized (before Flutter first frame is rendered and the bug manifests itself).

After running a couple of times (and moving this initialization first thing in my flutter main), the first error doesn't occur anymore, but the second remains:

image

I also have to write this: WidgetsFlutterBinding.ensureInitialized();, otherwise, my app says:

Exception has occurred.
FlutterError (ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.
If you're running an application and need to access the binary messenger before `runApp()` has been called (for example, during plugin initialization), then you need to explicitly call the `WidgetsFlutterBinding.ensureInitialized()` first.
If you're running a test, you can call the `TestWidgetsFlutterBinding.ensureInitialized()` as the first line in your test's `main()` method to initialize the binding.)

@timrijckaert
Copy link
Contributor

timrijckaert commented Sep 28, 2019

Is your callbackDispatcher a top level function?
Can you provide me with a sample that demonstrates this behaviour?

@timrijckaert timrijckaert added answered Used to auto-close 'answered' issues after a certain time of inactivity question Further information is requested labels Sep 28, 2019
@JCKodel
Copy link
Author

JCKodel commented Sep 28, 2019

That was the problem. Moving the function to public and outside the class made it work.

@JCKodel JCKodel closed this as completed Sep 28, 2019
@no-response no-response bot removed the answered Used to auto-close 'answered' issues after a certain time of inactivity label Sep 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants