私はthis tutroial about using your own SQLite databaseをフォローしていました。AndroidでSQLiteからデータを取得する際の問題
- 私のデータベース
- の準備私のプロジェクトのパッケージに同じEXACT
DataBaseHelper
クラスのコピー:私は、チュートリアルで説明したようにこれらのステップを行いました。クラスコードthere DataBaseHelper
クラスには、fetchData
のメソッドを追加したばかりです。 、その後public Cursor fetchData(String table) { String[] selectionArgs = new String[] {"*"}; return myDataBase.query(table, null, null, selectionArgs, null, null, null); }
私はこれやった私の活動のクラスのいずれかに:それは単に与えられた名前でテーブル全体をフェッチしている
DataBaseHelper myDbHelper; myDbHelper = new DataBaseHelper(this); try { myDbHelper.createDataBase(); } catch (IOException ioe) { throw new Error("Unable to create database"); } try { myDbHelper.openDataBase(); } catch (SQLException sqle) { throw sqle; } TextView txt = (TextView) findViewById(R.id.txt); try { //I will use my method to fetch a table named: myTable Cursor c = myDbHelper.fetchData("myTable"); if((Object)c.getCount() != null) txt.setText(c.getCount()); else txt.setText("null"); } catch(Exception e) { txt.setText("error"); }
をしかし、私は「エラーを取得しておきます'をTextViewに追加します。私の方法で問題はありますか?
これは私の最初の試行でしたが、うまくいきませんでした。私は代わりにこれを試して、同じ得た。お試しいただきありがとうございます。 – iTurki
あなたのアプリケーションは 'catch'部分に行くので、あなたがどんな例外を取得しているのかチェックしてください。 –
私はそれを理解しました:)私の答えを参照 – iTurki