Android Studio错误"无法解析方法的方法.add"

时间:2018-06-03 19:50:48

标签: java arrays android-studio

我知道这个问题很多,但我真的很难过,我看了其他的方法,并尝试了一切...... 我的编码问题如下,我在java中有一个公共类,我在全局范围内创建了一个字符串数组。我尝试使用array.add(" somestringhere")添加到它,但是它吐出一个错误说(标题)......还有一点需要注意的是这个类是在主类中为文件。所以,让我们看看我是否可以在这里展示它:



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) {
        }
    }
&#13;
&#13;
&#13;

我很感激任何帮助,我是编程和android工作室的新手,而且php..so是的,先谢谢,Justin

1 个答案:

答案 0 :(得分:1)

tasks是您定义的String数组

String[] tasks = extras.getStringArray("tasks");

并且Array没有任何add方法。 您需要将tasks转换为如下列表

List<String> list = Arrays.asList(tasks);

然后您可以使用list.add(schedule)