我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){
}
}
}
期待你的答复。
谢谢。