-1
java.lang.NullPointerException

它在我的嵌套数组中。基本上我想检索arrayIWantThisCat

[10 {1,2,3,4} , 20 {5,6,7,8}]

String[][] arrayIWantThisCat;
String[] arrayAddendAmounts;

try {
    SQLiteAdapter info = new SQLiteAdapter(this);
    info.open();
    alAddends = info.getFinalCategorysTagAddend();
    info.close();
    //  Array holds all unique Addend amounts
    arrayAddendAmounts = alAddends.toArray(new String[alAddends.size()]);               
 } catch (SQLiteConstraintException e) {
    Log.d("TAG", "failure to get data,", e);
    return;
 }

 int numberOfAddends = arrayAddendAmounts.length;
  for (int i = 0; i < numberOfAddends; i++) {
try {
    SQLiteAdapter info = new SQLiteAdapter(this);
    info.open();
    alWhatCatDoYouWant = info.getFinalCategorysCatIDsBasedOnAddend(arrayAddendAmounts[i]);
    info.close();

         ***//  This is where the issue is ( Nested Array )***
    arrayIWantThisCat[i] = alWhatCatDoYouWant.toArray(new String[alWhatCatDoYouWant.size()]);               
    } catch (SQLiteConstraintException e) {
    Log.d("TAG", "failure to get data,", e);
    return;
    }
}
4

3 回答 3

0

您尚未在代码中进行初始化arrayIWantThisCat,但您在此行中通过索引引用它:

arrayIWantThisCat[i] = alWhatCatDoYouWant.toArray(new String[alWhatCatDoYouWant.size()]);

这很可能会导致您的NullPointerException.

您可能希望使用 1 级大小对其进行初始化,例如:

arrayIWantThisCat = new String[myFirstLevelSize][];

... 在访问它的索引之前i,它可以等于myFirstLevelSize - 1.

于 2013-08-08T18:55:25.013 回答
0

您还没有创建一个数组,而只是一个为空的引用。这导致发生 NullPointerException。

String[][] arrayIWantThisCat;
于 2013-08-08T18:56:01.703 回答
0

String[][] arrayIWantThisCat = new String[0][];

应该修复它,使用 org.apache.commons.ArrayUtils 来调整它的大小或使用 Set/List 代替。

于 2013-08-08T18:58:47.980 回答