Wenn ich ein Projekt auf dem Emulator starte bekomme ich eine Nachricht "Leider hat dezo12 aufgehört".Warum funktioniert meine einfache SQLite App auf Android nicht?
LogCat zeigt nichts, und ich habe auch versucht, direkt auf dem Smartphone zu laufen, aber meine App ist auch abgestürzt.
Ich arbeite mit Eclipse Neon und ich installiere vor kurzem alle benötigten Tools in Android SDK-Manager. Hier
ist ein Code:
MAIN ACTIVITY.java
package com.example.dezo12;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = (TextView)findViewById(R.id.textView1);
SQLiteDatabase database = openOrCreateDatabase("rex.db", MODE_PRIVATE, null);
database.execSQL("create table if not exist sampletable(name text, location text)");
database.execSQL("insert into sampletable values('dezo', 'bela')");
Cursor cursor = database.rawQuery("select * from sampletable", null);
cursor.moveToFirst();
String name = cursor.getString(0);
String location = cursor.getString(1);
textView.setText(name+ "/n" +location);
database.close();
}
}
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"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="49dp"
android:layout_marginTop="40dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dezo12"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="22"
android:targetSdkVersion="22" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
'LogCat doesnt zeigen anything' Das ist ziemlich schwer zu glauben ... – John3136
' SQLiteOpenHelper' sollte idealerweise verwendet werden –