有人可以回答为什么我的数组列表有问题.我有一个类:List,People和Main(用来运行所有程序).
在List我创建一个新ArrayList的类型的对象People.
在Main我创建新的List对象,然后创建新的People对象,然后从List对象add方法调用,此时我得到一个nullPointerException异常.
public class Main {
public static void main(String[] args) {
List l = new List(); // making new List object
People p = new People(); // making new People object
l.addPeople(p); // calling from List object "addPeople" method and
}
// parsing People object "p"
}
import java.util.ArrayList;
public class List {
public List(){ //constructor
}
ArrayList<People>list; // new …Run Code Online (Sandbox Code Playgroud) 在C中,这是合法的,并将编译:
char names[5] = "Hello";
Run Code Online (Sandbox Code Playgroud)
但这个不是:
char names[5];
names = "Hello";
Run Code Online (Sandbox Code Playgroud)
如何将赋值放在字符数组"Hello"中?我可以不这样做strcpy吗?