WebView示例android
mView中有错误,我需要解决方案WebView示例android,android,android-webview,Android,Android Webview,mView中有错误,我需要解决方案 package com.example.account; import android.app.Activity; import android.os.Bundle; public class WebView extends Activity { private WebView webView; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInsta
package com.example.account;
import android.app.Activity;
import android.os.Bundle;
public class WebView extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");
}
}
我的xml
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
您应该将webview保留在任何父视图中尝试此布局
<?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/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
您使用的活动名称为
WebView
。SDK API已使用此名称。这就是它给你错误的原因
要解决这个问题,只需将您的WebView.java
文件重命名为另一个名称,如MyWebView.java
,那么您的问题肯定会得到解决
要安全地重命名.java文件,只需转到packageexplorer,选择WebView.java并按F2键,然后指定新名称。试试这个,可能会有所帮助
1。使用Eclipse创建一个新的Android项目,并将其命名为WebView
2。将以下语句添加到main.xml文件:
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent” >
<WebView
android:id=”@+id/webview1”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />
</LinearLayout>
4。不要忘记在清单文件中授予internet权限
谢谢
- 不要使用保留字作为变量、类和方法名。
- 这里,WebView被SDK保留或已经使用。若你们再使用那个词,编译器会感到困惑
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
请详细说明您面临的问题是什么Define
不起作用吗?
无法从视图转换到webview webview MVView=(webview)findViewById(R.id.webView1)@user3422485请上传webview文件的完整代码。只需查看此教程链接,同意您的观点,但请查看此链接。我认为OP正在使用它。有同样的问题,在保存所有干净的项目后,(无法从视图转换到webview)@user3422485,你能上传完整的代码吗?@user3422485错误是由于一些不同的原因产生的。请发布你的代码谢谢。但有趣的是,在编译java时并没有说在name@user3422485对它在编译时没有给出错误,它只在运行时给出这样的错误。谢谢),但是如果你想创建一个类,编译器会说有问题)@user3422485我希望这个功能将来会出现。
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent” >
<WebView
android:id=”@+id/webview1”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />
</LinearLayout>
package com.emergingandroidtech.WebView;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class MainActivity extends Activity
{
/**Called when the activity is first created.*/
@Override
public void onCreate(BundlesavedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView wv = (WebView) findViewById(R.id.webview1);
WebSettings webSettings = wv.getSettings();
webSettings.setBuiltInZoomControls(true);
wv.loadUrl( “www.google.com”);
}
}
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity
{
private WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview=(WebView)findViewById(R.id.webview);
//loads androidride homepage to webview
webview.loadUrl("https://www.androidride.com");
}
}