有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

尝试在应用程序内加载url时出现java空白屏幕

我是eclipse/Java新手。我寻找答案,但什么也解决不了我的问题。我希望有人能指导我。我试图启动一个带有安卓应用程序的网页,但是在安卓虚拟仿真中我得到了一个空白页面

这是我的密码

package com.example.t4;

import 安卓.os.Bundle;
import 安卓.app.Activity;
import 安卓.view.Menu;
import 安卓.webkit.WebView;

public class MainActivity extends Activity {

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

    WebView myWebView = (WebView) findViewById(R.id.webview);
    myWebView.loadUrl("http://www.google.com");
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
     // Inflate the menu; this adds items to the action bar if it is present.
     getMenuInflater().inflate(R.menu.main, menu);
     return true;
  }
}

这是AndroidManifest。xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
package="com.example.t4"
安卓:versionCode="1"
安卓:versionName="1.0" >
<uses-permission 安卓:name="安卓.permission.INTERNET"></uses-permission>

<uses-sdk
    安卓:minSdkVersion="8"
    安卓:targetSdkVersion="18" />

<application
    安卓:allowBackup="true"
    安卓:icon="@drawable/ic_launcher"
    安卓:label="@string/app_name"
    安卓:theme="@style/AppTheme" >
    <activity
        安卓:name="com.example.t4.MainActivity"
        安卓:label="@string/app_name" >
        <intent-filter>
            <action 安卓:name="安卓.intent.action.MAIN" />

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

   </manifest>

这是主要的活动。xml

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

<WebView 
    安卓:id="@+id/webview"
    安卓:layout_width="fill_parent"
    安卓:layout_height="fill_parent"
/>

</LinearLayout>

我不确定我做错了什么。代码运行时没有错误。我只是得到一个空白屏幕。非常感谢您的帮助。提前谢谢


共 (3) 个答案

  1. # 1 楼答案

    重新启动你的应用程序(我的意思是再次点击Run),并确保你已经启用了上面提到的javaScript

  2. # 2 楼答案

    看看这个working basic webview。我用你的“www.google.com”进行了测试,得到了一个空白视图。我用了“http://www.google.com”,它运行得很好。试试你的?但是也可以随意窃取示例代码

  3. # 3 楼答案

    尝试将myWebView.getSettings().setJavaScriptEnabled(true);//启用javascript

    myWebView.loadUrl("http://www.google.com");