【发布时间】:2013-11-07 08:46:52
【问题描述】:
这是我的代码:
public class AboutActivity extends Activity{
WebView aboutwebview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.edit_profile_settings);
aboutwebview = (WebView) findViewById(R.id.aboutwebview);
aboutwebview.setHorizontalScrollBarEnabled(false);
aboutwebview.loadUrl("file:///android_asset/pickld.html");
}
}
这里是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" >
<LinearLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#7fad33"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="@+id/tv0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Our Team"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff" />
</LinearLayout>
<WebView
android:id="@+id/aboutwebview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
我很确定html 文件位于 assets 文件夹中,我还在清单文件上设置了权限,但是当我运行应用程序时,我遇到了强制关闭错误说问题出在这一行:
aboutwebview.loadUrl("file:///android_asset/pickld.html");
我想知道可能是什么问题。
这是 logcat 错误:
【问题讨论】:
-
有什么问题?发布错误日志
-
请发布 logcat 错误。
-
看起来
webview为空。那是你有 webview 的 xml 吗? -
您确定您发布了edit_profile_settings.xml 代码吗?检查您是否使用正确的布局。你正在获得 NPE。
-
pickld.html 文件是否正确?