java 为什么 ArrayList<>.add() 不起作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29117592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why isn't ArrayList<>.add() working?
提问by TheScrub
I'm new to Java and I'm currently using Android Studio. I just can't understand why .add isn't working. Subject and Assignments are just custom classes. The issue is that the message "Cannot resolve symbol 'add'" pops up and the whole thing fails. I have imported java.util.ArrayList.
我是 Java 新手,目前正在使用 Android Studio。我只是不明白为什么 .add 不起作用。主题和作业只是自定义类。问题是弹出消息“无法解析符号'添加'”并且整个过程失败。我已经导入了 java.util.ArrayList。
ArrayList<Subject> mSubjects = new ArrayList<Subject>();
Subject cheese = new Subject("Cheese",new Assignment[]{new Assignment("Test 1",1.0f,1.0f,1.0f),new Assignment("Test 2",100f,100f,1.0f)},100f,4.0f);
mSubjects.add(cheese);
回答by stinepike
mSubjects.add(cheese);
put this method in your onCreate
method.
将此方法放入您的onCreate
方法中。