我尝试从ss
方法调用方法main
,但会抛出以下异常
Exception in thread "main" java.lang.NullPointerException at teste1.exp.ss(exp.java:16) at teste1.Main.main(Main.java:64) Java Result: 1
public class Main {
public static void main(String[] arguments) {
...................
private static String[] ff;
exp mega = new exp();
mega.ss(ff);
}
class exp {
public void ss (String gvanswer[]){
String answer[] = new String[3];
answer[0] = "pacific ";
answer[1] = "everest";
answer[2] = "amazon ";
if (gvnswer[0].equals("pacific"))
{System.out.println("eeeeeeeeeeeeee ");}
if (gvanswer[1].equals(answer[1])){System.out.println("l ");}
}
答案 0 :(得分:2)
你打电话给mega.ss(ff)
,但gf从未用类似的东西初始化:
ff = new String[1];
ff[0] = "foo";
答案 1 :(得分:0)
您尚未填充要传递到ff
方法的名为ss
的数组。
答案 2 :(得分:0)
您将ss
方法传递给未初始化的String[]
数组(ff
),因此NullPointerException
。