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

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.SearchView.setQuery(java.lang.CharSequence, boolean)' on a null object reference #742

Closed
5 tasks done
demchiva opened this issue Mar 23, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@demchiva
Copy link

Environment

Technology Version
Flutter version 2.0.1
Plugin version 5.2.0
Android version 9.0 (API 28)
iOS version
Xcode version

Device information:

Description

My asset is a game written in JS. Error does not appear on Android 11 (API 30). Version 4.0.0+4 works fine on both Android versions.

When i run this code:

import 'package:flutter_inappwebview/flutter_inappwebview.dart';

class MyInAppBrowser extends InAppBrowser {
  MyInAppBrowser();

  @override
  Future onLoadStop(Uri url) async {
    print('\n\nStopped $url\n\n');
  }

  @override
  Future<NavigationActionPolicy> shouldOverrideUrlLoading(
      NavigationAction navigationAction) async {
    print('\n\n override ${navigationAction.request.url}\n\n');
    this.webViewController.loadUrl(urlRequest: navigationAction.request);
    return NavigationActionPolicy.ALLOW;
  }

  @override
  void onLoadResource(final LoadedResource resource) {
    print('Started at: ' +
        resource.startTime.toString() +
        'ms ---> duration: ' +
        resource.duration.toString() +
        'ms ' +
        resource.url.toString());
  }

  @override
  void onExit() {
    print('Exit was called in inappbrowser!');
    super.onExit();
  }

  @override
  void onConsoleMessage(final ConsoleMessage consoleMessage) {
    print('''
    console output:
      message: ${consoleMessage.message}
      messageLevel: ${consoleMessage.messageLevel}
    ''');
  }
}
import 'package:employee_app/webview/MyInappBrowser.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

class GameScreen extends StatefulWidget {
  static const String ROUTE_NAME = '/game';

  @override
  State<StatefulWidget> createState() => GameScreenState();
}

class GameScreenState extends State<GameScreen> {
  final MyInAppBrowser inAppBrowser = MyInAppBrowser();

  @override
  void initState() {
    super.initState();
    inAppBrowser.webViewController.addJavaScriptHandler(
      handlerName: 'gameQuit',
      callback: (arguments) => _gameQuit(arguments.first),
    );
  }

  @override
  Widget build(BuildContext context) {
    inAppBrowser.openFile(
      assetFilePath: 'assets/games-content/jetpack-blast/index.html',
      options: InAppBrowserClassOptions(
        android: AndroidInAppBrowserOptions(hideTitleBar: true),
        crossPlatform: InAppBrowserOptions(
          hideToolbarTop: true,
          hideUrlBar: true,
        ),
        inAppWebViewGroupOptions: InAppWebViewGroupOptions(
          crossPlatform: InAppWebViewOptions(
            useOnLoadResource: true,
            mediaPlaybackRequiresUserGesture: false,
          ),
          android: AndroidInAppWebViewOptions(
            databaseEnabled: true,
            domStorageEnabled: true,
          ),
        ),
      ),
    );

    return WillPopScope(
      child: Scaffold(
        body: Center(
          child: CircularProgressIndicator(),
        ),
      ),
      onWillPop: () async {
        if (inAppBrowser.isOpened()) {
          await inAppBrowser.close();
        }
        return;
      },
    );
  }
  
  _gameQuit(final int score) {}
}

I am getting this error message:

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.SearchView.setQuery(java.lang.CharSequence, boolean)' on a null object reference
	at com.pichillilorenzo.flutter_inappwebview.in_app_browser.InAppBrowserActivity.didStartNavigation(InAppBrowserActivity.java:412)
 	at com.pichillilorenzo.flutter_inappwebview.in_app_webview.InAppWebViewClient.onPageStarted(InAppWebViewClient.java:200)
 	at xl.b(PG:219)
	at afG.handleMessage(PG:20)
	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)
@demchiva demchiva added the bug Something isn't working label Mar 23, 2021
@pichillilorenzo
Copy link
Owner

It will be fixed with next release! Thanks for reporting this issue!

@pichillilorenzo
Copy link
Owner

The fix is available in the master branch now.
However, today I think I can publish the new version 5.2.1.

Copy link

github-actions bot commented Nov 6, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants