2 struggle100403 struggle100403 于 2016.04.28 15:23 提问

各位高手,帮我分析以下代码在安卓手机上运行时报错的原因!

//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> ```


在eclipse中编译时并没有错误提示,是apk在模拟器和手机运行时报错误,具体如下:
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /login_person.jsp.
Reason:Error reading from remote server

但是网址:http://58.215.195.18:10010/login_person.jsp却能在手机的uc浏览器
和电脑上正常打开,真是百思不得其解!高手们,出马啊!拜托了!




5个回答

baidu_23086307
baidu_23086307   2016.04.29 07:25

你得贴错误日志呀!不然不好找到错误的原因

CSDNXIAON
CSDNXIAON   2016.04.29 09:12

求高手请进,帮我分析这种情况是什么原因
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!

u012215068
u012215068   2016.05.04 15:45

估计是你的webview的设置没有弄好··

  WebSettings s = getSettings();
        s.setBuiltInZoomControls(true);
        s.setCacheMode(WebSettings.LOAD_NO_CACHE);  //设置 缓存模式
        s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        s.setUseWideViewPort(true);
        s.setLoadWithOverviewMode(true);
        // s.setSavePassword(true);
        s.setSaveFormData(true);
        s.setJavaScriptEnabled(true);
        mWebChromeClient = new MyWebChromeClient();
        setWebChromeClient(mWebChromeClient);

        setWebViewClient(new MyWebViewClient());
u010560898
u010560898   2016.05.07 17:00
dongfeng9ge
dongfeng9ge   Ds   Rxr 2016.05.18 13:28

你把logcat贴出来给大家看看呀

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!