我知道这个问题已被多次询问,但由于我的背景,没有答案是有用的。问题是,我刚打开了我的第一个项目(在我的实际计算机中)所有的“R”。在mainActivity.java中变成红色。有谁知道这个问题的原因是什么以及如何修复它?
这是.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();
}
}
因此这是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并在框架布局上显示
的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'
}
答案 0 :(得分:1)
由于xml文件中的某些错误导致的问题。因此,请检查错误的所有xml布局,样式和选择器。并检查drawables文件名。就像你在drawables中添加一些图片一样,这些图片的名称包含像&#39; - &#39;这是给出名字的不正确方法。因此,找到错误并重建您的项目。这个问题很容易解决。
答案 1 :(得分:0)
当res dir的文件出现任何错误时,会发生此错误。所以首先尝试解决这些问题(布局,绘图,样式,值等)。 修复重建项目后,问题就解决了.. 快乐编码
答案 2 :(得分:0)
这对我有用
答案 3 :(得分:0)
尝试在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')