So far no one has been able to provided an answer or solution that resolves this. I hope someone has something to contribute because I'm at a loss. And this article (What is a NullPointerException, and how do I fix it?), even if everyone keeps recommending it as the 'go to guide' for 'null exceptions', I find it hard to apply to my situation as it relates to webView and the settings I've provided in the java script below.
If I remove the webView lines from the activity, the activity's page loads fine in the app. All white and without content of course, but it loads. Once I add the webView code back to the activity; the app crashes as soon as it attempts to load. While it appears to crash, the app actually loads the activity page in all white and throws itself to the device's background without closing and pops up a notification stating the obvious, that the app has crashed. It doesn't really exit the app, it just throws it to the backgrounds and sends up an error message. So I believe that the remedy can be found in reviewing my webView related code, but I can't find it and none of the previously recommended methods remedied it. And I should note that this is happening both on my actual connected device and on Android Studio's emulator, so I don't believe it to be phone settings or a cache issue either.
Here is my LogCat
05-08 14:19:03.423 31797-31797/com.app.sega E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.sega, PID: 31797
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.sega/com.app.sega.sega}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.webkit.WebView.findViewById(int)' on a null object reference
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.webkit.WebView.findViewById(int)' on a null object reference
at com.app.sega.sega.onCreate(sega.java:18)
I've just updated my files content below in trying to fix this. This is what I have as of right now. Getting the same results.
The webView script on the new activity in sega.java
package com.app.sega;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.appcompat.app.AppCompatActivity;
public class sega extends AppCompatActivity {
private WebView webview_s;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sega);
webview_s = (WebView)webview_s.findViewById(R.id.webview_sega);
webview_s.getSettings().getJavaScriptEnabled();
webview_s.setWebViewClient(new WebViewClient_s());
webview_s.setInitialScale(1);
webview_s.getSettings().getBuiltInZoomControls();
webview_s.getSettings().getUseWideViewPort();
}
private class WebViewClient_s extends WebViewClient {
public boolean shouldOverrideURLLoading (WebView view, String url) {
if (Uri.parse(url).getHost().equals("www.southeastgeorgiatoday.com")) {
return false;
}else {
Intent intent_sega = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent_sega);
return true;
}
}
}
}
I see nothing on line (sega.java:18) that is left empty/null. This is what is on line 18:
webview_s = (WebView)webview_s.findViewById(R.id.webview_sega);
Where is there a null entry? Here is the webView xml located in activity_sega.xml. you can see that I've entered the correct webView id in the java code above.
<WebView android:id="@+id/webview_sega"
android:layout_width="match_parent"
android:layout_height="match_parent" />