0

My application is terminated when I launched it on my mobile device.

I am trying to connect my application to SQLite database but it doesn't connect properly. When I launch my mobile gradle, the launch is successful. But a logcat error is showing:

waiting for device not connected and terminated.

When I run it without the database application, it runs properly.

This is the MainActivity code and the below there are different activities names code like Uro, Gass, etc.

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);
    }    
}

This is manifest code:

<?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>

This is DatabaseHelper class Code to connect Sqlitedatabase.

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;
    }
}

Here is the Gradle console message:

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

And here is the logcat message:

Waiting for process to come online
Timed out waiting for process to appear on lge-lg_d800-09ce27a110668ee5

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0
  1. You created a table with column name ADDRESS_TEXT, and you're trying to access column ADRESSS. Try removing "_" from this part of your code.

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

  2. String "create table"+Table_Name is interpreted as "create tabledoctor_table" so you should add space after table

Also, if you already created String variables for column names, you should use them in table creation as well.

Gotiasits
  • 1,135
  • 1
  • 10
  • 21