I'm developing a very simple Android app on a Mac in AndroidStudio and I've created an AVD based on the Nexus S. The app compiles with no issues, the emulator launches and then I get errors in logcat and the app crashes. In the emulator, an error dialog displays with the message "Unfortunately App has stopped"
Here's the logcat output (error level):
10-01 13:59:27.813 14114-14114/com.company.app E/SysUtils﹕ ApplicationContext is null in ApplicationStatus
10-01 13:59:27.832 14114-14114/com.company.app E/libEGL﹕ validate_display:255 error 3008 (EGL_BAD_DISPLAY)
10-01 13:59:27.832 14114-14114/com.company.app E/libEGL﹕ validate_display:255 error 3008 (EGL_BAD_DISPLAY)
10-01 13:59:27.832 14114-14114/com.company.app E/chromium﹕ [ERROR:gl_surface_egl.cc(327)] No suitable EGL configs found.
10-01 13:59:27.832 14114-14114/com.company.app E/chromium﹕ [ERROR:gl_surface_android.cc(23)] GLSurfaceEGL::InitializeOneOff failed.
10-01 13:59:27.832 14114-14114/com.company.app E/chromium﹕ [ERROR:browser_main_loop.cc(698)] GLSurface::InitializeOneOff failed
10-01 13:59:27.854 14114-14114/com.company.app E/DataReductionProxySettingListener﹕ No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp
10-01 13:59:28.530 14114-14165/com.company.app A/chromium﹕ [FATAL:gl_surface_android.cc(58)] Check failed: kGLImplementationNone != GetGLImplementation() (0 vs. 0)
10-01 13:59:28.530 14114-14165/com.company.app A/libc﹕ Fatal signal 6 (SIGABRT), code -6 in tid 14165 (GpuThread)
I'm assuming that the first error related to ApplicationContext is the cause of the other errors, but I'm not sure about that. I've tried about 10 different methods for setting context, but the ApplicationContext error persists.
My main questions: Is the ApplicationContext error the root cause of the crash? If not, what is? What might I try to fix it?
Here's the complete application code for reference:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company.app" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<uses-permission android:name="android.permission.INTERNET" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package com.company.app;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebSettings;
public class MainActivity extends AppCompatActivity {
private String appUrl = "http://company.com/mobile/index.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webView);
myWebView.setWebViewClient(new MyWebViewClient());
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl(appUrl);
}
}
MyWebViewClient.java
package com.company.app;
import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("company.com")) {
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent);
return true;
}
}