运行应用程序时Android数据库致命错误?

时间:2013-12-14 21:13:24

标签: java android

我正在编写我的第一个存储数据库的程序。但是,当我尝试运行时,它说发生了一些致命的错误。

以下是我的代码

MainActivity.java

package kenneth.database;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener{

    public Database db;
    EditText input,output;
    Button save,show;
    TextView auth;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        db = new Database(this);
        db.open();

        input = (EditText) findViewById(R.id.inputName);
        output = (EditText) findViewById(R.id.outputName);
        save = (Button)findViewById(R.id.saveName);
        show = (Button)findViewById(R.id.showName);
        auth = (TextView)findViewById(R.id.authentication);
        save.setOnClickListener(this);
        show.setOnClickListener(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onClick(View view) {
        // TODO Auto-generated method stub
        String username = input.getText().toString();
        switch(view.getId()){
        case R.id.saveName:
            db.insertUser(username);
            break;
        case R.id.showName:
            if(db.authenticateUser(username)){
                auth.setText("Authenticated");
            }
            else{
                auth.setText("Not Authenticated!!");
            }
            break;
        }

    }

}

Database.java

package kenneth.database;

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 Database extends SQLiteOpenHelper {
    public static final int version = 0;
    public static final String db_name = "database";
    public  static final String KEY_ROWID = "rollNumber";
    public  static final String DB_TABLE = "users";
    public  static final String DB_CREATE = "CREATE TABLE Kenneth (rollNumber INTEGER);";
    private SQLiteDatabase db;
    private Database dbHelper;

    public Database(Context context) {
        super(context, db_name, null, version);
        dbHelper = new Database(context);
        // TODO Auto-generated constructor stub
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL(DB_CREATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL("DROP TABLE IF EXISTS " + DB_TABLE);
        onCreate(db);
    }


      // Will be used by the ArrayAdapter in the ListView

          public void open() throws SQLException {
            db = dbHelper.getWritableDatabase();
          }

          public void close() {
            dbHelper.close();
          }
    // Insert User
            public long insertUser(String username) {
                // TODO Auto-generated method stub
                ContentValues vals = new ContentValues();
                vals.put(KEY_ROWID,username);
                return db.insert(DB_TABLE,null,vals);
            }

            public boolean authenticateUser(String username) {
                // TODO Auto-generated method stub
                Cursor cursor = db.query(
                        DB_TABLE,
                        new String[]{KEY_ROWID},
                        KEY_ROWID+"?",
                        new String[]{username},
                        null,
                        null,
                        null
                        )   ;
                if (cursor !=null && cursor.getCount()==1){
                    return true;
                }
                return false;
            }

}

当我尝试运行它时,会发生错误。以下是日志文件

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (javaClasses.cpp:129), pid=4408, tid=8684
#  fatal error: Invalid layout of preloaded class
#
# JRE version: 7.0_10-b18
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.6-b04 mixed mode windows-amd64 compressed oops)
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
#

---------------  T H R E A D  ---------------

Current thread (0x0000000002350800):  JavaThread "Unknown thread" [_thread_in_vm, id=8684, stack(0x0000000002220000,0x0000000002320000)]

Stack: [0x0000000002220000,0x0000000002320000]

---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )

Other Threads:

=>0x0000000002350800 (exited) JavaThread "Unknown thread" [_thread_in_vm, id=8684, stack(0x0000000002220000,0x0000000002320000)]

VM state:not at safepoint (not fully initialized)

VM Mutex/Monitor currently owned by a thread: None

GC Heap History (0 events):
No events

Deoptimization events (0 events):
No events

Internal exceptions (0 events):
No events

Events (10 events):
Event: 0.009 loading class 0x0000000002369550 done
Event: 0.009 loading class 0x0000000002369010 done
Event: 0.009 loading class 0x0000000002369640
Event: 0.009 loading class 0x0000000008a9c890
Event: 0.009 loading class 0x0000000008a9c890 done
Event: 0.009 loading class 0x0000000008a9c990
Event: 0.009 loading class 0x0000000008a9c990 done
Event: 0.009 loading class 0x0000000008a9daa0
Event: 0.010 loading class 0x0000000008a9daa0 done
Event: 0.010 loading class 0x0000000002369640 done


