所以,我复制本教程示例东西吧,从谷歌的android的网站,我是个得到一个错误,R.id无法得到解决。
下面是我的Java文件
包com.TestApp.HelloWebView;
进口android.app.Activity;
进口android.os.Bundle;
进口android.webkit.WebView;
公共类HelloWebView延伸活动{
的WebView mWebView;
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
mWebView =(web视图)findViewById(R.id.webview);
mWebView.getSettings()setJavaScriptEnabled(真)。
mWebView.loadUrl(http://www.google.com);
}
}
下面是我的 RES /布局/ main.xml中
< XML版本=1.0编码=UTF-8&GT?;
<的WebView机器人:ID =@ + ID / web视图
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT/>
解决方案
您必须导入R舱
进口com.TestApp.HelloWebView.R;
另外,作为需求贴你必须使用一个命名空间布局。
XML版本=1.0编码=UTF-8&GT?;
<的WebView的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / web视图
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT/>
So I copied this tutorial example thing right from Google's android site and I ma getting an error that R.id cannot be resolved.
Here is my Java file
package com.TestApp.HelloWebView;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class HelloWebView extends Activity {
WebView mWebView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.google.com");
}
}
Here is my res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<WebView android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
解决方案
You have to import your R class
import com.TestApp.HelloWebView.R;
Also as Demand posted you have to use a namespace for your layout.
?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>