Java 程序因“而崩溃”;D/ADB“服务:关闭原因是”eof=1“;关于insertData

Java 程序因“而崩溃”;D/ADB“服务:关闭原因是”eof=1“;关于insertData,java,android,database,android-sqlite,Java,Android,Database,Android Sqlite,我的程序在insertData上崩溃,我不知道如何确定这个错误的原因(我是安卓数据库开发的初级,以前从未使用过它) 我认为我的insert方法没有正确处理插入值,如布尔值或int值。有人能指出这个错误的原因吗 LogCat 06-02 12:28:04.439 8601-8601/?D/ADB\U服务:关闭,因为is\U eof=1 r=-1 s->fde.force\U eof=0 My DataBase.java My InsertData.java InsertData-layout.ht

我的程序在
insertData
上崩溃,我不知道如何确定这个错误的原因(我是安卓数据库开发的初级,以前从未使用过它)

我认为我的insert方法没有正确处理插入值,如布尔值或int值。有人能指出这个错误的原因吗

LogCat 06-02 12:28:04.439 8601-8601/?D/ADB\U服务:关闭,因为is\U eof=1 r=-1 s->fde.force\U eof=0

My DataBase.java My InsertData.java InsertData-layout.html
您似乎有很多问题。但是,
D/ADB\u服务:关闭,因为is\u eof=1 r=-1 s->fde.force\u eof=0
似乎不是其中之一。D/表示它是调试消息,不应该是显示停止符(这似乎是一条依赖于设备(android实现)的消息,有些可能会收到此消息,有些可能不会)

数字格式异常 在创建数据库和表之前(假设只有上述活动),插入可能会失败(如果名称输入不是数字),因为您试图将名称解析为权重高度的整数

您可能会遇到以下例外情况:-

06-03 00:08:31.518 2745-2745/va.vehicleapp E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.NumberFormatException: Invalid int: "Fred"
        at java.lang.Integer.invalidInt(Integer.java:138)
        at java.lang.Integer.parse(Integer.java:375)
        at java.lang.Integer.parseInt(Integer.java:366)
        at java.lang.Integer.parseInt(Integer.java:332)
        at va.vehicleapp.MainActivity.ClickMe(MainActivity.java:172)
        at va.vehicleapp.MainActivity.access$000(MainActivity.java:16)
        at va.vehicleapp.MainActivity$1.onClick(MainActivity.java:44)
        at android.view.View.performClick(View.java:4084)
        at android.view.View$PerformClick.run(View.java:16966)
        at android.os.Handler.handleCallback(Handler.java:615)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)
因此,您应该更改为在
onClick
方法中使用以下行:-

    String weight = txtWeight.getText().toString(); // CHANGED to txtWeight not txtName
    String height = txtHeight.getText().toString(); // CHANGED to txtHeight not txtName
将不创建该表 我怀疑,如果您查看日志,您将看到(或者在某个时候,如果您甚至调用onCreate方法,您可能会看到)以下内容:-

