【发布时间】:2017-12-27 12:20:29
【问题描述】:
我想从我的 SQLite 数据库中获取一列并将该信息添加到一个数组中。
我使用from array 和cursor 以及两个java 类。
我的 sqlite 数据库没有问题,因为在另一个页面中我能够获取信息。
我希望看到显示的信息时,我的 Android 应用程序强制关闭。
我的方法(displayrooidad):
public String displayrooidad(int row) {
Cursor cu = db.query(DB_TBL_ROOIDAD, null, null, null, null, null, null, null);
cu.moveToPosition(row);
String content = cu.getString(1);
return content;
}
我的java类 SQLiteHelper:是一个用于连接数据库的 javaclass。 open 和 close 方法工作正常。
public class Rooidad extends AppCompatActivity {
Spinner sp;
TextView txt;
SQLiteHelper sq;
String[] myarray;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rooidad);
// sp=(Spinner)findViewById(R.id.sp);
txt = (TextView)findViewById(R.id.test);
sq=new SQLiteHelper(getBaseContext());
sq.open();
int row =sq.countofrow();
myarray=new String[row];
for(int teller=0;teller<=row;teller++){
String tittle = sq.displayrooidad(teller);
myarray[teller]=tittle.toString();
}
sq.close();
txt.setText(myarray[4].toString());
}
}
【问题讨论】:
-
请发布您的
logcat。 -
我编辑了你的帖子以改进语法,但我不确定两个代码块之间的句子,你能澄清一下吗?
-
@Nathan 谢谢。我改了句
标签: java android arrays sqlite