0

I'm trying to create a simple App that loads a url into a webview. However, I keep getting net::ERR_CACHE_MISS. I've added the relevant permission for the internet which seemed the most common cause for the error.

Here is my code:

public class MainActivity extends AppCompatActivity {

private static String TAG = "Main";

@Override
protected void onCreate(Bundle savedInstanceState) {
   // getWindow().requestFeature(Window.FEATURE_PROGRESS);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}

@Override
protected void onStart() {
    super.onStart();
    WebView webview = (WebView)findViewById(R.id.web_view);
    webview.setWebViewClient(new myWebviewClient());

    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setLoadWithOverviewMode(true);
    webview.getSettings().setUseWideViewPort(true);

    webview.loadUrl("http://www.foodport.co.in");

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

public class myWebviewClient extends WebViewClient {
    @Override
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        super.onReceivedError(view, errorCode, description, failingUrl);
        Log.i(TAG, "onReceivedError "+ errorCode);
    }
}

I've added <uses-permission android:name="ANDROID.PERMISSION.INTERNET"/> to the manifest file.

Any help? The only clue I have is that a had another app using the same package name on the same phone, but that also that all the permissions. I'm checking on a phone which runs Android 4.4, I checked this post but I don't think this is the problem.

Community
  • 1
  • 1
Aman Gupta
  • 557
  • 1
  • 8
  • 23

3 Answers3

1

I've added to the manifest file

Android is case-sensitive. Please edit this to be android.permission.INTERNET.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

try this code

if (Build.VERSION.SDK_INT >= 19) {
    webview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
}
  or use this code 
 webview.getSettings().setCacheMode(android.webkit.WebSettings.LOAD_NO_CACHE);
anu
  • 213
  • 1
  • 3
  • 10
  • check this one ::: webview.getSettings().setCacheMode(android.webkit.WebSettings.LOAD_NO_CACHE); – anu Jul 09 '15 at 12:49
-2

You have to set the WebView webview = (WebView)findViewById(R.id.web_view);
in OnCreate method instead of onStart after setting layout for the activity setContentView(R.layout.activity_layout);

Abhijeet
  • 392
  • 2
  • 13
  • As per the activity life-cycle, `onCreate()` gets called first. After that `onStart()` gets called. So, it's completely fine to instantiate the web view in `onStart()` as the layout is already loaded. – Prerak Sola Jul 09 '15 at 12:38