android和sqlite有困难

时间:2013-06-15 19:47:25

标签: android sqlite

我是android和Sq-lite的新手,我似乎无法让这个数据库类工作。在主屏幕上选择一个国家,然后移动到数据屏幕并显示相应国家/地区的数据,但我无法看到加载数据库,它会在logCat中产生以下错误,如果您需要更多详细信息,请告诉我,任何帮助都会很棒:

06-12 19:44:59.893: E/Trace(1215): error opening trace file: No such file or directory (2)
06-12 19:45:00.923: I/Choreographer(1215): Skipped 58 frames!  The application may be doing too much work on its main thread.
06-12 19:45:01.003: D/gralloc_goldfish(1215): Emulator without GPU emulation det`enter code here`ected.
06-12 19:45:03.803: D/AndroidRuntime(1215): Shutting down VM
06-12 19:45:03.803: W/dalvikvm(1215): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-12 19:45:03.843: E/AndroidRuntime(1215): FATAL EXCEPTION: main
06-12 19:45:03.843: E/AndroidRuntime(1215): java.lang.IllegalStateException: getDatabase called recursively
06-12 19:45:03.843: E/AndroidRuntime(1215):     at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:204)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at com.Jamie.dosanddonts.DosAndDontsDbAdapter.populateTable(DosAndDontsDbAdapter.java:43)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at com.Jamie.dosanddonts.DosAndDontsDbAdapter.onCreate(DosAndDontsDbAdapter.java:37)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at com.Jamie.dosanddonts.DosAndDontsDbAdapter.findCountry(DosAndDontsDbAdapter.java:341)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at com.Jamie.dosanddonts.HomeScreen$1.onClick(HomeScreen.java:38)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at android.view.View.performClick(View.java:4204)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at android.view.View$PerformClick.run(View.java:17355)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at android.os.Handler.handleCallback(Handler.java:725)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at android.os.Looper.loop(Looper.java:137)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at android.app.ActivityThread.main(ActivityThread.java:5041)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at java.lang.reflect.Method.invokeNative(Native Method)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at java.lang.reflect.Method.invoke(Method.java:511)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-12 19:45:03.843: E/AndroidRuntime(1215):     at dalvik.system.NativeStart.main(Native Method)

这是我的班级:

package com.Jamie.dosanddonts;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.TextView;

public class DosAndDontsDbAdapter extends SQLiteOpenHelper  {


    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_TABLE = "dosAndDonts";
    private static final String COUNTRY = "Country name";
    private static final String INDICATOR = "Indicator";
    private static final String DESCRIPTION = "Description";
    private TextView temp;
    private Country currentCountry; 

    public DosAndDontsDbAdapter(Context context) {
          super(context, DATABASE_TABLE, null,DATABASE_VERSION); 
          }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub

        String CREATE_TABLE = "CREATE TABLE " + DATABASE_TABLE + "("
                + COUNTRY + " TEXT," + INDICATOR + " TEXT,"
                + DESCRIPTION + " TEXT" + ")"; 

