3
ListViewのデータベースエントリのリストを表示するアンドロイドアプリケーションをビルドする必要があります。ORM Lite with ListView and Mysqlバックエンド(アンドロイド)
Iはthis threadに出会ったとしようとした次の
CloseableIterator<Parlor> iterator = new ParlorAsync().execute().get();
AndroidDatabaseResults adr = (AndroidDatabaseResults) iterator.getRawResults();
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.list_view_template,
adr.getRawCursor(),
new String[]{""},
new int[]{R.id.parlor_name});
parlor_list.setAdapter(adapter);
パーラーエンティティとParlorAsync MySQLデータベースへの接続を処理し、データベース内のすべての行を返すAsyncTaskある
:
JdbcConnectionSource source = new JdbcConnectionSource("jdbc:mysql://192.168.1.1:3306/mydatabase");
source.setUsername("user");
source.setPassword("password");
Dao<Parlor, Integer> parlorDao = DaoManager.createDao(source, Parlor.class);
QueryBuilder<Parlor, Integer> queryBuilder = parlorDao.queryBuilder();
queryBuilder.selectColumns("name");
queryBuilder.orderBy("name", true);
return parlorDao.iterator(queryBuilder.prepare());
ご覧のとおり、JdbcConnectionSourceを使用しましたが、これが問題の開始場所です。今ではこれが、これらは私が間違って何をやっている私のGradleの依存関係
compile group: 'com.j256.ormlite', name: 'ormlite-core', version: '4.48'
compile group: 'com.j256.ormlite', name: 'ormlite-jdbc', version: '4.48'
compile group: 'com.j256.ormlite', name: 'ormlite-android', version: '4.48'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.6'
あるlist_view_template.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".ParlorListView">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/parlor_name" android:layout_alignParentTop="true" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
である私に
com.j256.ormlite.jdbc.JdbcDatabaseResults cannot be cast to com.j256.ormlite.android.AndroidDatabaseResults
を告げますか?
敬具
どうすればいいですか?私は外部のmysqlデータベース(ローカルではない)を取得し、JdbcConnectionSourceを使用して読み書きすることができましたが、このJdbcConnectionSourceからCursorを取得する必要があります... – LimitX
jdbcクエリを 'CursorProvider'でラップする必要があります – barmaley