3

私はAndroid開発の初心者であり、学習のためにニューボストンのWebサイトのチュートリアルに従います。しかし、なぜコードがそこで機能しないのかわかりません。データベースの作成を確認すると、何も奇妙なことはわかりません。手伝ってくれませんか。私は間違いを理解し、Androidの開発について学び続けることを嬉しく思います。

avdを起動して更新をクリックすると、「最終的に」「良好」になりますが、ログに記録されるエラーもあります。また、表示をクリックしてデータを表示すると、「残念ながら、SQLiteExampleが停止しました」というメッセージが表示されたダイアログが表示されます。

長い投稿で申し訳ありませんが、私が初心者のように、私があなたに与えることができるすべてのコードをあなたに与えます。

SQLiteExample.java

package exercice.thenewboston;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class SQLiteExample extends Activity implements OnClickListener
{
    Button  sqlUpdate, sqlView;
    EditText    sqlName, sqlHotness;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        sqlUpdate = (Button) findViewById(R.id.bSQLUpdate);
        sqlName = (EditText) findViewById(R.id.etSQLName);
        sqlHotness = (EditText) findViewById(R.id.etSQLHotness);

        sqlView = (Button) findViewById(R.id.bSQLopenView);
        sqlView.setOnClickListener(this);
        sqlUpdate.setOnClickListener(this);
    }

    public void onClick(View arg0){
        switch (arg0.getId())
        {
            case R.id.bSQLUpdate:

            boolean didItWork = true;
            try
            {
                String name = sqlName.getText().toString();
                String hotness = sqlHotness.getText().toString();

                HotOrNot entry = new HotOrNot(SQLiteExample.this);
                entry.open();
                entry.createEntry(name, hotness);
                entry.close();
            }
            catch(Exception e )
            {
                didItWork = false;
                String error = e.toString();
                Dialog d = new Dialog(this);
                d.setTitle("CATCH");
                TextView tv = new TextView(this);
                tv.setText(error);
                d.setContentView(tv);
                d.show();
            }

            finally
            {
                if (didItWork)
                {
                    Dialog d = new Dialog(this);
                    d.setTitle("FINALLY");
                    TextView tv = new TextView(this);
                    tv.setText("GOOD");
                    d.setContentView(tv);
                    d.show();
                }
            }
            break;
            case R.id.bSQLopenView:
                Intent i = new Intent("exercice.thenewboston.SQLVIEW");
                startActivity(i);
            break;
        }
    }
    }

HotOrNot.java

package exercice.thenewboston;

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

public class HotOrNot
{
    public static final String  KEY_ROWID           = "_id";
    public static final String  KEY_NAME            = "persons_name";
    public static final String  KEY_HOTNESS         = "persons_hotness";

    private static final String DATABASE_NAME       = "HotOrNotdb";
    private static final String DATABASE_TABLE      = "peopleTable";
    private static final int    DATABASE_VERSION    = 1;

    private DbHelper            ourHelper;
    private final Context       ourContext;
    private SQLiteDatabase      ourDatabase;

    private static class DbHelper extends SQLiteOpenHelper
    {

        public DbHelper(Context context)
        {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db)
        {
            db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_HOTNESS + " TEXT NOT NULL);");
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
        {
            db.execSQL("DROP TABLE IF EXITS " + DATABASE_TABLE);
            onCreate(db);
        }
    }

    public HotOrNot(Context c)
    {
        ourContext = c;
    }

    public HotOrNot open() throws SQLException
    {
        ourHelper = new DbHelper(ourContext);
        ourDatabase = ourHelper.getWritableDatabase();
        return this;
    }

    public void close()
    {
        ourHelper.close();
    }

    public long createEntry(String name, String hotness)
    {
        ContentValues cv = new ContentValues();
        cv.put(KEY_NAME, name);
        cv.put(KEY_HOTNESS, hotness);
        return ourDatabase.insert(DATABASE_TABLE, null, cv);
    }

    public String getData()
    {
        String[] columns = new String[]{ KEY_ROWID, KEY_NAME, KEY_HOTNESS};
        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
        String result = "";

        int iRow = c.getColumnIndex(KEY_ROWID);
        int iName = c.getColumnIndex(KEY_NAME);
        int iHotness = c.getColumnIndex(KEY_HOTNESS);

        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext())
        {
            result = result + c.getString(iRow) + " " + c.getString(iName) + " " + c.getString(iHotness) + "\n";
        }

        return result;

    }
}

SQLView.java

package exercice.thenewboston;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class SQLView extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sqlview);
        TextView tv  = (TextView) findViewById(R.id.tvSQLinfo);
        HotOrNot info = new HotOrNot(this);
        info.open();
        String data = info.getData();
        info.close();
        tv.setText(data);
    }
}

res->レイアウト->main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/TextView1"
        android:text="Name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

    </TextView>

    <EditText
        android:id="@+id/etSQLName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </EditText>

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hotness scale 1 to 10">
    </TextView>

    <EditText
        android:id="@+id/etSQLHotness"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </EditText>

    <Button
        android:id="@+id/bSQLUpdate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Update SQLite Database" />


    <Button
        android:id="@+id/bSQLopenView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="View">

    </Button>

