I Am having complicated problem.. So i want tokenizing string article that each article saved on my database sqlite. i am using cursor to retrieve data from database, and i convert to arrayList named sejarahList. so sejarahList contain article each list.
When i use StringTokenizer or split to tokenize sejarahList, always getting error and android app force close. i search resemble problem, but it can't solve.. when i print sejarahList, sejarahList is not null..
Here's my code:
public void tokenizing() {
String sql = "SELECT sejarah FROM data_sejarah";
Cursor c = myDbHelper.rawQuery(sql, null);
ArrayList<String> sejarahList = new ArrayList<String>();
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
sejarahList.add(c.getString(c.getColumnIndex("sejarah")));
}
ArrayList<String> sejarahToken = new ArrayList<String>();
for (String s : sejarahList) {
StringTokenizer st = new StringTokenizer(s);
while (st.hasMoreTokens()) {
sejarahToken.add(st.nextToken());
txtString.append(st+"\n");
}
}
}
Here's my logcat:
03-28 14:52:55.892: E/AndroidRuntime(4838): FATAL EXCEPTION: main
03-28 14:52:55.892: E/AndroidRuntime(4838): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ta.historyinv/com.ta.historyinv.MainTM}: java.lang.NullPointerException
03-28 14:52:55.892: E/AndroidRuntime(4838): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
03-28 14:52:55.892: E/AndroidRuntime(4838): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2146)
03-28 14:52:55.892: E/AndroidRuntime(4838): at android.app.ActivityThread.access$700(ActivityThread.java:140)
03-28 14:52:55.892: E/AndroidRuntime(4838): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
03-28 14:52:55.892: E/AndroidRuntime(4838): at android.os.Handler.dispatchMessage(Handler.java:99)
03-28 14:52:55.892: E/AndroidRuntime(4838): at android.os.Looper.loop(Looper.java:137)
03-28 14:52:55.892: E/AndroidRuntime(4838): at android.app.ActivityThread.main(ActivityThread.java:4944)
03-28 14:52:55.892: E/AndroidRuntime(4838): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 14:52:55.892: E/AndroidRuntime(4838): at java.lang.reflect.Method.invoke(Method.java:511)
03-28 14:52:55.892: E/AndroidRuntime(4838): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
03-28 14:52:55.892: E/AndroidRuntime(4838): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
03-28 14:52:55.892: E/AndroidRuntime(4838): at dalvik.system.NativeStart.main(Native Method)
03-28 14:52:55.892: E/AndroidRuntime(4838): Caused by: java.lang.NullPointerException
03-28 14:52:55.892: E/AndroidRuntime(4838): at java.util.StringTokenizer.<init>(StringTokenizer.java:100)
03-28 14:52:55.892: E/AndroidRuntime(4838): at java.util.StringTokenizer.<init>(StringTokenizer.java:59)
03-28 14:52:55.892: E/AndroidRuntime(4838): at com.ta.historyinv.MainTM.tokenizing(MainTM.java:60)
03-28 14:52:55.892: E/AndroidRuntime(4838): at com.ta.historyinv.MainTM.onCreate(MainTM.java:24)
03-28 14:52:55.892: E/AndroidRuntime(4838): at android.app.Activity.performCreate(Activity.java:5188)
03-28 14:52:55.892: E/AndroidRuntime(4838): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
03-28 14:52:55.892: E/AndroidRuntime(4838): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2085)
03-28 14:52:55.892: E/AndroidRuntime(4838): ... 11 more
Aucun commentaire:
Enregistrer un commentaire