gpt4 book ai didi

java - Android Studio : can´t resolve symbol R

转载 作者:行者123 更新时间:2023-12-01 11:05:27 25 4
gpt4 key购买 nike

我知道这个问题已被问过多次,但由于我的上下文,没有任何答案是有用的。问题是,我刚刚打开我的第一个项目(在我的实际计算机中)所有“R”。在mainActivity.java中变成红色。有谁知道这个问题的原因是什么以及如何解决?

这是 .java 主要 Activity

package xyz.elblog.elblog;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.graphics.drawable.Drawable;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
import android.view.View.OnClickListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import android.widget.FrameLayout;
import android.text.Html;
import android.app.Activity;
public class home extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
String readJSON = getJSON("http://blogging.mysite.com.mx/json.php");
try{
JSONObject jsonObject = new JSONObject(readJSON);
String seo = jsonObject.getString("seo");
WebView bprimary = (WebView) findViewById(R.id.bprimary);
bprimary.loadData(seo,"text/html","UTF-8");
} catch(Exception e){e.printStackTrace();}
finally {
System.out.println("Success");
}

}

public String getJSON(String address){
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(address);
try{
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if(statusCode == 200){
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while((line = reader.readLine()) != null){
builder.append(line);
}
} else {
Log.e(home.class.toString(),"Failedet JSON object");
}
}catch(ClientProtocolException e){
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
return builder.toString();
}
}

因此这是 home.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent">

<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/bprimary"></FrameLayout>

</LinearLayout>

我正在尝试使用 json html 并在框架布局上显示

构建.gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 19
buildToolsVersion "23.0.1"

defaultConfig {
applicationId "xyz.elblog.elblog"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
}

最佳答案

该问题是由于您的 xml 文件中存在一些错误而导致的。因此,请检查所有 xml 布局、样式和选择器是否有错误。还要检查可绘制文件的文件名。就像您在可绘制对象中添加一些图片,其名称中包含“-”等符号一样,这是给出名称的不正确方式。因此,找到错误并重建您的项目。这个问题很容易解决。

关于java - Android Studio : can´t resolve symbol R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33007013/

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