        db.execSQL(CREATE_TABLE);
        populateTable();
    }

        public void populateTable()
        {

        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues cv = new ContentValues();
        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Shake hands when you greet someone.");
        db.insert(DATABASE_TABLE, null, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Do say 'bonjour' or 'bonsoir'.");
        db.insert(DATABASE_TABLE, null, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Flowers should be given in odd numbers but not 13.");
        db.insert(DATABASE_TABLE, null, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Always smile");
        db.insert(DATABASE_TABLE, null, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Always arrive on time for dinner.");
        db.insert(DATABASE_TABLE, null, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "When eating Do not rest your elbows on the table.");
        db.insert(DATABASE_TABLE, null, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Don't refer to someone by their first name unless you are a close friend.");
        db.insert(DATABASE_TABLE, null, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Never offer cheap wine.");
        db.insert(DATABASE_TABLE, null, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not begin eating until the hostess says 'bon appetit' ");
        db.insert(DATABASE_TABLE, null, cv);

        cv.clear();

        cv.put(COUNTRY, "France");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not cut salad with a knife and fork. Fold the lettuce on to your fork. ");
        db.insert(DATABASE_TABLE, null, cv);

        cv.clear();


        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Shake hands when greeting and leaving someone.");
        db.insert(DATABASE_TABLE, null, cv);

        cv.clear();

        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "When you have finished eating lay your knide and fork parallel across your plate.");
        db.insert(DATABASE_TABLE, null, cv);

        cv.clear();

        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "When in a pub pay for a round of drinks for everyone in your group.");
        db.insert(DATABASE_TABLE, null, cv);

        cv.clear();

        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "When eating The fork is held tines down so food is scooped on to the back of the fork.");
        db.insert(DATABASE_TABLE, null, cv);

        cv.clear();

        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "When eating, Table manners are Continental.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Never get in their personal space.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "It's inapropriate to ask personal questions.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "They'll become unconfortalbe if engage in prolonged eye contact.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "When eating don't rest your elbows on the table.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "United_Kingdom");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "DON'T make the V for victory sign with your palm facing yourself.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();


        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "When greeting The usual handshake with direct eye contact.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Have calling card made.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "If you bring wine, make sure it is a good vintage.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "If you are invited to a meal, bring gift-wrapped such as wine or chocolates. ");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Table manners are Continental.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Never give your business card in lieu of a calling card in a social situation.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not give chrysanthemums as they are used at funerals.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not keep your hands in your lap during the meal.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not give red flowers as they indicate secrecy. ");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Italy");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not give yellow flowers as they indicate jealousy.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();

        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "A quick, firm handshake is the traditional greeting.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Titles are very important and denote respect.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "When entering a room, shake hands with everyone individually.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Yellow roses or tea roses are always well received. ");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "If you bring wine, it should be imported.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not give lilies or chrysanthemums as they are used at funerals. ");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Never arrive early, aslways on time.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not begin eating until the hostess starts.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not rest your elbows on the table.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Germany");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not cut lettuce in a salad. Fold it using your knife and fork.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();


        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Many men use a two-handed shake.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Always bring a gift to someones house.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Always keep your hands visible when eating.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "Use utensils to eat most food.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Do");
        cv.put(DESCRIPTION, "If you have not finished eating, cross your knife and fork on your plate.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not begin eating until the hostess starts.  ");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Do not get up until the guest of honour does. ");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Never toast first always allow the host to.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "When at dinner don't sit unless invited to do so.");
        db.insert(DATABASE_TABLE, null, cv);
        cv.clear();
        cv.put(COUNTRY, "Spain");
        cv.put(INDICATOR, "Dont");
        cv.put(DESCRIPTION, "Don't go bare cheasted anywhere other than the beach or poolside.");
        db.insert(DATABASE_TABLE, null, cv);
        db.close();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub

    }

     public void findCountry(String country)
       {
        int index = 0;
        SQLiteDatabase mDb = this.getReadableDatabase(); 
        List <DosAndDonts> dosNDonts = new ArrayList <DosAndDonts>();

        Cursor cursor = mDb.query(DATABASE_TABLE, new String[] {INDICATOR, DESCRIPTION }, COUNTRY + "=?",
                new String[] { String.valueOf(country) }, null, null, null, null);

        Country returnedCountry = new Country();
        returnedCountry.setName(country);

        while(cursor.moveToNext())
        {
            dosNDonts.add(new DosAndDonts(cursor.getString(index),
                        cursor.getString(index + 1)));          

            index = index + 2;          
        }

        returnedCountry.setCountryDosAndDonts(dosNDonts);

        currentCountry = returnedCountry;
        this.displayResult();
       }

        public void displayResult() 
        {

            TextView country = (TextView) temp.findViewById(R.id.Country_name);
            TextView do1 = (TextView) temp.findViewById(R.id.Do1);
            TextView do2 = (TextView) temp.findViewById(R.id.Do2);
            TextView do3 = (TextView) temp.findViewById(R.id.Do3);
            TextView do4 = (TextView) temp.findViewById(R.id.Do4);
            TextView do5 = (TextView) temp.findViewById(R.id.Do5);
            TextView dont1 = (TextView) temp.findViewById(R.id.Dont1);
            TextView dont2 = (TextView) temp.findViewById(R.id.Dont2);
            TextView dont3 = (TextView) temp.findViewById(R.id.Dont3);
            TextView dont4 = (TextView) temp.findViewById(R.id.Dont4);
            TextView dont5 = (TextView) temp.findViewById(R.id.Dont5);

            TextView dos[] = { do1, do2, do3, do4, do5 };
            TextView donts[] = { dont1, dont2, dont3, dont4, dont5 };

            int doCounter = 0;
            int dontCounter = 0;
            int index = 0;
            List <DosAndDonts> dosNDonts = currentCountry.getCountryDosAndDonts(); 

            country.setText(currentCountry.getName());

            while (index < dosNDonts.size())
            {
                if (dosNDonts.get(index).getIndicator().equals("Do"))
                {
                    dos[doCounter].setText(dosNDonts.get(index).getDescription());
                    doCounter++;
                } 
                else 
                {
                    donts[dontCounter].setText(dosNDonts.get(index).getDescription());
                    dontCounter++;
                }
                index++;
            }
        }




     }