</LinearLayout>

res->レイアウト->sqlview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id= "@+id/tableLayout1">

        <TableRow>
           <TextView android:text="Names"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1">
           </TextView>

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="Hotness"
                android:layout_weight="1">
            </TextView>

        </TableRow>

    </TableLayout>

    <TextView
        android:id="@+id/tvSQLinfo"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="get info from db">
    </TextView>

</LinearLayout>

起動時にログを記録し、データを入力し、更新をクリックし、表示をクリックした後

04-29 16:01:58.217: I/dalvikvm(530): threadid=3: reacting to signal 3
04-29 16:01:58.277: I/dalvikvm(530): Wrote stack traces to '/data/anr/traces.txt'
04-29 16:01:58.627: D/gralloc_goldfish(530): Emulator without GPU emulation detected.
04-29 16:01:58.737: I/dalvikvm(530): threadid=3: reacting to signal 3
04-29 16:01:58.757: I/dalvikvm(530): Wrote stack traces to '/data/anr/traces.txt'
04-29 16:02:20.867: I/SqliteDatabaseCpp(530): sqlite returned: error code = 1, msg = table peopleTable has no column named persons_hotness, db=/data/data/exercice.thenewboston/databases/HotOrNotdb
04-29 16:02:20.945: E/SQLiteDatabase(530): Error inserting persons_hotness=4 persons_name=rt
04-29 16:02:20.945: E/SQLiteDatabase(530): android.database.sqlite.SQLiteException: table peopleTable has no column named persons_hotness: , while compiling: INSERT INTO peopleTable(persons_hotness,persons_name) VALUES (?,?)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at android.database.sqlite.SQLiteStatement.acquireAndLock(SQLiteStatement.java:260)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:112)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1718)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1591)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at exercice.thenewboston.HotOrNot.createEntry(HotOrNot.java:69)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at exercice.thenewboston.SQLiteExample.onClick(SQLiteExample.java:46)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at android.view.View.performClick(View.java:3511)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at android.view.View$PerformClick.run(View.java:14105)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at android.os.Handler.handleCallback(Handler.java:605)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at android.os.Handler.dispatchMessage(Handler.java:92)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at android.os.Looper.loop(Looper.java:137)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at android.app.ActivityThread.main(ActivityThread.java:4424)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at java.lang.reflect.Method.invokeNative(Native Method)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at java.lang.reflect.Method.invoke(Method.java:511)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-29 16:02:20.945: E/SQLiteDatabase(530):  at dalvik.system.NativeStart.main(Native Method)
04-29 16:02:26.688: I/SqliteDatabaseCpp(530): sqlite returned: error code = 1, msg = no such column: persons_hotness, db=/data/data/exercice.thenewboston/databases/HotOrNotdb
04-29 16:02:26.698: D/AndroidRuntime(530): Shutting down VM
04-29 16:02:26.698: W/dalvikvm(530): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
04-29 16:02:26.848: E/AndroidRuntime(530): FATAL EXCEPTION: main
04-29 16:02:26.848: E/AndroidRuntime(530): java.lang.RuntimeException: Unable to start activity ComponentInfo{exercice.thenewboston/exercice.thenewboston.SQLView}: android.database.sqlite.SQLiteException: no such column: persons_hotness: , while compiling: SELECT _id, persons_name, persons_hotness FROM peopleTable
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.os.Looper.loop(Looper.java:137)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.app.ActivityThread.main(ActivityThread.java:4424)
04-29 16:02:26.848: E/AndroidRuntime(530):  at java.lang.reflect.Method.invokeNative(Native Method)
04-29 16:02:26.848: E/AndroidRuntime(530):  at java.lang.reflect.Method.invoke(Method.java:511)
04-29 16:02:26.848: E/AndroidRuntime(530):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-29 16:02:26.848: E/AndroidRuntime(530):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-29 16:02:26.848: E/AndroidRuntime(530):  at dalvik.system.NativeStart.main(Native Method)
04-29 16:02:26.848: E/AndroidRuntime(530): Caused by: android.database.sqlite.SQLiteException: no such column: persons_hotness: , while compiling: SELECT _id, persons_name, persons_hotness FROM peopleTable
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:127)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:94)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:53)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1564)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1449)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1405)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1485)
04-29 16:02:26.848: E/AndroidRuntime(530):  at exercice.thenewboston.HotOrNot.getData(HotOrNot.java:75)
04-29 16:02:26.848: E/AndroidRuntime(530):  at exercice.thenewboston.SQLView.onCreate(SQLView.java:17)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.app.Activity.performCreate(Activity.java:4465)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-29 16:02:26.848: E/AndroidRuntime(530):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-29 16:02:26.848: E/AndroidRuntime(530):  ... 11 more
04-29 16:02:27.018: I/dalvikvm(530): threadid=3: reacting to signal 3
04-29 16:02:27.238: I/dalvikvm(530): Wrote stack traces to '/data/anr/traces.txt'
04-29 16:02:27.338: D/dalvikvm(530): GC_CONCURRENT freed 238K, 6% free 6678K/7047K, paused 19ms+5ms
04-29 16:02:27.388: E/SQLiteDatabase(530): close() was never explicitly called on database '/data/data/exercice.thenewboston/databases/HotOrNotdb' 
04-29 16:02:27.388: E/SQLiteDatabase(530): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
04-29 16:02:27.388: E/SQLiteDatabase(530):  at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1943)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1007)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1051)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:770)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:157)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at exercice.thenewboston.HotOrNot.open(HotOrNot.java:55)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at exercice.thenewboston.SQLView.onCreate(SQLView.java:16)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at android.app.Activity.performCreate(Activity.java:4465)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at android.os.Looper.loop(Looper.java:137)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at android.app.ActivityThread.main(ActivityThread.java:4424)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at java.lang.reflect.Method.invokeNative(Native Method)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at java.lang.reflect.Method.invoke(Method.java:511)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-29 16:02:27.388: E/SQLiteDatabase(530):  at dalvik.system.NativeStart.main(Native Method)
04-29 16:02:27.527: I/dalvikvm(530): threadid=3: reacting to signal 3
04-29 16:02:27.537: I/dalvikvm(530): Wrote stack traces to '/data/anr/traces.txt'
04-29 16:02:27.837: I/dalvikvm(530): threadid=3: reacting to signal 3
04-29 16:02:27.857: I/dalvikvm(530): Wrote stack traces to '/data/anr/traces.txt'
04-29 16:02:29.787: I/Process(530): Sending signal. PID: 530 SIG: 9

