DbT.java에서 list.class로 화면 전환후..
쿼리를 날리면 에러가 나네요 ㅡㅡ;;
======================================================
public class DbT extends Activity
implements View.OnClickListener {
private Button b1, b2, b3, b4, b5, b6;
private EditText et1, et2, et3;
private SQLiteDatabase db;
private static final String DBNAME="comdb1.db"; //DB이름
private static final String TNAME ="address1";//테이블 이름
private ContentValues row;
private Cursor cursor;
static String temp;
private Intent i;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
i = new Intent(this, list.class);
startActivity(i);//list.class로 화면 전환후..
=================================================
private void selectData2(){
String sql = "select name,addr,ddate from address1 order by name;";
showMsg("들어온다.", 0);
try{
cursor2 = db1.rawQuery(sql, null);//<------여기서 에러가 납니다.
/*String Result = "";
while (cursor.moveToNext()) {
String name = cursor.getString(0);//name
String addr = cursor.getString(1);//addr
String ddate = cursor.getString(2);//ddate
Result += (name + " = " + addr + "," + ddate + "\n");
temp = name;
showMsg(Result, 0);
}
cursor.close();*/
//showMsg(TNAME+" 데이터 입력 완료", 0);
}catch(SQLiteException se){
showMsg(TNAME+" 목록열기 실패", 0);
}
}
=====================================================
03-22 02:49:25.238: ERROR/AndroidRuntime(4144): Uncaught handler: thread main exiting due to uncaught exception
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): java.lang.RuntimeException: Unable to start activity ComponentInfo{soo.db.test/soo.db.test.list}: java.lang.NullPointerException
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): at android.os.Handler.dispatchMessage(Handler.java:99)
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): at android.os.Looper.loop(Looper.java:123)
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): at android.app.ActivityThread.main(ActivityThread.java:4363)
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): at java.lang.reflect.Method.invokeNative(Native Method)
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): at java.lang.reflect.Method.invoke(Method.java:521)
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): at dalvik.system.NativeStart.main(Native Method)
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): Caused by: java.lang.NullPointerException
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): at soo.db.test.list.selectData2(list.java:79)
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): at soo.db.test.list.onCreate(list.java:46)
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
03-22 02:49:25.258: ERROR/AndroidRuntime(4144): ... 11 more
DbT에서는 같은 함수로 하면
private void selectData(){
String sql = "select name,addr,ddate from address1 order by name;";
showMsg("들어온다.", 0);
try{
cursor = db.rawQuery(sql, null);
String Result = "";
while (cursor.moveToNext()) {
String name = cursor.getString(0);//name
String addr = cursor.getString(1);//addr
String ddate = cursor.getString(2);//ddate
Result += (name + " = " + addr + "," + ddate + "\n");
temp = name;
showMsg(Result, 0);
}
cursor.close();
//showMsg(TNAME+" 데이터 입력 완료", 0);
}catch(SQLiteException se){
showMsg(TNAME+" 목록열기 실패", 0);
}
--------------------------------------------------
잘 나오는데
i = new Intent(this, list.class);로 해서 하면 에러가 나요 AndroidManifest.xml설정도 해줬는데요
======================
<activity android:name=".list"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.EDIT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
}
메니피스트에 등록하는 것은 broadcast receiver, activity, service, content provider 이런것들만 등록이 되는걸로 아는데요.
그리고
list.java에서 ListView를 써서 목록을 보여줄려고 합니다.
Intent로
i = new Intent(this, list.class);
startActivity(i);
이렇게 해서 목록(list.class)로 이동할려고 하는데요..
제가 초보라서...이렇게 하는게 맞는지 모르겠습니다.
중요한건 같은 selectData()를 DbT.java에서 하면 되고,
list.java에서 하면 왜 안되는거죠?
분명 쿼리나 문법은 이상이 없는거 같은데..



