Bonjour

Je veux remplir deux textview avec une requete SQLite, je n'ai pas d'erreur sur mon code, mais pas d'affichage j'ai une fermeture de l'appli sur le simulateur

J'ai fait un SqlHelper.java

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
public class SqlHelperInscrit extends SQLiteOpenHelper{
	public static final String DATABASE_PATH = "/data/data/com.wtp.applimultipage/databases/";
	public static final String DATABASE_NAME = "inscriptionsBD";
	public static final String TABLE_NAME = "Inscrits";
	public static final String COLUMN_ID = "_id";
	public static final String COLUMN_NOM = "nom";
	public static final String COLUMN_PRENOM = "prenom";
	public SQLiteDatabase dbSqlite;
	private final Context myContext;
 
	public SqlHelperInscrit(Context context) {
		super(context, DATABASE_NAME, null, 1);
		this.myContext = context;
 
	}
	@Override
	public void onCreate(SQLiteDatabase db) {
		// check if exists and copy database from resource
		createDB();
	}
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w("SqlHelperInscrit", "Upgrading database from version " + oldVersion
				+ " to " + newVersion + ", which will destroy all old data");
		onCreate(db);
	}
	public void createDatabase() {
		createDB();
	}
	private void createDB() {
		boolean dbExist = DBExists();
		if (!dbExist) {
			copyDBFromResource();
		}
	}
	private boolean DBExists() {
		SQLiteDatabase db = null;
		try {
			String databasePath = DATABASE_PATH + DATABASE_NAME;
			db = SQLiteDatabase.openDatabase(databasePath, null,
					SQLiteDatabase.OPEN_READWRITE);
			db.setLocale(Locale.getDefault());
			db.setLockingEnabled(true);
			db.setVersion(1);
		} catch (SQLiteException e) {
			Log.e("SqlHelperInscrit", "database not found");
		}
		if (db != null) {
			db.close();
		}
		return db != null ? true : false;
	}
	private void copyDBFromResource() {
		InputStream inputStream = null;
		OutputStream outStream = null;
		String dbFilePath = DATABASE_PATH + DATABASE_NAME;
		try {
			inputStream = myContext.getAssets().open(DATABASE_NAME);
			outStream = new FileOutputStream(dbFilePath);
			byte[] buffer = new byte[1024];
			int length;
			while ((length = inputStream.read(buffer)) > 0) {
				outStream.write(buffer, 0, length);
			}
			outStream.flush();
			outStream.close();
			inputStream.close();
		} catch (IOException e) {
			throw new Error("Problem copying database from resource file.");
		}
	}
	public void openDataBase() throws SQLException {
		String myPath = DATABASE_PATH + DATABASE_NAME;
		dbSqlite = SQLiteDatabase.openDatabase(myPath, null,
				SQLiteDatabase.OPEN_READWRITE);
	}
	@Override
	public synchronized void close() {
		if (dbSqlite != null)
			dbSqlite.close();
		super.close();
	}
	public Cursor getCursor() {
		SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
		queryBuilder.setTables(TABLE_NAME);
		String[] asColumnsToReturn = new String[] { COLUMN_ID,
				COLUMN_NOM, COLUMN_PRENOM };
		Cursor mCursor = queryBuilder.query(dbSqlite, asColumnsToReturn, null,
				null, null, null, "nom ASC");
		return mCursor;
	}
	public void clearSelections() {
		ContentValues values = new ContentValues();
		values.put(" selected", 0);
		this.dbSqlite.update(SqlHelperInscrit.TABLE_NAME, values, null, null);
	}
}
et ma page d'affichage

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public class page_1_2 extends SimpleCursorAdapter {
	private Context context;
	private Cursor currentCursor;
	public page_1_2(Context context, int layout, Cursor c,
			String[] from, int[] to, SqlHelperInscrit dbHelper) {
		super(context, layout, c, from, to);
		this.currentCursor = c;
		this.context = context;
	}
	public View getView(int pos, View inView, ViewGroup parent) {
		View v = inView;
		if (v == null) {
			LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inflater.inflate(R.layout.page_1_2, null);
		}
		this.currentCursor.moveToPosition(pos);
				TextView voirNom = (TextView) v.findViewById(R.id.lenom);
		voirNom.setText(this.currentCursor.getString(this.currentCursor
				.getColumnIndex(SqlHelperInscrit.COLUMN_NOM)));
				TextView voirPrenom = (TextView) v.findViewById(R.id.leprenom);
		voirPrenom.setText(this.currentCursor.getString(this.currentCursor
				.getColumnIndex(SqlHelperInscrit.COLUMN_PRENOM)));
			return (v);
	}
}
Pouvez-vous m'indiquer s'il y a erreur
Merci
JCM