我正在尝试从数据库中获取一个值并将其添加到一个数组中以在列表视图中显示它。这是我的代码。
当我检查 arg1 时,我得到了值,我不明白我做错了什么。
高分法
list_score=(ListView)findViewById(R.id.score_list);//listview
//get DB
for(int i=0;i<3;i++){
highscoreDB.execSQL("CREATE TABLE IF NOT EXISTS HIGHSCORE"+(i+3)+"(" +
"TIME long(9),MOVE integer(4),GRID integer(2));"
);
Cursor gethighscorealter=highscoreDB.rawQuery("SELECT*FROM HIGHSCORE"+(i+3)+
" ORDER BY TIME asc, MOVE asc ;"
, null);
if(gethighscorealter.getCount()>0){
gethighscorealter.moveToFirst();
timer= gethighscorealter.getLong(gethighscorealter.getColumnIndex("TIME"));
move = gethighscorealter.getInt(gethighscorealter.getColumnIndex("MOVE"));
grid = gethighscorealter.getInt(gethighscorealter.getColumnIndex("GRID"));
arg1[i]=timer;
arg2[i]=move;
arg3[i]=grid;
}else{
arg1[i]=1;
arg2[i]=1;
arg3[i]=i+3;
}
}
list_score.setAdapter(new IntRangeAdapter(this,R.layout.score,arg1, arg2, arg3));
highscoreview();
高分法
AlertDialog.Builder showhighscore =new AlertDialog.Builder(this);
LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.high_score_list, null);//score
showhighscore.setCancelable(false);
showhighscore.setTitle(" ");
showhighscore.setView(layout);
showhighscore.setIcon(R.drawable.menu_icon);
showhighscore.setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.cancel();
onResume();
}
});
showhighscore.show();
IntRangeAdapter 类
public class IntRangeAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private int mItemResource;
private long[] time= new long[10];
private int[] move=new int[10];
private int[] grid=new int[10];
public IntRangeAdapter(Context context, int itemLayout,long[] arg1,int[] arg2,int[] arg3) {
mInflater = LayoutInflater.from(context);
mItemResource = itemLayout;
time=arg1;
move=arg2;
grid=arg3;
}
public int getCount() {
return 4;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(mItemResource, parent, false);
}
TextView tv = (TextView) convertView.findViewById(R.id.textView1);
TextView tv2 = (TextView) convertView.findViewById(R.id.textView2);
TextView tv3 = (TextView) convertView.findViewById(R.id.textView3);
tv.setText(""+time[position]);
tv2.setText(move[position]);
tv3.setText(grid[position]);
return convertView;
}
}
我的原木猫
06-26 00:43:06.639: E/AndroidRuntime(1817): FATAL EXCEPTION: main
06-26 00:43:06.639: E/AndroidRuntime(1817): java.lang.NullPointerException
06-26 00:43:06.639: E/AndroidRuntime(1817): at skripsi.slidame.PuzzleActivity.highscore(PuzzleActivity.java:283)
06-26 00:43:06.639: E/AndroidRuntime(1817): at skripsi.slidame.PuzzleActivity.onOptionsItemSelected(PuzzleActivity.java:147)
PuzzleActivity.java:283
是list_score.setAdapter(new IntRangeAdapter(this,R.layout.score,arg1, arg2, arg3));