Dynamic libraries:
0x00007ff6e2a80000 - 0x00007ff6e2ab3000     C:\Program Files\Java\eclipse\jre\bin\javaw.exe
0x00007ffaea8a0000 - 0x00007ffaeaa49000     C:\WINDOWS\SYSTEM32\ntdll.dll
0x00007ffae8360000 - 0x00007ffae8499000     C:\WINDOWS\system32\KERNEL32.DLL
0x00007ffae7da0000 - 0x00007ffae7eae000     C:\WINDOWS\system32\KERNELBASE.dll
0x00007ffae6850000 - 0x00007ffae68db000     C:\WINDOWS\system32\apphelp.dll
0x00007ffae32d0000 - 0x00007ffae331c000     C:\WINDOWS\AppPatch\AppPatch64\AcGenral.DLL
0x00007ffaea290000 - 0x00007ffaea337000     C:\WINDOWS\system32\msvcrt.dll
0x00007ffae7a60000 - 0x00007ffae7a8b000     C:\WINDOWS\SYSTEM32\SspiCli.dll
0x00007ffae8640000 - 0x00007ffae8691000     C:\WINDOWS\system32\SHLWAPI.dll
0x00007ffaea3b0000 - 0x00007ffaea521000     C:\WINDOWS\system32\USER32.dll
0x00007ffae84c0000 - 0x00007ffae8636000     C:\WINDOWS\system32\ole32.dll
0x00007ffae8990000 - 0x00007ffae9d9f000     C:\WINDOWS\system32\SHELL32.dll
0x00007ffae7230000 - 0x00007ffae724f000     C:\WINDOWS\SYSTEM32\USERENV.dll
0x00007ffae8740000 - 0x00007ffae87e5000     C:\WINDOWS\system32\ADVAPI32.dll
0x00007ffadc9f0000 - 0x00007ffadca0b000     C:\WINDOWS\SYSTEM32\MPR.dll
0x00007ffae87f0000 - 0x00007ffae8926000     C:\WINDOWS\system32\RPCRT4.dll
0x00007ffae8930000 - 0x00007ffae8987000     C:\WINDOWS\SYSTEM32\sechost.dll
0x00007ffae8180000 - 0x00007ffae8357000     C:\WINDOWS\SYSTEM32\combase.dll
0x00007ffaea000000 - 0x00007ffaea145000     C:\WINDOWS\system32\GDI32.dll
0x00007ffae7c20000 - 0x00007ffae7c34000     C:\WINDOWS\SYSTEM32\profapi.dll
0x00007ffae60b0000 - 0x00007ffae6151000     C:\WINDOWS\SYSTEM32\SHCORE.dll
0x00007ffae8140000 - 0x00007ffae8174000     C:\WINDOWS\system32\IMM32.DLL
0x00007ffaea150000 - 0x00007ffaea288000     C:\WINDOWS\system32\MSCTF.dll
0x00007ffae5840000 - 0x00007ffae5a9a000     C:\WINDOWS\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.9600.16384_none_62475f7becb72503\COMCTL32.dll
0x00000000619d0000 - 0x0000000061aa1000     C:\Program Files\Java\eclipse\jre\bin\msvcr100.dll
0x00000000612b0000 - 0x00000000619cf000     C:\Program Files\Java\eclipse\jre\bin\server\jvm.dll
0x00007ffadeb00000 - 0x00007ffadeb09000     C:\WINDOWS\SYSTEM32\WSOCK32.dll
0x00007ffae0360000 - 0x00007ffae037f000     C:\WINDOWS\SYSTEM32\WINMM.dll
0x00007ffaea600000 - 0x00007ffaea607000     C:\WINDOWS\system32\PSAPI.DLL
0x00007ffae9da0000 - 0x00007ffae9df8000     C:\WINDOWS\system32\WS2_32.dll
0x00007ffae0330000 - 0x00007ffae035a000     C:\WINDOWS\SYSTEM32\WINMMBASE.dll
0x00007ffae8130000 - 0x00007ffae8139000     C:\WINDOWS\system32\NSI.dll
0x00007ffae80e0000 - 0x00007ffae812a000     C:\WINDOWS\SYSTEM32\cfgmgr32.dll
0x00007ffae6ab0000 - 0x00007ffae6ad6000     C:\WINDOWS\SYSTEM32\DEVOBJ.dll
0x00000000612a0000 - 0x00000000612af000     C:\Program Files\Java\eclipse\jre\bin\verify.dll
0x0000000061270000 - 0x0000000061298000     C:\Program Files\Java\eclipse\jre\bin\java.dll
0x0000000061250000 - 0x0000000061265000     C:\Program Files\Java\eclipse\jre\bin\zip.dll

VM Arguments:
jvm_args: -Dfile.encoding=Cp1252 -Xbootclasspath:D:\Kenneth\InterIITTech\adt-bundle-windows-x86_64-20131030\sdk\platforms\android-16\android.jar 
java_command: kenneth.database.Database
Launcher Type: SUN_STANDARD

Environment Variables:
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_10
PATH=C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WinAVR-20100110\bin;C:\WinAVR-20100110\utils\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Bitvise SSH Client;C:\Program Files\Java\jdk1.7.0_02\bin;C:\Program Files\MATLAB\R2011a\runtime\win64;C:\Program Files\MATLAB\R2011a\bin;C:\Program Files\SourceGear\Common\DiffMerge\;D:\Kenneth\InterIITTech\adt-bundle-windows-x86_64-20131030\sdk\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\
USERNAME=Kenneth Roy
OS=Windows_NT
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 58 Stepping 9, GenuineIntel



---------------  S Y S T E M  ---------------

OS: Windows 8 , 64 bit Build 9200 

CPU:total 8 (4 cores per cpu, 2 threads per core) family 6 model 58 stepping 9, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, ht, tsc, tscinvbit, tscinv

Memory: 4k page, physical 4066664k(972364k free), swap 10091836k(2938884k free)

vm_info: Java HotSpot(TM) 64-Bit Server VM (23.6-b04) for windows-amd64 JRE (1.7.0_10-b18), built on Nov 28 2012 05:00:40 by "java_re" with unknown MS VC++:1600

time: Sun Dec 15 02:34:47 2013
elapsed time: 0 seconds

0 个答案:

没有答案