カーソルから2次元文字列配列を埋める
-
12-11-2019 - |
質問
私はデータベースをAndroid ExpendableListにロードしようとしている問題があります。何らかの理由で私が得るのはカテゴリですが、カテゴリの実際のリストではありません、私は間違っていますか?
public static String[][] sortSpellNames(){
int groupnmbr = 0;
int childnmbr = 0;
String[] aGroups = {"Combat", "Detection", "Health", "Illusion", "Manipulation"};
String[] Combat = new String[grabList("SHADOWRUNSPELLS",new String[]{"Name"}, "'Category' like 'Combat'").getCount()],
Detection = new String[grabList("SHADOWRUNSPELLS",new String[]{"Name"}, "'Category' like 'Detection'").getCount()],
Health = new String[grabList("SHADOWRUNSPELLS",new String[]{"Name"}, "'Category' like 'Health'").getCount()],
Illusion = new String[grabList("SHADOWRUNSPELLS",new String[]{"Name"}, "'Category' like 'Illusion'").getCount()],
Manipulation = new String[grabList("SHADOWRUNSPELLS",new String[]{"Name"}, "'Category' like 'Manipulation'").getCount()];
Cursor cursor;
while(groupnmbr < aGroups.length){
childnmbr = 0;
cursor = grabList("SHADOWRUNSPELLS",new String[]{"Name"}, "'Category' like '" + aGroups[groupnmbr] + "'");
cursor.moveToFirst();
while(cursor.moveToNext()){
switch(groupnmbr){
case 0: Combat[childnmbr] = cursor.getString(cursor.getColumnIndex("Name"));
break;
case 1: Detection[childnmbr] = cursor.getString(cursor.getColumnIndex("Name"));
break;
case 2: Health[childnmbr] = cursor.getString(cursor.getColumnIndex("Name"));
break;
case 3: Illusion[childnmbr] = cursor.getString(cursor.getColumnIndex("Name"));
break;
case 4: Manipulation[childnmbr] = cursor.getString(cursor.getColumnIndex("Name"));
break;
}
childnmbr++;
}
groupnmbr++;
}
String[][] aChildren = {Combat, Detection, Health, Illusion, Manipulation};
return aChildren;
}
. 解決
私は問題を解決しました。最初に検索は検索が '"の代わりに検索を囲む必要があります。それから私はを変更して解決されたNULLポインタ例外に遭遇しました
String[] Combat = new String[grabList("SHADOWRUNSPELLS",new String[]{"Name"}, "'Category' like 'Combat'").getCount()]
.
String[] Combat = new String[grabList("SHADOWRUNSPELLS",new String[]{"Name"}, "'Category' like 'Combat'").getCount() - 1]
.
と各文字列[]に対して繰り返します。うまくいけば、これは他の誰かにも同様の問題に遭遇するのに役立ちます。
所属していません StackOverflow