6

The app works on previous versions of Android, but not on Oreo. It's a WebView with Notifications. I've been researching this error and haven't found anything similar.

The stack trace:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: net.oneteamit.tk, PID: 3171
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.oneteamit.tk/net.oneteamit.tk.MainActivity}:
    java.lang.IllegalArgumentException
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6541)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
 Caused by: java.lang.IllegalArgumentException
    at android.os.Parcel.readException(Parcel.java:1946)
    at android.os.Parcel.readException(Parcel.java:1888)
    at android.app.INotificationManager$Stub$Proxy.createNotificationChannels(INotificationManager.java:1418)
    at android.app.NotificationManager.createNotificationChannels(NotificationManager.java:446)
    at android.app.NotificationManager.createNotificationChannel(NotificationManager.java:434)
    at net.oneteamit.tk.MainActivity.onCreate(MainActivity.java:47)
    at android.app.Activity.performCreate(Activity.java:6975)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
    at android.app.ActivityThread.-wrap11(Unknown Source:0) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
    at android.os.Handler.dispatchMessage(Handler.java:105) 
    at android.os.Looper.loop(Looper.java:164) 
    at android.app.ActivityThread.main(ActivityThread.java:6541) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

MainActivity:

public class MainActivity extends AppCompatActivity {

    private WebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mWebView = (WebView) findViewById(R.id.activity_main_webview);
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mWebView.loadUrl("My test URL");
        mWebView.setWebViewClient(new WebViewClient());
        mWebView.getSettings().setAppCacheEnabled(false);
        mWebView.clearCache(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            // Create channel to show notifications.
            String channelId  = getString(R.string.default_notification_channel_id);
            String channelName = getString(R.string.default_notification_channel_name);

            NotificationManager notificationManager =
                getSystemService(NotificationManager.class);

            notificationManager.createNotificationChannel(
                new NotificationChannel(channelId,
                                        channelName,
                                        NotificationManager.IMPORTANCE_LOW));
        }

        mWebView.getSettings().setUseWideViewPort(true);
        mWebView.getSettings().setLoadWithOverviewMode(true);
        mWebView.setInitialScale(1);
        mWebView.getSettings().setBuiltInZoomControls(true);
    }
}
Mike M.
  • 38,532
  • 8
  • 99
  • 95
Chris H
  • 61
  • 1
  • 3
  • Comment out the call to `notificationManager.createNotificationChannel(...);` to see if the exception still occurs. Check that the values of `default_notification_channel_id` and `default_notification_channel_name` are not null or empty. – Bob Snyder Mar 02 '18 at 17:19
  • This Worked! I just commented out the 2 lines i had for notificationManager.createNotificationChannel(...) and it worked. – Chris H Mar 02 '18 at 18:55
  • You'll have to experiment to see why creating the channel is failing. Possibly your channel id or channel name are invalid. – Bob Snyder Mar 02 '18 at 19:08

3 Answers3

12

This exception occurs when the channel name is invalid. I was able to reproduce the stack trace by running with an empty channel name:

<string name="default_notification_channel_name"></string>

Check the value you have defined for default_notification_channel_name and change it to a valid value.

Bob Snyder
  • 37,759
  • 6
  • 111
  • 158
3

<string name="app_name"></string> was the reason of this error. Empty string causes FATAL EXCEPTION.

foodman47
  • 41
  • 2
1

AppCompactActivity is backward compatible but not forward compatible,are there any components that you are using that are not supported by Android 8.0,or is the Android Studio or the IDE up to date with Oreo.

  • not sure, I am researching but so far the notification part should work. – Chris H Mar 02 '18 at 16:32
  • I have another app which is just a webview and works for jellybean and up to Oreo, Im not changeing this one but my current app is a duplicate with firebase notifications in it. – Chris H Mar 02 '18 at 16:37