gpt4 book ai didi

java - R.id 无法解析

转载 作者:IT老高 更新时间:2023-10-28 23:17:33 26 4
gpt4 key购买 nike

所以我直接从 Google 的 android 网站复制了这个教程示例,我收到了一个 R.id 无法解析的错误。

这是我的 Java 文件

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");
}

}

这是我的 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"/>

最佳答案

你必须导入你的 R 类

import com.TestApp.HelloWebView.R;

正如 Demand 发布的那样,您必须为您的布局使用命名空间。

?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"/>

关于java - R.id 无法解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2483732/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com