非常感谢您的回复,我已经对onCreate()和populate()方法进行了更改,现在从(1)开始在我的logCat中获取这组错误消息,并且消息集重复约50次,再一次任何帮助都会很棒。

06-12 19:53:00.803: I/Choreographer(1549): Skipped 56 frames!  The application may be doing too much work on its main thread.
06-12 19:53:00.873: D/gralloc_goldfish(1549): Emulator without GPU emulation detected.
06-12 19:53:04.593: E/SQLiteLog(1549): (1) near "name": syntax error
06-12 19:53:04.653: E/SQLiteDatabase(1549): Error inserting Country name=France     Description=Shake hands when you greet someone. Indicator=Do
06-12 19:53:04.653: E/SQLiteDatabase(1549): android.database.sqlite.SQLiteException: near "name": syntax error (code 1): , while compiling: INSERT INTO dosAndDonts(Country name,Description,Indicator) VALUES (?,?,?)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at com.Jamie.dosanddonts.DosAndDontsDbAdapter.populateTable(DosAndDontsDbAdapter.java:49)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at com.Jamie.dosanddonts.DosAndDontsDbAdapter.onCreate(DosAndDontsDbAdapter.java:37)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at com.Jamie.dosanddonts.DosAndDontsDbAdapter.findCountry(DosAndDontsDbAdapter.java:341)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at com.Jamie.dosanddonts.HomeScreen$1.onClick(HomeScreen.java:38)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at android.view.View.performClick(View.java:4204)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at android.view.View$PerformClick.run(View.java:17355)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at android.os.Handler.handleCallback(Handler.java:725)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at android.os.Looper.loop(Looper.java:137)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at android.app.ActivityThread.main(ActivityThread.java:5041)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at java.lang.reflect.Method.invokeNative(Native Method)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at java.lang.reflect.Method.invoke(Method.java:511)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-12 19:53:04.653: E/SQLiteDatabase(1549):     at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:0)

从onCreate()调用该方法时,将db作为参数传递给populateTable()。您已经从onCreate()打开了数据库,无需再次获取可写数据库。

onCreate看起来像这样:

@Override
public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub

    String CREATE_TABLE = "CREATE TABLE " + DATABASE_TABLE + "("
            + COUNTRY + " TEXT," + INDICATOR + " TEXT,"
            + DESCRIPTION + " TEXT" + ")"; 

    db.execSQL(CREATE_TABLE);
    populateTable(db);
}

并且populateTable()的开头看起来像这样:

public void populateTable(SQLiteDatabase db) {

    ContentValues cv = new ContentValues();
    cv.put(COUNTRY, "France");
    cv.put(INDICATOR, "Do");
    ...
}

对于第二个错误,问题可能是您的列名称。尝试将“国家/地区名称”更改为“country_name”。我认为这是导致问题的名称空间。

答案 1 :(得分:0)

在您做出更改后,您可能需要取出COUNTRY变量中的空格。

尝试使用类似的内容

private static final String COUNTRY = "Country_Name";