应用程序崩溃在运行到手机android

时间:2014-01-16 00:31:32

标签: java android eclipse sqlite

我是android数据库的新手。我正在创建一个关于数据库(youtube)的youtube教程的应用程序。

我遵循了所有内容,当我运行应用程序时会发生一些事情,应用程序崩溃。

当我首先运行应用程序时,一切正常,但是当我开始单击“创建”按钮时,应用程序崩溃了。

这是错误:

  01-16 08:23:29.319: E/NativeCrypto(1015): ssl=0x598d7898 cert_verify_callback x509_store_ctx=0x56246ab8 arg=0x0
01-16 08:23:29.320: E/NativeCrypto(1015): ssl=0x598d7898 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_RSA
01-16 08:23:49.373: E/NativeCrypto(501): ssl=0x56b78cc0 cert_verify_callback x509_store_ctx=0x55bb2ab8 arg=0x0
01-16 08:23:49.373: E/NativeCrypto(501): ssl=0x56b78cc0 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_RSA
01-16 08:24:32.711: E/KeyguardUpdateMonitor(501): Object tried to add another callback
01-16 08:24:32.711: E/KeyguardUpdateMonitor(501): java.lang.Exception: Called by
01-16 08:24:32.711: E/KeyguardUpdateMonitor(501):   at com.android.internal.policy.impl.keyguard.KeyguardUpdateMonitor.registerCallback(KeyguardUpdateMonitor.java:1107)
01-16 08:24:32.711: E/KeyguardUpdateMonitor(501):   at com.android.internal.policy.impl.keyguard.KeyguardSelectorView.onResume(KeyguardSelectorView.java:369)
01-16 08:24:32.711: E/KeyguardUpdateMonitor(501):   at com.android.internal.policy.impl.keyguard.KeyguardHostView.onScreenTurnedOn(KeyguardHostView.java:1118)
01-16 08:24:32.711: E/KeyguardUpdateMonitor(501):   at com.android.internal.policy.impl.keyguard.KeyguardViewManager.onScreenTurnedOn(KeyguardViewManager.java:404)
01-16 08:24:32.711: E/KeyguardUpdateMonitor(501):   at com.android.internal.policy.impl.keyguard.KeyguardViewMediator.handleNotifyScreenOn(KeyguardViewMediator.java:1767)
01-16 08:24:32.711: E/KeyguardUpdateMonitor(501):   at com.android.internal.policy.impl.keyguard.KeyguardViewMediator.access$2300(KeyguardViewMediator.java:106)
01-16 08:24:32.711: E/KeyguardUpdateMonitor(501):   at com.android.internal.policy.impl.keyguard.KeyguardViewMediator$4.handleMessage(KeyguardViewMediator.java:1413)
01-16 08:24:32.711: E/KeyguardUpdateMonitor(501):   at android.os.Handler.dispatchMessage(Handler.java:107)
01-16 08:24:32.711: E/KeyguardUpdateMonitor(501):   at android.os.Looper.loop(Looper.java:194)
01-16 08:24:32.711: E/KeyguardUpdateMonitor(501):   at android.os.HandlerThread.run(HandlerThread.java:60)
01-16 08:24:32.794: E/AudioMTKHardware(136): setParameters() still have param.size() = 1, remain param = "screen_state=on"
01-16 08:24:55.102: E/BreakpadManager(7715): Breakpad init failed: Couldn't load fb_stl_shared from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/system/app/Facebook.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]]: findLibrary returned null
01-16 08:24:55.811: E/NativeCrypto(1015): ssl=0x54f8f498 cert_verify_callback x509_store_ctx=0x56246ab8 arg=0x0
01-16 08:24:55.812: E/NativeCrypto(1015): ssl=0x54f8f498 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_RSA
01-16 08:24:56.111: E/WifiManager(7715): mWifiServiceMessenger == null
01-16 08:24:57.101: E/NativeCrypto(1015): ssl=0x5add3108 cert_verify_callback x509_store_ctx=0x56a4dab8 arg=0x0
01-16 08:24:57.102: E/NativeCrypto(1015): ssl=0x5add3108 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_RSA
01-16 08:24:58.626: E/NativeCrypto(1015): ssl=0x58094b58 cert_verify_callback x509_store_ctx=0x5479bab8 arg=0x0
01-16 08:24:58.626: E/NativeCrypto(1015): ssl=0x58094b58 cert_verify_callback calling verifyCertificateChain authMethod=RSA
01-16 08:25:08.008: E/AudioMTKHardware(136): setParameters() still have param.size() = 1, remain param = "screen_state=off"

我的代码也在这里:来自主要活动:

package com.example.studentdatabase;


