2017-05-14 9 views
0

以下のコードはエラー404の生成時に指定されたリンクにリダイレクトされず、エラーページを表示しています。親切にも下のコードを見てください。Webビューでエラー404が生成されました - 目的のページにリダイレクトされません

@Override 
public void onReceivedError(WebView view, int errorCode, 
          String description, String failingUrl) { 
    //Log.e(TAG," Error occured while loading the page at Url"+ failingUrl+"." +description); 

    if (errorCode == 404) { 
     // show Alert here for Page Not found 
     view.loadUrl("http://google.com"); 
    } else { 
     Intent intent = new Intent(MainActivity.this, noconnection.class); 
     intent.putExtra("a", "mainactivity is source"); 
     startActivity(intent); 

     Toast.makeText(getApplicationContext(), "Error occured, please check network connectivity", Toast.LENGTH_SHORT).show(); 
     super.onReceivedError(view, errorCode, description, failingUrl); 
    } 
} 

エラーログ:

05-14 09:54:36.655 5673-5673/com.hare.pat E/SysUtils: ApplicationContext is null in ApplicationStatus 
05-14 09:54:36.885 5673-5673/com.hare.pat E/chromium: [ERROR:browser_gpu_channel_host_factory.cc(258)] Failed to init browser shader disk cache. 
05-14 09:54:37.026 5673-5673/com.hare.pat E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY) 

答えて

0

エラーコードはERROR_ *一定の値に対応し、いない404

あなたはERROR_FILE_NOT_FOUNDを使用する必要があります(その定数値は-14) (documentation

定数here 参考としてここにエラー定数を追加しました。

/** Generic error */ 
public static final int ERROR_UNKNOWN = -1; 
/** Server or proxy hostname lookup failed */ 
public static final int ERROR_HOST_LOOKUP = -2; 
/** Unsupported authentication scheme (not basic or digest) */ 
public static final int ERROR_UNSUPPORTED_AUTH_SCHEME = -3; 
/** User authentication failed on server */ 
public static final int ERROR_AUTHENTICATION = -4; 
/** User authentication failed on proxy */ 
public static final int ERROR_PROXY_AUTHENTICATION = -5; 
/** Failed to connect to the server */ 
public static final int ERROR_CONNECT = -6; 
/** Failed to read or write to the server */ 
public static final int ERROR_IO = -7; 
/** Connection timed out */ 
public static final int ERROR_TIMEOUT = -8; 
/** Too many redirects */ 
public static final int ERROR_REDIRECT_LOOP = -9; 
/** Unsupported URI scheme */ 
public static final int ERROR_UNSUPPORTED_SCHEME = -10; 
/** Failed to perform SSL handshake */ 
public static final int ERROR_FAILED_SSL_HANDSHAKE = -11; 
/** Malformed URL */ 
public static final int ERROR_BAD_URL = -12; 
/** Generic file error */ 
public static final int ERROR_FILE = -13; 
/** File not found */ 
public static final int ERROR_FILE_NOT_FOUND = -14; 
/** Too many requests during this load */ 
public static final int ERROR_TOO_MANY_REQUESTS = -15; 
+0

まだ同じで、リダイレクトしていません – Observer

+0

デバッガポイントをそこに置いて、どのようなエラーコード値を取得できますか? – Santosh

+0

あなたはhttp://stackoverflow.com/questions/34626377/android-webview-error-failed-to-init-browser-shader-disk-cacheとhttp://stackoverflow.com/questions/30013125/sysutils- applicationcontext-null-in-applicationstatus-webview ...私は 'errorCode == 404'以外の問題があると思います。 – Santosh

関連する問題