我想在字符串数组中保存一些值。我该怎么做?
我的程序是:我想从数据库lalit_db
获取数据并将其放入我的UI中的列表中并对其执行一些操作。
所以为此,我尝试了其他一些代码但当我尝试将字符串保存到edit.putString(rs.getStrnig(3));
时出现错误。
基本上,数据被访问,我也在日志中打印,但它没有被存储
如何以及在哪里可以存储来自我的数据库的一些字符串数据?
我试过了:
try {
st = MainActivity.conn.createStatement();
rs = st.executeQuery("SELECT * FROM lalit_db;");
for(int i=0;rs.next();i++)
{
/////// I have tried this...........
// listOfMenus[i] = rs.getString(3);
edit.putString("Value " +i, rs.getString(3));
Log.w(rs.getString(2), rs.getString(3));
}
while(rs.next()){
Log.w(rs.getString(2), rs.getString(3));
listOfMenus = new String[]{rs.getString(3)};
}
Thread.sleep(5000);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.w("Process completed", "After all thingsss........");
return null;
}
错误是:
01-04 10:57:51.072: D/AndroidRuntime(3490): Shutting down VM
01-04 10:57:51.072: W/dalvikvm(3490): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
01-04 10:57:51.192: E/AndroidRuntime(3490): FATAL EXCEPTION: main
01-04 10:57:51.192: E/AndroidRuntime(3490): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.z/com.example.z.menus}: java.lang.NullPointerException
01-04 10:57:51.192: E/AndroidRuntime(3490): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-04 10:57:51.192: E/AndroidRuntime(3490): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-04 10:57:51.192: E/AndroidRuntime(3490): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-04 10:57:51.192: E/AndroidRuntime(3490): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
请帮我解决这个问题。提前谢谢。