gpt4 book ai didi

java - 添加到数组时强制关闭

转载 作者:行者123 更新时间:2023-11-29 19:11:15 24 4
gpt4 key购买 nike

我想从我的 SQLite 数据库中获取一列并将该信息添加到一个数组中。我使用 from arraycursor 以及两个 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。打开和关闭方法正常工作。

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());
}
}

最佳答案

我认为你需要输入 teller < row因为你的tab只有row元素不row+1 .

关于java - 添加到数组时强制关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45237808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com