3

The intent of this is to have a webpage firing within the app itself. The app runs without glitches, but the webpage is never seen. The .xml contains the webpage and a list beneath it.

The .xml file reads as

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_centerVertical="true"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

     <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />

    <ListView
        android:layout_width="fill_parent"
        android:layout_height="500dp"
        android:id="@android:id/list"/>
</LinearLayout>

The activity in the .java reads as

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    WebView myWebView = new WebView(this);
    myWebView.getSettings().setJavaScriptEnabled(true);
    myWebView.setWebViewClient(new WebViewClient());
    myWebView.loadUrl("https://google.com");

    // Other AWS gibberish
}

I can get the webpage to fire as an separate application, but this is not what I want.

    WebView webview = new WebView(this);
    setContentView(webview);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl("http://google.ca");

Edit: I have already added the internet permission to the manifest

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

Some references I have been using here, here, here and documentation without success

Edit 2: Going through the device debug files and the following are being logged

10-18 22:07:59.296 7717-7717/com.amazon.mysampleapp I/WebViewFactory: Loading com.google.android.webview version 53.0.2785.124 (code 278512400)
10-18 22:07:59.306 7717-7826/com.amazon.mysampleapp I/System.out: (HTTPLog)-Static: SBServiceAPI: getService class android.os.ServiceManager
10-18 22:07:59.306 7717-7826/com.amazon.mysampleapp I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
10-18 22:07:59.306 7717-7826/com.amazon.mysampleapp I/System.out: (HTTPLog)-Static: isShipBuild true
10-18 22:07:59.306 7717-7826/com.amazon.mysampleapp I/System.out: (HTTPLog)-Thread-46729-141117018: SmartBonding Enabling is false, SHIP_BUILD is true, log to file is false, DBG is false
10-18 22:07:59.306 7717-7826/com.amazon.mysampleapp I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
10-18 22:07:59.336 7717-7826/com.amazon.mysampleapp I/System.out: KnoxVpnUidStorageknoxVpnSupported API value returned is false
10-18 22:07:59.336 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter>
10-18 22:07:59.336 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.ServiceWorkerControllerAdapter>
10-18 22:07:59.336 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
10-18 22:07:59.346 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.TokenBindingManagerAdapter>
10-18 22:07:59.366 7717-7717/com.amazon.mysampleapp I/cr_LibraryLoader: Time to load native libraries: 6 ms (timestamps 655-661)
10-18 22:07:59.366 7717-7717/com.amazon.mysampleapp I/cr_LibraryLoader: Expected native library version number "53.0.2785.124", actual native library version number "53.0.2785.124"
10-18 22:07:59.376 7717-7717/com.amazon.mysampleapp W/ResourceType: Failure getting entry for 0x01080ad1 (t=7 e=2769) (error -75)
10-18 22:07:59.386 7717-7717/com.amazon.mysampleapp I/cr_LibraryLoader: Expected native library version number "53.0.2785.124", actual native library version number "53.0.2785.124"
10-18 22:07:59.396 7717-7717/com.amazon.mysampleapp I/chromium: [INFO:library_loader_hooks.cc(151)] Chromium logging enabled: level = 0, default verbosity = 0
10-18 22:07:59.436 7717-7717/com.amazon.mysampleapp I/cr_BrowserStartup: Initializing chromium process, singleProcess=true
10-18 22:07:59.606 7717-7826/com.amazon.mysampleapp I/DefaultDeliveryClient: Successful submission of 4 events
10-18 22:07:59.646 7717-7843/com.amazon.mysampleapp W/cr_media: Requires BLUETOOTH permission
10-18 22:07:59.686 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContentsClientAdapter$WebResourceErrorImpl>
10-18 22:07:59.696 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<com.android.webview.chromium.WebViewContentsClientAdapter$WebResourceErrorImpl>
10-18 22:07:59.736 7717-7717/com.amazon.mysampleapp D/ConnectivityManager: CallingUid : 10097, CallingPid : 7717
10-18 22:07:59.736 7717-7854/com.amazon.mysampleapp D/ConnectivityManager.CallbackHandler: CM callback handler got msg 524290
10-18 22:07:59.766 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<org.chromium.content.browser.FloatingWebActionModeCallback>
10-18 22:07:59.766 7717-7717/com.amazon.mysampleapp I/art: Rejecting re-init on previously-failed class java.lang.Class<org.chromium.content.browser.FloatingWebActionModeCallback>
Community
  • 1
  • 1
Iorek
  • 393
  • 1
  • 8
  • 24

1 Answers1

5

Instead of instantiating a new Webview at onCreate I think you may need to use the one specified in your layout:

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.NAME_OF_THE_XML_FILE); // change here to match the name of your xml file


    // WebView myWebView = new WebView(this); instead of this, try this one below:
    WebView myWebView = (WebView) findViewById(R.id.webview);

    myWebView.getSettings().setJavaScriptEnabled(true);
    myWebView.setWebViewClient(new WebViewClient());
    myWebView.loadUrl("https://google.com");

    // Other AWS gibberish
}
Fábio Hiroki
  • 545
  • 2
  • 8
  • Is there a specific import to go with this? There is a "View cannot be converted to WebView" error on gradle compile – Iorek Oct 19 '16 at 02:29
  • 1
    Sorry, it was missing a cast in my solution. Please check my edited answer. – Fábio Hiroki Oct 19 '16 at 02:30
  • Afraid not. There is a fatal error on a null object, first on the setJavaScriptEnabled() and once that is removed the fatal error moves to setWebViewClient(). java.lang.NullPointerException: Attempt to invoke virtual method 'void android.webkit.WebView.setWebViewClient(android.webkit.WebViewClient)' on a null object reference – Iorek Oct 19 '16 at 02:40
  • You also need to explicitly set the layout file your activity is rendering to match the xml described in your question. Please check again my edited answer. – Fábio Hiroki Oct 19 '16 at 03:00
  • Still crashing. Thank you for holding my hand through this painful experience – Iorek Oct 19 '16 at 03:21
  • Sigh, I think this is turning into a hardware issue - validate_display:255 error 3008 (EGL_BAD_DISPLAY). Thank you for helping – Iorek Oct 19 '16 at 03:26
  • But is it the same crash that is happening (NullPointerException)? If that's the case, two things could be the problem: either the .xml file name is incorrect or the `WebView` specified in the layout file doesn't have the `android:id="@+id/webview"` property, which is the identifier used by the Activity to find the WebView reference – Fábio Hiroki Oct 19 '16 at 03:39
  • It is not crashing anymore. It is simply back to loading a blank webview page – Iorek Oct 19 '16 at 03:42
  • Don't know if you are testing only in the emulator, but i would suggest you test on a real Android device to check if the error still occurs. Found on this answer: http://stackoverflow.com/questions/32897280/android-webview-app-crashing-in-emulator-null-application-context that the problem could be related to the emulator configuration. – Fábio Hiroki Oct 19 '16 at 04:06
  • I am using a real android device to test – Iorek Oct 19 '16 at 09:54