Bonjour
J'ai essayé de mettre ne oeuvre ce tutoriel qui met en pratique une application android/Sqllite
je me heurt à les exceptions, les suivantes:
et dans l'émulateur j'ai le message suivant:10-11 08:35:57.262: DEBUG/dalvikvm(61): GC_FOR_MALLOC freed 11422 objects / 637808 bytes in 156ms
10-11 08:35:57.293: INFO/ActivityManager(61): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.test/.test }
10-11 08:35:57.603: INFO/ActivityManager(61): Start proc com.test for activity com.test/.test: pid=561 uid=10032 gids={1015}
10-11 08:35:58.472: INFO/ActivityManager(61): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.test/.test }
10-11 08:35:59.203: DEBUG/AndroidRuntime(561): Shutting down VM
10-11 08:35:59.203: WARN/dalvikvm(561): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): FATAL EXCEPTION: main
10-11 08:35:59.244: ERROR/AndroidRuntime(561): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.test/com.test.test}: java.lang.ClassNotFoundException: com.test.test in loader dalvik.system.PathClassLoader[/data/app/com.test-1.apk]
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at android.os.Handler.dispatchMessage(Handler.java:99)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at android.os.Looper.loop(Looper.java:123)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at android.app.ActivityThread.main(ActivityThread.java:4627)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at java.lang.reflect.Method.invokeNative(Native Method)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at java.lang.reflect.Method.invoke(Method.java:521)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at dalvik.system.NativeStart.main(Native Method)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): Caused by: java.lang.ClassNotFoundException: com.test.test in loader dalvik.system.PathClassLoader[/data/app/com.test-1.apk]
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
10-11 08:35:59.244: ERROR/AndroidRuntime(561): ... 11 more
10-11 08:35:59.273: WARN/ActivityManager(61): Force finishing activity com.test/.test
10-11 08:36:00.083: WARN/ActivityManager(61): Activity pause timeout for HistoryRecord{43fcfc10 com.test/.test}
10-11 08:36:10.885: WARN/ActivityManager(61): Activity destroy timeout for HistoryRecord{43fcfc10 com.test/.test}
android application using sqlite has stopped...
Structure
SQLiteCountryAssistant.java
UsingSQLite.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
98
99
100
101
102
103
104 package com.test; import android.database.*; import android.database.sqlite.*; import android.content.ContentValues; import android.content.Context; import android.util.Log; public class SQLiteCountryAssistant extends SQLiteOpenHelper { private static final String DB_NAME = "usingsqlite.db"; private static final int DB_VERSION_NUMBER = 1; private static final String DB_TABLE_NAME = "countries"; private static final String DB_COLUMN_1_NAME = "country_name"; private static final String DB_CREATE_SCRIPT = "create table " + DB_TABLE_NAME + " (_id integer primary key autoincrement, country_name text not null);)"; private SQLiteDatabase sqliteDBInstance = null; public SQLiteCountryAssistant(Context context) { super(context, DB_NAME, null, DB_VERSION_NUMBER); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO: Implement onUpgrade } @Override public void onCreate(SQLiteDatabase sqliteDBInstance) { Log.i("onCreate", "Creating the database..."); sqliteDBInstance.execSQL(DB_CREATE_SCRIPT); } public void openDB() throws SQLException { Log.i("openDB", "Checking sqliteDBInstance..."); if(this.sqliteDBInstance == null) { Log.i("openDB", "Creating sqliteDBInstance..."); this.sqliteDBInstance = this.getWritableDatabase(); } } public void closeDB() { if(this.sqliteDBInstance != null) { if(this.sqliteDBInstance.isOpen()) this.sqliteDBInstance.close(); } } public long insertCountry(String countryName) { ContentValues contentValues = new ContentValues(); contentValues.put(DB_COLUMN_1_NAME, countryName); Log.i(this.toString() + " - insertCountry", "Inserting: " + countryName); return this.sqliteDBInstance.insert(DB_TABLE_NAME, null, contentValues); } public boolean removeCountry(String countryName) { int result = this.sqliteDBInstance.delete(DB_TABLE_NAME, "country_name='" + countryName + "'", null); if(result > 0) return true; else return false; } public long updateCountry(String oldCountryName, String newCountryName) { ContentValues contentValues = new ContentValues(); contentValues.put(DB_COLUMN_1_NAME, newCountryName); return this.sqliteDBInstance.update(DB_TABLE_NAME, contentValues, "country_name='" + oldCountryName + "'", null); } public String[] getAllCountries() { Cursor cursor = this.sqliteDBInstance.query(DB_TABLE_NAME, new String[] {DB_COLUMN_1_NAME}, null, null, null, null, null); if(cursor.getCount() >0) { String[] str = new String[cursor.getCount()]; int i = 0; while (cursor.moveToNext()) { str[i] = cursor.getString(cursor.getColumnIndex(DB_COLUMN_1_NAME)); i++; } return str; } else { return new String[] {}; } } }
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 package com.test; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; public class UsingSQLite extends Activity { private SQLiteCountryAssistant sqlliteCountryAssistant; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocompleteCountry); sqlliteCountryAssistant = new SQLiteCountryAssistant(UsingSQLite.this); sqlliteCountryAssistant.openDB(); // Insert a few countries that begin with "C" sqlliteCountryAssistant.insertCountry("Cambodia"); sqlliteCountryAssistant.insertCountry("Cameroon"); sqlliteCountryAssistant.insertCountry("Canada"); sqlliteCountryAssistant.insertCountry("Cape Verde"); sqlliteCountryAssistant.insertCountry("Cayman Islands"); sqlliteCountryAssistant.insertCountry("Chad"); sqlliteCountryAssistant.insertCountry("Chile"); sqlliteCountryAssistant.insertCountry("China"); //sqlliteCountryAssistant.removeCountry("Chad"); //sqlliteCountryAssistant.updateCountry("Canada", "Costa Rica"); String[] countries = sqlliteCountryAssistant.getAllCountries(); // Print out the values to the log for(int i = 0; i < countries.length; i++) { Log.i(this.toString(), countries[i]); } ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, countries); textView.setAdapter(adapter); } public void onDestroy() { super.onDestroy(); sqlliteCountryAssistant.close(); } }
Merci d'avance
Partager