06-02 23:24:12.135 2113-2113/? E/SQLiteLog: (1) near "TABLEDataOfSchedule_tableID": syntax error
06-02 23:24:12.135 2113-2113/? D/AndroidRuntime: Shutting down VM
06-02 23:24:12.135 2113-2113/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa6244288)
06-02 23:24:12.135 2113-2113/? E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{va.vehicleapp/va.vehicleapp.MainActivity}: android.database.sqlite.SQLiteException: near "TABLEDataOfSchedule_tableID": syntax error (code 1): , while compiling: CREATE TABLEDataOfSchedule_tableID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT,AGE INTEGER NOT NULL DEFAULT 0, GENDER_M INTEGER NOT NULL DEFAULT 0, GENDER_F INTEGER NOT NULL DEFAULT 0, TRAUMA INTEGER NOT NULL DEFAULT 0, WEIGHT INTEGER NOT NULL DEFAULT 0, HEIGHT INTEGER NOT NULL DEFAULT 0);
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
        at android.app.ActivityThread.access$600(ActivityThread.java:130)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.database.sqlite.SQLiteException: near "TABLEDataOfSchedule_tableID": syntax error (code 1): , while compiling: CREATE TABLEDataOfSchedule_tableID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT,AGE INTEGER NOT NULL DEFAULT 0, GENDER_M INTEGER NOT NULL DEFAULT 0, GENDER_F INTEGER NOT NULL DEFAULT 0, TRAUMA INTEGER NOT NULL DEFAULT 0, WEIGHT INTEGER NOT NULL DEFAULT 0, HEIGHT INTEGER NOT NULL DEFAULT 0);
        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
        at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
        at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
        at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
        at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
        at va.vehicleapp.DataBase.onCreate(DataBase.java:27)
        at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
        at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
        at va.vehicleapp.MainActivity.onCreate(MainActivity.java:23)
        at android.app.Activity.performCreate(Activity.java:5008)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
        at android.app.ActivityThread.access$600(ActivityThread.java:130) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:137) 
        at android.app.ActivityThread.main(ActivityThread.java:4745) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:511) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
        at dalvik.system.NativeStart.main(Native Method) 
  • 删除应用程序的数据、卸载应用程序或将数据库版本增加到2,即(将
    super(上下文,数据库名称,null,1);
    更改为
    super(上下文,数据库名称,null,2);

  • 然后重新运行应用程序

  • 测试结果 进行上述更改,运行(删除应用程序的数据后,创建正确的表很重要),使用以下命令完成输入字段:-

    • 弗雷德
    • 十,
    • 二十一,
    • 45,
    • 男性(勾选)
    • 女性(勾选),
      • 能够同时勾选这两项吗???? -插入字幕未勾选

    导致Toast确认插入。

    请出示您的日志您收到的异常情况是什么?My LogCat-06-02 12:28:04.439 8601-8601/?D/ADB_SERVICES:关闭,因为is_eof=1 r=-1 s->fde.force_eof=0感谢您提供的信息我非常怀疑您的日志只包含一行。当我们要求日志时,我们需要完整的未编辑的一行
    06-03 00:08:31.518 2745-2745/va.vehicleapp E/AndroidRuntime: FATAL EXCEPTION: main
        java.lang.NumberFormatException: Invalid int: "Fred"
            at java.lang.Integer.invalidInt(Integer.java:138)
            at java.lang.Integer.parse(Integer.java:375)
            at java.lang.Integer.parseInt(Integer.java:366)
            at java.lang.Integer.parseInt(Integer.java:332)
            at va.vehicleapp.MainActivity.ClickMe(MainActivity.java:172)
            at va.vehicleapp.MainActivity.access$000(MainActivity.java:16)
            at va.vehicleapp.MainActivity$1.onClick(MainActivity.java:44)
            at android.view.View.performClick(View.java:4084)
            at android.view.View$PerformClick.run(View.java:16966)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
    
        String weight = txtWeight.getText().toString(); // CHANGED to txtWeight not txtName
        String height = txtHeight.getText().toString(); // CHANGED to txtHeight not txtName
    
    06-02 23:24:12.135 2113-2113/? E/SQLiteLog: (1) near "TABLEDataOfSchedule_tableID": syntax error
    06-02 23:24:12.135 2113-2113/? D/AndroidRuntime: Shutting down VM
    06-02 23:24:12.135 2113-2113/? W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa6244288)
    06-02 23:24:12.135 2113-2113/? E/AndroidRuntime: FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to start activity ComponentInfo{va.vehicleapp/va.vehicleapp.MainActivity}: android.database.sqlite.SQLiteException: near "TABLEDataOfSchedule_tableID": syntax error (code 1): , while compiling: CREATE TABLEDataOfSchedule_tableID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT,AGE INTEGER NOT NULL DEFAULT 0, GENDER_M INTEGER NOT NULL DEFAULT 0, GENDER_F INTEGER NOT NULL DEFAULT 0, TRAUMA INTEGER NOT NULL DEFAULT 0, WEIGHT INTEGER NOT NULL DEFAULT 0, HEIGHT INTEGER NOT NULL DEFAULT 0);
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
         Caused by: android.database.sqlite.SQLiteException: near "TABLEDataOfSchedule_tableID": syntax error (code 1): , while compiling: CREATE TABLEDataOfSchedule_tableID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT,AGE INTEGER NOT NULL DEFAULT 0, GENDER_M INTEGER NOT NULL DEFAULT 0, GENDER_F INTEGER NOT NULL DEFAULT 0, TRAUMA INTEGER NOT NULL DEFAULT 0, WEIGHT INTEGER NOT NULL DEFAULT 0, HEIGHT INTEGER NOT NULL DEFAULT 0);
            at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
            at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
            at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
            at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
            at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
            at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
            at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
            at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
            at va.vehicleapp.DataBase.onCreate(DataBase.java:27)
            at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
            at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
            at va.vehicleapp.MainActivity.onCreate(MainActivity.java:23)
            at android.app.Activity.performCreate(Activity.java:5008)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
            at android.app.ActivityThread.access$600(ActivityThread.java:130) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
            at android.os.Handler.dispatchMessage(Handler.java:99) 
            at android.os.Looper.loop(Looper.java:137) 
            at android.app.ActivityThread.main(ActivityThread.java:4745) 
            at java.lang.reflect.Method.invokeNative(Native Method) 
            at java.lang.reflect.Method.invoke(Method.java:511) 
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
            at dalvik.system.NativeStart.main(Native Method) 
    
    @Override
    public void onCreate(SQLiteDatabase db){
        db.execSQL("CREATE TABLE " + TABLE_NAME + //<<<< ADDED space
                " (" +  // ADDED to enclose column definition in brackets
                COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                COL_NAME + " TEXT," +
                COL_AGE + " INTEGER NOT NULL DEFAULT 0, " +
                COL_GENDER_M + " INTEGER NOT NULL DEFAULT 0, " +
                COL_GENDER_F + " INTEGER NOT NULL DEFAULT 0, " +
                COL_TRAUMA + " INTEGER NOT NULL DEFAULT 0, " +
                COL_WEIGHT + " INTEGER NOT NULL DEFAULT 0, " +
                COL_HEIGHT + " INTEGER NOT NULL DEFAULT 0);");
    }