我知道这个问题被问了很多,但我真的被难住了,我已经寻找了其他方法,并尝试了所有方法……我的编码问题如下,我在java中有一个公共类,并且我在全局作用域中创建了一个字符串数组。我试着用array.add(“这里的某个字符串”)添加它,但它显示了一个错误,说(标题)...还有一件事需要注意的是,这个类位于文件的主类中。所以让我们看看我是否可以在这里展示它:
public class see_schedule_activity extends AppCompatActivity {
.
..
.
.
.
// you can make this class as another java file so it will be separated from your main activity.
public class AsyncTaskParseJson extends AsyncTask<String, String, String> {
final String TAG = "AsyncTaskParseJson.java";
// set your json string url here
String yourJsonStringUrl = "http://www.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxphp";
// contacts JSONArray
JSONArray dataJsonArr = null;
@Override
protected void onPreExecute() {
}
@Override
protected String doInBackground(String... arg0) {
try {
// I have a intent passed from teh main class
Bundle extras = getIntent().getExtras();
String[] tasks = extras.getStringArray("tasks");
// instantiate our json parser
JsonParser jParser = new JsonParser();
// get json string from url
JSONObject json = jParser.getJSONFromUrl(yourJsonStringUrl);
// get the array of users
dataJsonArr = json.getJSONArray("schedule");
// loop through all users
for (int i = 0; i < dataJsonArr.length(); i++) {
JSONObject c = dataJsonArr.getJSONObject(i);
// Storing each json item in variable
activityid = c.getString("activityid");
String yesno = c.getString("yesno");
String start = c.getString("start");
String stop = c.getString("stop");
String plusminus = c.getString("plusminus");
Log.e("Hash Map", "Routine ID #" + activityid);
if (!TextUtils.isEmpty(activityid) && TextUtils.isDigitsOnly(activityid)) {
routine = hm.get(Integer.valueOf(activityid));
} else {
routine = "";
}
// TODO: Make the PHP work with a variable residentID
//TODO: only make a string if the yes is checked
//TODO: make the routine name
// Log.e(TAG, "Value for yesno:" + yesno);
if (c.getString("yesno").equals("Yes")) {
schedule = routine + " starts at " + start + " and ends at " + stop + " with plusorminus " +
plusminus + " minutes ";
tasks.add(schedule);// This lines yeilds the problem
Log.e(TAG, "" + schedule);
}
// // show the values in our logcat
// Log.e(TAG, "activityid: " + activityid
// + ", yesno: " + yesno
// + ", start: " + start
// + ", stop: " + stop
// + ", plusminus: " + plusminus);
}
Intent intent = new Intent(getApplicationContext(),see_schedule_activity.class);
intent.putExtra("tasks_filled",tasks);
startActivity(intent);
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String strFromDoInBg) {
}
}
我非常感谢任何帮助,我是编程和安卓工作室的新手,php..so是的,提前谢谢你,贾斯汀
https://stackoverflow.com/questions/50670409
复制相似问题