public class MainActivity extends AppCompatActivity {
TextView thevalue;
Button getJson;
private static String url = "https://api.xively.com/v2/feeds/1465271593";
JSONArray user = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getJson = (Button) findViewById(R.id.getdata); //**(R.id.getdata is red)**
getJson.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new JSONParse().execute();
}
});
}
private class JSONParse extends AsyncTask<String, String, JSONObject> {
@Override
protected void onPreExecute() {
super.onPreExecute();
thevalue = (TextView)findViewById(R.id.value); **//(R.id.value is red)**
}
@Override
protected JSONObject doInBackground(String... args) {
getJson theParser = new getJson(); //**(It is in red lines)**
JSONObject json = theParser.doIt(url); //**(doIt is red)**
return json;
}
@Override
protected void onPostExecute(JSONObject json) {
try {
user = json.getJSONArray("datastreams");
JSONObject c = user.getJSONObject(0);
String curval = c.getString("current_value");
Log.i("JSONARR", user.toString());
thevalue.setText(curval);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
这是我检索数据的代码,但上面注释的单词是红色或红色。谁知道如何解决这个问题?