2012-03-11 2 views
0

기존 sqlite db에 연결하고 db의 몇 가지 기본 정보를 표시하는 응용 프로그램을 만들었지 만 에뮬레이터에서 예기치 않게 닫히고 오류의 의미를 모르겠습니다. db는 Information과 android_metadata라는 두 개의 테이블 만 가지고 있습니다.안드로이드 db 오류의

프로젝트 파일에있는 유일한 오류는 AndroidManifest.xml에 있습니다. 그것은 말합니다 : "속성 minSdkVersion (8)이 프로젝트 타겟 API 레벨 (10)보다 낮습니다."다른 SO 게시물은 이것을 무시할 수 있으므로 편집하지 않았습니다. . 로그 캣 추적)

이것은 DB의 '상태'번째 열에으로 목록보기를 채우는 활동 :

import java.io.IOException; 
import java.util.ArrayList; 
import java.util.List; 

import healthy.com.sdp.R; 
import healthy.com.sdp.db.DataBaseHelper; 

import android.app.Activity; 
import android.app.AlertDialog; 
import android.content.Context; 
import android.content.Intent; 
import android.database.Cursor; 
import android.database.SQLException; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.ListView; 

public class StateListActivity extends Activity { 

    private ListView _listView; 
    private List<StateDisease> stateNames = new ArrayList<StateDisease>(); 
    DataBaseHelper myDbHelper; 
    AlertDialog.Builder builder ; 
    AlertDialog alert; 
    Context _context; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.state_list);   

     myDbHelper = new DataBaseHelper(this); 

     _listView = (ListView) findViewById(R.id.listState); 
     _listView.setAdapter(new SingleTextAdapter(getBaseContext(), R.layout.adapter_single_text, stateNames)); 

     _listView.setOnItemClickListener(clickListener); 
     _context = this; 
     try { 

      myDbHelper.createDataBase(); 

     } catch (IOException ioe) { 

      throw new Error("Unable to create database"); 

     } 

     try { 

      myDbHelper.openDataBase(); 
      Cursor cursor = myDbHelper.executeRawQuery("Select * from Information"); 


      if(cursor.moveToFirst()) 
      { 
       while (cursor.isAfterLast() == false) 
       { 
        StateDisease sd = new StateDisease(); 
        sd._stateId = cursor.getInt(cursor.getColumnIndex("_id")); 
        sd._percentHeartDisease = cursor.getDouble(cursor.getColumnIndex("HeartDisease")); 
        sd._percentObesity = cursor.getDouble(cursor.getColumnIndex("Obesity"));      
        sd._stateName = cursor.getString(cursor.getColumnIndex("States"));     
        sd._percentLungDisease = cursor.getDouble(cursor.getColumnIndex("LungDisease")); 

        stateNames.add(sd); 
        cursor.moveToNext(); 
       } 
      } 


      myDbHelper.close(); 

     }catch(SQLException sqle){ 

      throw sqle; 

     } 
    } 

    private OnItemClickListener clickListener = new OnItemClickListener() 
    { 

     @Override 
     public void onItemClick(AdapterView<?> parent, View v, int pos, 
       long id) {  

      Intent intent = new Intent(getBaseContext(), DiseaseSelectionActivity.class); 
      Bundle b = new Bundle(); 
      b.putInt(Constant.STATE_ID, stateNames.get(pos)._stateId); 
      b.putString(Constant.STATE_NAME, stateNames.get(pos)._stateName); 
      intent.putExtras(b); 
      startActivity(intent); 
     } 

    }; 
} 

그리고 이것은 로그 캣 추적입니다 :

