0

The Web Page at file:///#/android_asset/webpage.htm could not be loaded as: Is a directory.在模拟器中遇到错误。

但我的代码是webView.loadUrl("file:///android_asset/webpage.htm");

首先页面完美呈现,但在渲染后再次刷新页面并且没有被加载并且将使网页不可用。如果我们仔细看android模拟器给出的url,在android_asset之前有两个额外的字符。

下面是代码。

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){

        }

    }
}

期待你的答复。

谢谢。

4

2 回答 2

1

哦,这让我头疼,他们改变了其中一个 android 版本的工作方式,但不记得是哪个。这是我所做的:

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

如果您的静态网页有图片,请使用此链接:

file:///android_asset/yourimage.png

编辑试试这个:https ://stackoverflow.com/a/8737547/969325 ,清理项目并检查资产文件是否在路径中。

于 2012-05-14T13:03:11.720 回答
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;  

             }  
         } 
于 2012-05-14T13:05:20.433 回答