我的Android设备在我的设备上运行应用程序时终止

时间:2017-07-13 14:43:40

标签: android

我的应用程序在我的移动设备上启动时终止。

我正在尝试将我的应用程序连接到SQLite数据库,但它没有正确连接。 当我启动移动计算机时,启动成功。但是显示了一个logcat错误:

  

等待设备未连接并终止。

当我在没有数据库应用程序的情况下运行它时,它运行正常。

这是MainActivity代码,下面有不同的活动名称代码,如Uro,Gass等。

package com.example.asim.obaid;

import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
        DatabaseHelper myDb;
        EditText editname,editemail,editaddress;
        Button btnAddData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        getSupportActionBar().setCustomView(R.layout.actionbar);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        myDb = new DatabaseHelper(this);
        editname = (EditText)findViewById(R.id.editText_name);
        editemail = (EditText)findViewById(R.id.editText_email);
        editaddress = (EditText)findViewById(R.id.editText_address);
        btnAddData = (Button)findViewById(R.id.button_add);
        AddData();

        Button btn_0 = (Button)findViewById(R.id.btn_0);

        btn_0.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, doctorpannal.class);
                startActivity(intent);
            }
        });
    }

    public void AddData() {
        btnAddData.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean isInserted =   myDb.insertData(editname.getText().toString(),
                        editemail.getText().toString(),
                        editaddress.getText().toString());

                if(isInserted == true)
                    Toast.makeText(MainActivity.this ,"Success",Toast.LENGTH_SHORT).show();
                else
                    Toast.makeText(MainActivity.this ,"Not Success",Toast.LENGTH_SHORT).show();
            }
        });
    }

    public void Dentist(View view) {
        Intent intent = new Intent(this, dentist.class);
        startActivity(intent);
    }

    public void PHY(View view) {
        Intent intent = new Intent(this, phy.class);
        startActivity(intent);
    }

    public void DER(View view) {
        Intent intent = new Intent(this, der.class);
        startActivity(intent);
    }

    public void Phytherapy(View view) {
        Intent intent = new Intent(this, phyterapy.class);
        startActivity(intent);
    }

    public void Gas(View view) {
        Intent intent = new Intent(this, gas.class);
        startActivity(intent);
    }

    public void Uro(View view) {
        Intent intent = new Intent(this, uro.class);
        startActivity(intent);
    }

    public void ERT(View view) {
        Intent intent = new Intent(this, ert.class);
        startActivity(intent);
    }

    public void EyeSpec(View view) {
        Intent intent = new Intent(this, espec.class);
        startActivity(intent);
    }

    public void GenralMed(View view) {
        Intent intent = new Intent(this, gm.class);
        startActivity(intent);
    }

    public void Onclolgy(View view) {
        Intent intent = new Intent(this, on.class);
        startActivity(intent);
    }

    public void Ped(View view) {
        Intent intent = new Intent(this, ped.class);
        startActivity(intent);
    }

    public void Orthoped(View view) {
        Intent intent = new Intent(this, ortped.class);
        startActivity(intent);
    }

    public void Readiology(View view) {
        Intent intent = new Intent(this, redology.class);
        startActivity(intent);
    }

    public void LiverSpec(View view) {
        Intent intent = new Intent(this, ls.class);
        startActivity(intent);
    }

    public void Neplogy(View view) {
        Intent intent = new Intent(this, npg.class);
        startActivity(intent);
    }    
}

这是明显的代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    package="com.example.asim.obaid">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="Find a doctor"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".dentist"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".phy"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".der"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".gas"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".phyterapy"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".uro"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".ert"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".espec"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".gm"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".on"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".ped"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".ortped"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".redology"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".ls"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".npg"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity android:name=".doctorpannal"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
    </application>
</manifest>

这是用于连接Sqlitedatabase的DatabaseHelper类代码。

package com.example.asim.obaid;

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

/**
 * Created by asim on 7/12/2017.
 */
public class DatabaseHelper extends SQLiteOpenHelper {

    public static final String DataBase_Name="Doctor.db";
    public static final String Table_Name="doctor_table";
    public static final String Col_1="ID";
    public static final String Col_2="DR_NAME";
    public static final String Col_3="EMAIL";
    public static final String Col_4="ADDRESS";

    public DatabaseHelper(Context context) {
        super(context, DataBase_Name, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table"+Table_Name+"(ID INTEGER PRIMARY KEY AUTOINCREMENT,DR_NAME TEXT,EMAIL TEXT,ADDRESS_TEXT)");
    }

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

    public boolean insertData(String dr_name, String email, String address) {
        SQLiteDatabase db= this.getWritableDatabase();
        ContentValues contentValues= new ContentValues();
        contentValues .put(Col_2,dr_name);
        contentValues .put(Col_3,email);
        contentValues .put(Col_4,address);
        long result=    db.insert(Table_Name,null,contentValues);
        if (result == -1)
            return false;
        else
            return true;
    }
}

以下是Gradle控制台消息:

Executing tasks: [:app:assembleDebug]

Configuration on demand is an incubating feature.
Incremental java compilation is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2330Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72330Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2330Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72330Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42330Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2330Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppindexing810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBasement810Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:mergeDebugShaders UP-TO-DATE
:app:compileDebugShaders UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:buildInfoDebugLoader
:app:transformClassesWithExtractJarsForDebug UP-TO-DATE
:app:transformClassesWithInstantRunVerifierForDebug UP-TO-DATE
:app:transformClassesWithJavaResourcesVerifierForDebug UP-TO-DATE
:app:mergeDebugJniLibFolders UP-TO-DATE
:app:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:app:transformResourcesAndNative_libsWithJavaResourcesVerifierForDebug UP-TO-DATE
:app:transformClassesWithInstantRunForDebug UP-TO-DATE
:app:transformClasses_enhancedWithInstant+reloadDexForDebug UP-TO-DATE
:app:incrementalDebugTasks
:app:prePackageMarkerForDebug
:app:fastDeployDebugExtractor UP-TO-DATE
:app:generateDebugInstantRunAppInfo
:app:transformClassesWithDexForDebug
To run dex in process, the Gradle daemon needs a larger heap.
It currently has approximately 910 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to more than 4096 MB.
To do this set org.gradle.jvmargs=-Xmx4096M in the project gradle.properties.
For more information see https://docs.gradle.org/current/userguide/build_environment.html
:app:validateDebugSigning
:app:packageDebug
:app:zipalignDebug
:app:fullDebugBuildInfoGenerator
:app:assembleDebug

BUILD SUCCESSFUL

Total time: 15.218 secs

这是logcat消息:

  

等待进程上线
  超时等待进程出现在lge-lg_d800-09ce27a110668ee5

1 个答案:

答案 0 :(得分:0)

  1. 您创建了一个列名为ADDRESS_TEXT的表,并且您尝试访问列ADRESSS。尝试从代码的这一部分删除“_”。

    db.execSQL(“create table”+ Table_Name +“(ID INTEGER PRIMARY KEY AUTOINCREMENT,DR_NAME TEXT,EMAIL TEXT,ADDRESS_TEXT)”);

  2. 字符串"create table"+Table_Name被解释为"create tabledoctor_table“因此您应该在table

  3. 之后添加空格

    此外,如果您已经为列名创建了String变量,那么您也应该在表创建中使用它们。