首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android Studio错误“无法解析方法.add的方法”

Android Studio错误“无法解析方法.add的方法”
EN

Stack Overflow用户
提问于 2018-06-04 03:50:48
回答 1查看 993关注 0票数 1

我知道这个问题被问了很多,但我真的被难住了,我已经寻找了其他方法,并尝试了所有方法……我的编码问题如下,我在java中有一个公共类,并且我在全局作用域中创建了一个字符串数组。我试着用array.add(“这里的某个字符串”)添加它,但它显示了一个错误,说(标题)...还有一件事需要注意的是,这个类位于文件的主类中。所以让我们看看我是否可以在这里展示它:

代码语言:javascript
运行
复制
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是的,提前谢谢你,贾斯汀

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50670409

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档