0

I am getting error as The Web Page at file:///#/android_asset/webpage.htm could not be loaded as: Is a directory. in the emulator.

but my code is webView.loadUrl("file:///android_asset/webpage.htm");

First the page renders perfectly but again after rendering refreshes the page and does not get loaded and will get the web page not available. If we could carefully see the url that has been given out by the android emulator there are two extra characters before android_asset.

Below is the code.

public class Catalog extends Activity {
final Activity activity = this;
WebView webView;
 ProgressDialog progressDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);//used for rendering percentage of loading 
setContentView(R.layout.catalog_layout);

try{

    webView = (WebView) findViewById(R.id.browserwebview);
    webView.getSettings().setJavaScriptEnabled(true);

     webView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress)
            {
                activity.setTitle("Loading...");
                activity.setProgressBarVisibility(true);
                activity.setProgress(progress * 100);

                if(progress == 100){
                    activity.setTitle(R.string.app_name);

                }

            }

        });

        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
            {
                Toast.makeText(activity, "Oh no!"+ description, Toast.LENGTH_SHORT).show();

            }

            @Override
            public void onLoadResource (WebView view, String url) {


            }




            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {


                return true;
            }


        });





        webView.loadUrl("file:/android_asset/web/webpage.html");


}
catch (Exception e) {
    e.printStackTrace();
}


ImageButton btnBack = (ImageButton)this.findViewById(R.id.buttonBackCatalog);
btnBack.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View view) {
        if(webView.canGoBack()){
             webView.goBack();
        }else{
            Intent myIntent = new Intent(view.getContext(), FCFActivity.class);`
           `startActivityForResult(myIntent, 0);
        }


    }


});


/*
 * Actions for footer Buttons
 * 
 */

ImageButton buttonFooterMainHome = (ImageButton)findViewById(R.id.footerMainBtnHome);
buttonFooterMainHome.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View view) {
        Intent myIntent = new Intent(view.getContext(), FCFActivity.class);
        startActivityForResult(myIntent, 0);

    }
});


LinearLayout homeLinearLayout=(LinearLayout)this.findViewById(R.id.footerLayoutHome);
homeLinearLayout.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View view) {
        Intent myIntent = new Intent(view.getContext(), FCFActivity.class);
        startActivityForResult(myIntent, 0);

    }
});






}
     @Override
    public void onConfigurationChanged(final Configuration newConfig)
    {
        // Ignore orientation change to keep activity from restarting
        super.onConfigurationChanged(newConfig);

        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {

        } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){

        }

    }
}

Looking forward to your reply.

thanks.

Mukunda
  • 1,593
  • 3
  • 26
  • 45
  • Let me get this straight. You get to the webpage, but when the progress bar is done loading you get the error? Tryed removing it see if it is related? Tryed with a very simple html file? – Warpzit May 14 '12 at 18:42

2 Answers2

1

Oh this caused me headaches, and they changed how it worked for one of the android versions, but can't remember which. Here is what I do:

webView.loadUrl("file:/android_asset/webpage.html");

and if your static webpage has images you use this link:

file:///android_asset/yourimage.png

Edit try this: https://stackoverflow.com/a/8737547/969325, clean project and check if asset file is at path.

Community
  • 1
  • 1
Warpzit
  • 27,966
  • 19
  • 103
  • 155
0
- `You are using only htm use html` 


webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new myWebClient());
webview.loadurl();
and


 public class myWebClient extends WebViewClient  
         {  
             @Override  
             public void onPageStarted(WebView view, String url, Bitmap favicon) {  
                 // TODO Auto-generated method stub  
                 super.onPageStarted(view, url, favicon);  
             }  

             @Override  
             public boolean shouldOverrideUrlLoading(WebView view, String url) {  
                 // TODO Auto-generated method stub  

                 view.loadUrl(url);  
                 return true;  

             }  
         } 
Nitin
  • 1,966
  • 4
  • 22
  • 53