【问题标题】:force close while adding to array添加到数组时强制关闭
【发布时间】:2017-12-27 12:20:29
【问题描述】:

我想从我的 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。 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


【解决方案1】:

我认为您需要输入teller &lt; row,因为您的tab 只有row 元素而不是row+1

【讨论】:

  • 非常感谢。已修复我删除了“=”
  • @M.borjian 如果解决了你的问题,你可以接受答案:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-01
  • 2015-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多