よろしくお願いします。

詳細:SAMへの回答Samに返信していただきありがとうございます。だから私はDATABASE_VERSION=2を置きます。および20

@Override
public void onCreate(SQLiteDatabase db)
{
 db.execSQL("DROP TABLE IF EXITS " + DATABASE_TABLE);  // same error if i remove this line

db.execSQL("CREATE TABLE peopleTable ( _id INTEGER PRIMARY KEY AUTOINCREMENT, persons_name TEXT NOT NULL, persons_hotness TEXT NOT NULL);");
}

アップデート「Catch.android.database.sqlite.SQLiteException:Near "EXITS":syntax error:while compiling:DROP Table ifEXITSpeopleTable」をクリックするとAndroidでメッセージエラーが発生します

04-29 19:11:50.361: W/dalvikvm(536): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
04-29 19:11:50.441: E/AndroidRuntime(536): FATAL EXCEPTION: main
04-29 19:11:50.441: E/AndroidRuntime(536): java.lang.RuntimeException: Unable to start activity ComponentInfo{exercice.thenewboston/exercice.thenewboston.SQLView}: android.database.sqlite.SQLiteException: near "EXITS": syntax error: , while compiling: DROP TABLE IF EXITS peopleTable
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.os.Looper.loop(Looper.java:137)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.app.ActivityThread.main(ActivityThread.java:4424)
04-29 19:11:50.441: E/AndroidRuntime(536):  at java.lang.reflect.Method.invokeNative(Native Method)
04-29 19:11:50.441: E/AndroidRuntime(536):  at java.lang.reflect.Method.invoke(Method.java:511)
04-29 19:11:50.441: E/AndroidRuntime(536):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-29 19:11:50.441: E/AndroidRuntime(536):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-29 19:11:50.441: E/AndroidRuntime(536):  at dalvik.system.NativeStart.main(Native Method)
04-29 19:11:50.441: E/AndroidRuntime(536): Caused by: android.database.sqlite.SQLiteException: near "EXITS": syntax error: , while compiling: DROP TABLE IF EXITS peopleTable
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:134)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.database.sqlite.SQLiteStatement.acquireAndLock(SQLiteStatement.java:260)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:84)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1899)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1839)
04-29 19:11:50.441: E/AndroidRuntime(536):  at exercice.thenewboston.HotOrNot$DbHelper.onUpgrade(HotOrNot.java:44)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:170)
04-29 19:11:50.441: E/AndroidRuntime(536):  at exercice.thenewboston.HotOrNot.open(HotOrNot.java:57)
04-29 19:11:50.441: E/AndroidRuntime(536):  at exercice.thenewboston.SQLView.onCreate(SQLView.java:16)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.app.Activity.performCreate(Activity.java:4465)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-29 19:11:50.441: E/AndroidRuntime(536):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-29 19:11:50.441: E/AndroidRuntime(536):  ... 11 more
04-29 19:11:50.691: I/dalvikvm(536): threadid=3: reacting to signal 3
04-29 19:11:50.711: I/dalvikvm(536): Wrote stack traces to '/data/anr/traces.txt'
04-29 19:11:51.071: I/dalvikvm(536): threadid=3: reacting to signal 3
04-29 19:11:51.111: I/dalvikvm(536): Wrote stack traces to '/data/anr/traces.txt'
4

1 に答える 1

1

createステートメントは問題ないように見えるので、ある時点でテーブルのデザインを変更したと思います。古いテーブルを削除して、新しいスキーマを作成してみてください。これを行う最も簡単な方法は、を2にアップグレードするDATABASE_VERSIONことです。

于 2012-04-29T18:26:06.373 に答える