When I run a project on emulator I get a message "Unfortunately, dezo12 has stopped".
LogCat doesn't show anything, and I also tried to run directly on smartphone, but my app also crashed.
I work with eclipse neon and I recently install all needed tools in Android sdk manager.
Here is a 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>