开发者社区> 问答> 正文

各位大神,帮忙分析以下代码在安卓手机上运行时报错的原因行吗?

//MainActivity.java如下:

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings.RenderPriority;
import android.webkit.WebView;
import android.webkit.WebViewClient;
    public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

WebView browser=(WebView)findViewById(R.id.Toweb);  
browser.loadUrl("http://58.215.195.18:10010/login_person.jsp");  //在此app不能上网提示“Proxy_Error",但UC浏览器和电脑都能上
browser.getSettings().setSupportZoom(true);  
browser.getSettings().setBuiltInZoomControls(true);  
browser.getSettings().setJavaScriptEnabled(true);
browser.getSettings().setDomStorageEnabled(true);
browser.getSettings().setBlockNetworkImage(true);
browser.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
browser.getSettings().setAllowFileAccess(true);
browser.getSettings().setAppCacheEnabled(true); 
browser.getSettings().setSaveFormData(false);
browser.getSettings().setLoadsImagesAutomatically(true);
browser.setWebViewClient(new WebViewClient() {  
    public boolean shouldOverrideUrlLoading(WebView view, String url)  
    {   

        view.loadUrl(url);  
                return true;  
    }         
     }); 
}  

@Override  
public boolean onKeyDown(int keyCode, KeyEvent event) {  
WebView browser=(WebView)findViewById(R.id.Toweb);  
// Check if the key event was the Back button and if there's history  
if ((keyCode == KeyEvent.KEYCODE_BACK) && browser.canGoBack()) {  
    browser.goBack();  
    return true;  
}  
return super.onKeyDown(keyCode, event);  
} 


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
} 

//activity_main.xml如下:

     xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.wuxireservedfunds.MainActivity" >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
    <WebView android:id="@+id/Toweb"  
        android:layout_width="fill_parent"  
        android:layout_height="fill_parent" /> 

</RelativeLayout>

//AndroidManifest.xml如下:

<?xml version="1.0" encoding="utf-8"?>
   <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.wuxireservedfunds"
    android:versionCode="1"
    android:versionName="1.0" >
     <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="21" />
     <uses-permission 
            android:name="android.permission.INTERNET">
        </uses-permission>  
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest> 

screenshot

展开
收起
爵霸 2016-02-29 15:55:51 2678 0
1 条回答
写回答
取消 提交回答
  • 你得贴错误日志呀!不然不好找到错误的原因

    2019-07-17 18:50:25
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载