为什么我的程序无法打开webView页面?

时间:2012-10-24 18:48:52

标签: android android-webview connect

我创建了一个程序应该连接到互联网的Android应用程序,当我按下Go按钮时,程序应该打开webView页面(google.com)。我的程序无法连接到互联网,我不知道为什么?我将log.i()函数添加到程序中,当我点击按钮时,我看到了这一点。

Go.java

package org.example.test;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.view.View.OnClickListener;

public class MainActivity extends Activity{
private WebView webView;
private Button go_button;

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    Log.i(UI_MODE_SERVICE, "HELOOOOOOOOOOOOOOOOOO");
    setContentView(R.layout.activity_main);
    webView=(WebView) findViewById(R.id.web_view);
    go_button=(Button) findViewById(R.id.go_button);
    go_button.setOnClickListener(new OnClickListener(){
        public void onClick(View view){
            Log.i(UI_MODE_SERVICE, "STARRRRRRRRRRRRRRT");
            webView.loadUrl("http://www.google.com");
            Log.i(UI_MODE_SERVICE, "BYEEEEEEEEEEEEEEEEEEEEE");
        }
    });
}
 }

MainActivity:

package org.example.test;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
    }

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

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <WebView
         android:id="@+id/web_view"
         android:layout_width="match_parent"
         android:layout_height="0dp"
         android:layout_weight="1.0" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/go_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/go_button"/>
      </LinearLayout>
  </LinearLayout>

的strings.xml

<resources>

    <string name="app_name">test</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>

    <string name="go_button">GO</string>

 </resources>

的AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.example.test"
    android:versionCode="1"
    android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
 </application>

</manifest>

logcat的:

10-24 22:04:50.674: DEBUG/AndroidRuntime(30445): >>>>>> AndroidRuntime START  com.android.internal.os.RuntimeInit <<<<<<
10-24 22:04:50.674: DEBUG/AndroidRuntime(30445): CheckJNI is OFF
10-24 22:04:50.854: DEBUG/AndroidRuntime(30445): Calling main entry com.android.commands.pm.Pm
10-24 22:04:50.870: DEBUG/AndroidRuntime(30445): Shutting down VM
10-24 22:04:50.870: INFO/AndroidRuntime(30445): NOTE: attach of thread 'Binder Thread #3' failed
10-24 22:04:50.877: DEBUG/dalvikvm(30445): GC_CONCURRENT freed 101K, 89% free 463K/4096K, paused 0ms+1ms
10-24 22:04:50.885: DEBUG/jdwp(30445): Got wake-up signal, bailing out of select
10-24 22:04:50.885: DEBUG/dalvikvm(30445): Debugger has detached; object registry had 1 entries
10-24 22:04:51.213: DEBUG/AndroidRuntime(30458): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
10-24 22:04:51.213: DEBUG/AndroidRuntime(30458): CheckJNI is OFF
10-24 22:04:51.393: DEBUG/AndroidRuntime(30458): Calling main entry com.android.commands.am.Am
10-24 22:04:51.393: INFO/ActivityManager(178): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=org.example.test/.MainActivity} from pid 30458
10-24 22:04:51.495: DEBUG/AndroidRuntime(30458): Shutting down VM
10-24 22:04:51.510: DEBUG/dalvikvm(30469): Late-enabling CheckJNI
10-24 22:04:51.510: INFO/ActivityManager(178): Start proc org.example.test for activity org.example.test/.MainActivity: pid=30469 uid=10111 gids={}
10-24 22:04:51.518: DEBUG/dalvikvm(30458): GC_CONCURRENT freed 102K, 89% free 484K/4096K, paused 1ms+0ms
10-24 22:04:51.518: DEBUG/dalvikvm(30458): Debugger has detached; object registry had 1 entries
10-24 22:04:51.518: INFO/AndroidRuntime(30458): NOTE: attach of thread 'Binder Thread #3' failed
10-24 22:04:51.526: INFO/WindowManager(178): createSurface Window{41cc2288 Starting org.example.test paused=false}: DRAW NOW PENDING
10-24 22:04:51.573: DEBUG/OpenGLRenderer(438): Flushing caches (mode 1)
10-24 22:04:51.580: INFO/uimode(30469): HELOOOOOOOOOOOOOOOOOO
10-24 22:04:51.635: DEBUG/OpenGLRenderer(438): Flushing caches (mode 0)
10-24 22:04:51.666: INFO/WindowManager(178): createSurface Window{41cc2e48 org.example.test/org.example.test.MainActivity paused=false}: DRAW NOW PENDING
10-24 22:04:51.690: DEBUG/libEGL(30469): loaded /system/lib/egl/libGLES_android.so
10-24 22:04:51.698: DEBUG/libEGL(30469): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
10-24 22:04:51.698: DEBUG/libEGL(30469): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
10-24 22:04:51.705: DEBUG/libEGL(30469): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
10-24 22:04:51.854: DEBUG/OpenGLRenderer(30469): Enabling debug mode 0
10-24 22:04:52.260: INFO/ActivityManager(178): Displayed org.example.test/.MainActivity: +767ms
10-24 22:05:00.276: INFO/uimode(30469): STARRRRRRRRRRRRRRT
10-24 22:05:00.276: INFO/uimode(30469): BYEEEEEEEEEEEEEEEEEEEEE
10-24 22:05:03.659: INFO/uimode(30469): STARRRRRRRRRRRRRRT
10-24 22:05:03.659: INFO/uimode(30469): BYEEEEEEEEEEEEEEEEEEEEE

感谢您的建议。 欢呼声。

2 个答案:

答案 0 :(得分:1)

您需要在Manifest中添加INTERNET权限。

答案 1 :(得分:0)

1)你的堆栈追溯难以辨认:我不知道是否有错误

2)感谢您提供AndroidManifest.xml。我没有看到“互联网”权限 - 你需要它!