【发布时间】:2014-04-19 21:44:52
【问题描述】:
我是 eclipse/Java 的新手。我寻找答案,但没有解决我的问题。我希望有人可以指导我。我正在尝试使用 android 应用程序启动网页,但是我在 Android Virtual Emulation 中得到一个空白页面。
这是我的代码
package com.example.t4;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.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:android="http://schemas.android.com/apk/res/android"
package="com.example.t4"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.t4.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>
这里是activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
我不确定我做错了什么。代码运行没有错误。我只是得到一个空白屏幕。任何帮助深表感谢。提前致谢。
【问题讨论】:
-
您能检查一下您的 AVD 是否在线吗?只需转到浏览器并尝试转到 google.com 或其他一些随机页面。
-
感谢您的建议。我打开了 AVD,只有一个空白页。没有一个按钮在做任何事情。我对此真的很陌生,所以请耐心等待。你能指导我更多吗?
-
我点击了“主页”按钮,它什么也没做。或任何其他按钮,
-
您的 AVD 尚未加载。那是你的问题。根据您的计算机,最多可能需要 15 分钟。
-
感谢 DrkStr。你是对的,它需要一段时间才能加载。我可以看到 AVD。我在屏幕周围有一个红色边框,现在我正在等待查看应用程序是否加载。到目前为止什么都没有。我会在 1 小时后出去检查。