次の 2 つの方法を使用してプログラムを実行すると、nullpointerexception が発生します。
public static String getType(int x)
{
Contact_Type Type;
String strType = "";
Type = AddyBook.get(x).getContactType();
strType = Type.toString ( );
return strType;
}
public static String displayByType(String type)
{
int i = 0;
String strTypeList = "";
if(type.equals(null))
strTypeList = "What?What?What?LOLOLOLOLOLnopechucktesta";
while(i < AddyBook.size())
{
if(getType(i).equalsIgnoreCase(type))
{
strTypeList += getType(i);
strTypeList += "\n";
}
i++;
}
return strTypeList;
}
私が指摘されている行は
strType = Type.toString ( );
と
if(getType(i).equalsIgnoreCase(type))
また、操作対象の変数を除いて同一の他のメソッドでも例外が発生します。
私の問題は、ドライバークラスで「getType」メソッドを直接テストしたところ、正しく機能したことです。次に、「displayByType」メソッドで、「Type が null の場合はこれを行う」とさえ言いますが、それでも例外がスローされます。理由はわかりませんが、おそらく非常に単純で明白だと思います。あまりにも長い間これに取り組んできたので、今は見ることができません。:/
編集 1: Type = AddyBook.get(x) の内容はオブジェクトであり、.getContactType() の結果は列挙型です。