03-11 07:14:33.013: I/Database(336): sqlite returned: error code = 1, msg = no such table: Information 
03-11 07:14:33.013: W/System.err(336): android.database.sqlite.SQLiteException: no such table: Information: , while compiling: Select * from Information 
03-11 07:14:33.022: W/System.err(336): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 
03-11 07:14:33.022: W/System.err(336): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92) 
03-11 07:14:33.022: W/System.err(336): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65) 
03-11 07:14:33.022: W/System.err(336): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83) 
03-11 07:14:33.022: W/System.err(336): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49) 
03-11 07:14:33.032: W/System.err(336): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42) 
03-11 07:14:33.032: W/System.err(336): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356) 
03-11 07:14:33.032: W/System.err(336): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1324) 
03-11 07:14:33.032: W/System.err(336): at healthy.com.sdp.db.DataBaseHelper.executeRawQuery(DataBaseHelper.java:149) 
03-11 07:14:33.032: W/System.err(336): at healthy.com.sdp.activity.StateListActivity.onCreate(StateListActivity.java:58) 
03-11 07:14:33.032: W/System.err(336): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
03-11 07:14:33.032: W/System.err(336): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 
03-11 07:14:33.032: W/System.err(336): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 
03-11 07:14:33.032: W/System.err(336): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
03-11 07:14:33.050: W/System.err(336): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 
03-11 07:14:33.050: W/System.err(336): at android.os.Handler.dispatchMessage(Handler.java:99) 
03-11 07:14:33.052: W/System.err(336): at android.os.Looper.loop(Looper.java:123) 
03-11 07:14:33.052: W/System.err(336): at android.app.ActivityThread.main(ActivityThread.java:3683) 
03-11 07:14:33.052: W/System.err(336): at java.lang.reflect.Method.invokeNative(Native Method) 
03-11 07:14:33.052: W/System.err(336): at java.lang.reflect.Method.invoke(Method.java:507) 
03-11 07:14:33.052: W/System.err(336): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
03-11 07:14:33.052: W/System.err(336): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
03-11 07:14:33.052: W/System.err(336): at dalvik.system.NativeStart.main(Native Method) 
03-11 07:14:33.052: D/AndroidRuntime(336): Shutting down VM 
03-11 07:14:33.052: W/dalvikvm(336): threadid=1: thread exiting with uncaught exception (group=0x40015560) 
03-11 07:14:33.072: E/AndroidRuntime(336): FATAL EXCEPTION: main 
03-11 07:14:33.072: E/AndroidRuntime(336): java.lang.RuntimeException: Unable to start activity ComponentInfo{healthy.com.sdp/healthy.com.sdp.activity.StateListActivity}: java.lang.NullPointerException 
03-11 07:14:33.072: E/AndroidRuntime(336): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 
03-11 07:14:33.072: E/AndroidRuntime(336): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 
03-11 07:14:33.072: E/AndroidRuntime(336): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
03-11 07:14:33.072: E/AndroidRuntime(336): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 
03-11 07:14:33.072: E/AndroidRuntime(336): at android.os.Handler.dispatchMessage(Handler.java:99) 
03-11 07:14:33.072: E/AndroidRuntime(336): at android.os.Looper.loop(Looper.java:123) 
03-11 07:14:33.072: E/AndroidRuntime(336): at android.app.ActivityThread.main(ActivityThread.java:3683) 
03-11 07:14:33.072: E/AndroidRuntime(336): at java.lang.reflect.Method.invokeNative(Native Method) 
03-11 07:14:33.072: E/AndroidRuntime(336): at java.lang.reflect.Method.invoke(Method.java:507) 
03-11 07:14:33.072: E/AndroidRuntime(336): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
03-11 07:14:33.072: E/AndroidRuntime(336): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
03-11 07:14:33.072: E/AndroidRuntime(336): at dalvik.system.NativeStart.main(Native Method) 
03-11 07:14:33.072: E/AndroidRuntime(336): Caused by: java.lang.NullPointerException 
03-11 07:14:33.072: E/AndroidRuntime(336): at healthy.com.sdp.activity.StateListActivity.onCreate(StateListActivity.java:61) 
03-11 07:14:33.072: E/AndroidRuntime(336): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
03-11 07:14:33.072: E/AndroidRuntime(336): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 
03-11 07:14:33.072: E/AndroidRuntime(336): ... 11 more 
03-11 07:14:37.442: I/Process(336): Sending signal. PID: 336 SIG: 9 

감사에 대한 어떤 도움. 이 테이블 "정보"가 이전에 생성 된 것은 아니지만

답변

0

당신은 문/쿼리를

Select * from Information 

을 실행하고 있습니다. 이것을 보시려면 link/tutorial 더 나은 방법으로 sqlite db를 사용하는 방법을 알고 계십시오.

관련 문제