Android工作室:´t能解决符号R

时间:2022-01-10 20:50:33

I know this question has been asked several times, but no answers are useful due to my context. The thing is, I just opened my first project (in my actual computer) all the "R." in the mainActivity.java turn red. Do anyone know what are the causes for this problem and how it can be fixed?

我知道这个问题已经被问过好几次了,但是由于我的背景,没有答案是有用的。事情是这样的,我刚打开了我的第一个项目(在我的实际电脑中)所有的“r”在主要活动中。java变红了。有人知道这个问题的原因以及它是如何解决的吗?

Here is the .java main activity

这里是.java主要活动。

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

therefore this the home.xml

因此这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>

im trying to get with json html and show on frame layout

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

build.gradle:

build.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'
}

4 个解决方案

#1


1  

The problem due to some error in your xml files. So, check all your xml layouts, styles, and selectors for the error. And also check the drawables file names. Like your add some pics in drawables having names containing symbols like '-' etc which is incorrect way to giving name. So, find the error and rebuild your project. This issues will be solved easily.

这个问题是由于您的xml文件中的一些错误造成的。因此,检查所有xml布局、样式和选择器的错误。还要检查drawables文件名。就像你在drawables中添加一些含有诸如“-”之类的符号的图片,这是不正确的命名方式。因此,找到错误并重新构建项目。这个问题很容易解决。

#2


0  

This error occurs when there is any error in res dir's files. So first try to fix those problems(in layout, drawables, styles, values etc etc). After fixing rebuild your project and the problem will be solved.. Happy Coding

在res dir的文件中出现错误时,会出现此错误。因此,首先尝试解决这些问题(在布局、可绘制、样式、值等方面)。在修复重建项目后,问题将得到解决。快乐的编码

#3


0  

  1. Check if there is no error in XML file, and cross-verify your recent modifications
  2. 检查XML文件中是否没有错误,并交叉验证您最近的修改。
  3. Try "Sync Project With Gradle Files"
  4. 尝试“与Gradle文件同步项目”

This has worked for me

这对我很有效。

#4


0  

try compile HttpClient library in your Gradle files like:-

尝试在您的Gradle文件中编译HttpClient库,比如:-。

compile files('libs/fluent-hc-4.5.jar') compile files('libs/httpclient-4.5.jar') compile files('libs/httpclient-cache-4.5.jar') compile files('libs/httpclient-win-4.5.jar') compile files('libs/httpcore-4.4.1.jar') compile files('libs/httpmime-4.5.jar') compile files('libs/jna-4.1.0.jar') compile files('libs/jna-platform-4.1.0.jar')

编译文件('libs/httpclient-4.5.jar')编译文件('libs/httpclient-win-4.5.jar')编译文件('libs/httpclient-win-4. jar')编译文件('libs/httpmime-4.5.jar')编译文件('libs/httpmime-4.5.jar')编译文件('libs/jna-4.1.0.jar')编译文件('libs/jna-4.1.0.jar')编译文件('libs/jna-4.1.0.jar')

#1


1  

The problem due to some error in your xml files. So, check all your xml layouts, styles, and selectors for the error. And also check the drawables file names. Like your add some pics in drawables having names containing symbols like '-' etc which is incorrect way to giving name. So, find the error and rebuild your project. This issues will be solved easily.

这个问题是由于您的xml文件中的一些错误造成的。因此,检查所有xml布局、样式和选择器的错误。还要检查drawables文件名。就像你在drawables中添加一些含有诸如“-”之类的符号的图片,这是不正确的命名方式。因此,找到错误并重新构建项目。这个问题很容易解决。

#2


0  

This error occurs when there is any error in res dir's files. So first try to fix those problems(in layout, drawables, styles, values etc etc). After fixing rebuild your project and the problem will be solved.. Happy Coding

在res dir的文件中出现错误时,会出现此错误。因此,首先尝试解决这些问题(在布局、可绘制、样式、值等方面)。在修复重建项目后,问题将得到解决。快乐的编码

#3


0  

  1. Check if there is no error in XML file, and cross-verify your recent modifications
  2. 检查XML文件中是否没有错误,并交叉验证您最近的修改。
  3. Try "Sync Project With Gradle Files"
  4. 尝试“与Gradle文件同步项目”

This has worked for me

这对我很有效。

#4


0  

try compile HttpClient library in your Gradle files like:-

尝试在您的Gradle文件中编译HttpClient库,比如:-。

compile files('libs/fluent-hc-4.5.jar') compile files('libs/httpclient-4.5.jar') compile files('libs/httpclient-cache-4.5.jar') compile files('libs/httpclient-win-4.5.jar') compile files('libs/httpcore-4.4.1.jar') compile files('libs/httpmime-4.5.jar') compile files('libs/jna-4.1.0.jar') compile files('libs/jna-platform-4.1.0.jar')

编译文件('libs/httpclient-4.5.jar')编译文件('libs/httpclient-win-4.5.jar')编译文件('libs/httpclient-win-4. jar')编译文件('libs/httpmime-4.5.jar')编译文件('libs/httpmime-4.5.jar')编译文件('libs/jna-4.1.0.jar')编译文件('libs/jna-4.1.0.jar')编译文件('libs/jna-4.1.0.jar')