import android.os.Bundle;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.View;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class MainActivity extends Activity {
    String fname,lname,email;
    SQLiteDatabase db;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        db= openOrCreateDatabase("MyDB1",MODE_PRIVATE,null);
        db.execSQL("CREATE TABLE IF NOT EXISTS Student(fname VARCHAR,lname VARCHAR,email VARCHAR)");
    }

        public void Adddata(View view){

        EditText editText1=(EditText) findViewById(R.id.firstname);
        EditText editText2=(EditText) findViewById(R.id.lastname);
        EditText editText3=(EditText) findViewById(R.id.email);

        fname=editText1.getText().toString();
        lname=editText2.getText().toString();
        email=editText3.getText().toString();
        db.execSQL("INSERT INTO Student VALUES('"+fname+"','"+lname+"','"+email+"')");


    }   

    public void showdata(View view){

        Cursor c=db.rawQuery("SELECT * from Student", null);
        int count=c.getCount();
        c.moveToFirst();
        TableLayout tableLayout=new TableLayout(getApplicationContext());
        tableLayout.setVerticalScrollBarEnabled(true);
        TableRow tableRow;
        TextView textView,textView1,textView2,textView3,textView4,textView5;
        tableRow=new TableRow(getApplicationContext());

        textView=new TextView(getApplicationContext());
        textView.setText("Firstname");
        textView.setTextColor(Color.RED);
        textView.setTypeface(null,Typeface.BOLD);
        textView.setPadding(20, 20, 20, 20);
        tableRow.addView(textView);

        textView4=new TextView(getApplicationContext());
        textView4.setText("LastName");
        textView4.setTextColor(Color.RED);
        textView4.setTypeface(null,Typeface.BOLD);
        textView4.setPadding(20, 20, 20, 20);

        textView5=new TextView(getApplicationContext());
        textView5.setText("LastName");
        textView5.setTextColor(Color.RED);
        textView5.setTypeface(null,Typeface.BOLD);
        textView5.setPadding(20, 20, 20, 20);
        tableRow.addView(tableRow);

        for(Integer j=0; j < count; j++){
            tableRow=new TableRow(getApplicationContext());
            textView1=new TextView(getApplicationContext());
            textView1.setText(c.getString(c.getColumnIndex("fname")));
            textView2=new TextView(getApplicationContext());
            textView2.setText(c.getString(c.getColumnIndex("lname")));
            textView3=new TextView(getApplicationContext());
            textView3.setText(c.getString(c.getColumnIndex("email")));

            textView1.setPadding(20, 20,20, 20);
            textView2.setPadding(20, 20,20, 20);
            textView3.setPadding(20, 20,20, 20);

            tableRow.addView(textView1);
            tableRow.addView(textView2);
            tableRow.addView(textView3);

            tableLayout.addView(tableRow);
            c.moveToNext();




        }
        setContentView(tableLayout);
        db.close();
        }
        public void close(View view){

            System.exit(0);
        }


}

我的activity_main.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView2"
    android:layout_below="@+id/textView2"
    android:layout_marginTop="25dp"
    android:text="last Name" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="25dp"
    android:text="Email" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="18dp"
    android:layout_marginTop="27dp"
    android:text="First Name" />

<EditText
    android:id="@+id/firstname"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView2"
    android:layout_alignBottom="@+id/textView2"
    android:layout_toRightOf="@+id/textView2"
    android:ems="10" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/lastname"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView1"
    android:layout_alignBottom="@+id/textView1"
    android:layout_alignLeft="@+id/firstname"
    android:ems="10" />

<EditText
    android:id="@+id/email"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView3"
    android:layout_alignBottom="@+id/textView3"
    android:layout_toRightOf="@+id/textView1"
    android:ems="10" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView3"
    android:layout_below="@+id/email"
    android:layout_marginTop="28dp"
    android:onClick="Adddata"
    android:text="create" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/button1"
    android:layout_alignBottom="@+id/button1"
    android:layout_alignRight="@+id/email"
    android:layout_marginRight="42dp"
    android:onClick="showdata"
    android:text="Show Table" />

<Button
    android:id="@+id/button3"
    andro

id:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_below="@+id/button1"
        android:layout_marginTop="33dp"
        android:onClick="close"
        android:text="Close" />

</RelativeLayout>

2 个答案:

答案 0 :(得分:0)

您的activity_main.xml最后没有标记</RelativeLayout>。我不确定这是一个错字错误。添加它并重建应用程序。希望它能为你运行。

答案 1 :(得分:0)

更改Create Table

db.execSQL("CREATE TABLE IF NOT EXISTS Student(fname TEXT,lname TEXT,email TEXT)");

SQLite使用动态类型。内容可以存储为INTEGER,REAL,TEXT,BLOB或NULL。  并检查db是否为null。