Kaskus

Tech

edhitya15Avatar border
TS
edhitya15
[ask]tolong bantuin eror progam ane gan
ini ane coba bikin bikin progam android "ANDROID SQLite Database" paling dasar tp tetep eror gan,padahal ane njiplak plek tp tetep salah gan
mohon bantuannya gan...
ni awal ane nykrip di res -> value -> string xml
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="hello">Masukan nama dan hobi</string>
<string name="app_name">Database Android1</string>
<string name="btnAddtxt">Add</string>
<string name="namaLabel">Nama</string>
<string name="hobiLabel">hobi</string>
<string name="nomorLabel">No.</string>
</resources>


di situ msh blm ada eror gan
lalu ane nyekrip lagi di res -> layout -> activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
androidemoticon-Embarrassmentrientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<EditText
android:id="@+id/inNama"
android:layout_width="100dip"
android:layout_height="wrap_content" />

<EditText
android:id="@+id/inHobi"
android:layout_width="100dip"
android:layout_height="wrap_content" />

<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btnAdd" /> "Baris ini eror gan (error: Error: No resource found that matches the given name (at 'text' with value '@string/btnAdd').)"
</LinearLayout>

<TableLayout
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TableRow
android:id="@+id/tabel_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/no_id"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:text="@string/nomorLabel" />

<TextView
android:id="@+id/hobi_id"
android:layout_width="100dip"
android:layout_height="@string/hobiLabel" />
</TableRow>
</TableLayout>
</TextView>

</LinearLayout>


itu aq harus gimana gan perbaaikinya?
ane tetep nerusin aja sapa tau ada yg kurang,
terus ane buat class di "DatabaseAndroid -> src ->com.db.satu" namanya "DatabaseManager.java" isi sourcodenya

package com.db.satu;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DatabaseManager {

private static final String ROW_ID = "_id";
private static final String ROW_NAMA = "nama";
private static final String ROW_HOBI = "hobi";

private static final String NAMA_DB = "DatabaseAndroidSatu";
private static final String NAMA_TABEL = "hobiku";
private static final int DB_VERSION = 1;

private static final String CREATE_TABLE = "create table "+NAMA_TABEL+" ("+ROW_ID+" integer PRIMARY KEY autoincrement, "+ROW_NAMA+" text,"+ROW_HOBI+" text)";

private final Context context;
private DatabaseOpenHelper dbHelper;
private SQLiteDatabase db;

public DatabaseManager(Context ctx) {
this.context = ctx;
dbHelper = new DatabaseOpenHelper(context);
db = dbHelper.getWritableDatabase();
}
private static class DatabaseOpenHelper extends SQLiteOpenHelper {
public DatabaseOpenHelper(Context context) {
super(context, NAMA_DB, null, DB_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVer, int newVer) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS "+NAMA_DB);
onCreate(db);
}
}
public void close() {
dbHelper.close();
}
public void addRow(String nama, String hobi) {
ContentValues values = new ContentValues();
values.put(ROW_NAMA, nama);
values.put(ROW_HOBI, hobi);
try {
db.insert(NAMA_TABEL, null, values);
} catch (Exception e) {
Log.e("DB ERROR", e.toString());
e.printStackTrace();
}
}
public ArrayList<ArrayList<Object>> ambilSemuaBaris() {
ArrayList<ArrayList<Object>> dataArray = new ArrayList<ArrayList<Object>>();
Cursor cur;
try {
cur = db.query(NAMA_TABEL,
new String[] { ROW_ID, ROW_NAMA, ROW_HOBI }, null, null,
null, null, null);
cur.moveToFirst();
if (!cur.isAfterLast()) {
do {
ArrayList<Object> dataList = new ArrayList<Object>();
dataList.add(cur.getLong(0));
dataList.add(cur.getString(1));
dataList.add(cur.getString(2));
dataArray.add(dataList);
} while (cur.moveToNext());
}
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("DEBE ERROR", e.toString());
}
return dataArray;
}
}


disini belom ada erornya gan,
lalu ane rubah nama di "DatabaseAndroid -> src ->com.db.satu ->DatabaseAndroid.java jadi AndroidDatabaseSatu.java
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
androidemoticon-Embarrassmentrientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<EditText
android:id="@+id/inNama"
android:layout_width="100dip"
android:layout_height="wrap_content" />

<EditText
android:id="@+id/inHobi"
android:layout_width="100dip"
android:layout_height="wrap_content" />

<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btnAdd" />
</LinearLayout>

<TableLayout
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TableRow
android:id="@+id/tabel_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/no_id"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:text="@string/nomorLabel" />

<TextView
android:id="@+id/hobi_id"
android:layout_width="100dip"
android:layout_height="@string/hobiLabel" />
</TableRow>
</TableLayout>
</TextView>

</LinearLayout>

gk ada erornya gan....

disni ane bingung gan pada layout.xml blm bisa ane perbaiki,,,
mohon pencerahannya gan
thxemoticon-Sorry
0
724
1
GuestAvatar border
Komentar yang asik ya
Urutan
Terbaru
Terlama
GuestAvatar border
Komentar yang asik ya
Komunitas Pilihan