0

I was just started to learn Android programming and I was trying to make a simple Android SQLite database and I encountered some error in my ".java" files in the "src" such as "R cannot be resolved to a variable" and an error in my xml at menu folder say that "Error: No resource found that matches the given name (at 'title' with value '@string/action_settings'). database_android_satu.xml /DatabaseAndroid/res/menu line 5 Android AAPT Problem" I deeply gratitude for your kindness of your answer and maybe some advice..

here is my .java files :

package com.db.satu;

    import java.util.ArrayList;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TableLayout;
    import android.widget.TableRow;
    import android.widget.TextView;
    import android.widget.Toast;

    public class DatabaseAndroidSatu extends Activity {
    DatabaseManager dm;
    EditText nama, hobi;
    Button addBtn;
    TableLayout tabel4data;// tabel for data

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    dm = new DatabaseManager(this);
    tabel4data = (TableLayout) findViewById(R.id.tabel_data);
    nama = (EditText) findViewById(R.id.inNama);
    hobi = (EditText) findViewById(R.id.inHobi);
    addBtn = (Button) findViewById(R.id.btnAdd);
    addBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    simpKamuta();
    }
});
    updateTable();
    }

    protected void simpKamuta() {
    try {
    dm.addRow(nama.getText().toString(),hobi.getText().toString());
    Toast.makeText(getBaseContext(),
    nama.getText().toString() + ", berhasil disimpan",
    Toast.LENGTH_SHORT).show();
    updateTable();
    kosongkanField();
    } catch (Exception e) {
    e.printStackTrace();
    Toast.makeText(getBaseContext(), "gagal simpan, " +
        e.toString(),Toast.LENGTH_LONG).show();
    }
    }
    protected void kosongkanField(){
    nama.setText("");
    hobi.setText("");
    }
    protected void updateTable() {
    // TODO Auto-generated method stub
    while (tabel4data.getChildCount() > 1) {
    tabel4data.removeViewAt(1);
    }

    ArrayList<ArrayList<Object>> data = dm.ambilSemuaBaris();//

    for (int posisi = 0; posisi < data.size(); posisi++) {
    TableRow tabelBaris = new TableRow(this);
    ArrayList<Object> baris = data.get(posisi);

    TextView idTxt = new TextView(this);
    idTxt.setText(baris.get(0).toString());
    tabelBaris.addView(idTxt);

    TextView namaTxt = new TextView(this);
    namaTxt.setText(baris.get(1).toString());
    tabelBaris.addView(namaTxt);

    TextView hobiTxt = new TextView(this);
    hobiTxt.setText(baris.get(2).toString());
    tabelBaris.addView(hobiTxt);

    tabel4data.addView(tabelBaris);
    }
}}

here is my .xml files that located in menu folder of the project : its contain an error: "Error: No resource found that matches the given name (at 'title' with value '@string/action_settings'). database_android_satu.xml /DatabaseAndroid/res/menu line 5 Android AAPT Problem"

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.db.satu.DatabaseAndroidSatu" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_settings"/>

</menu>
Roland
  • 127,288
  • 10
  • 191
  • 288
Ethanhunt
  • 23
  • 5

2 Answers2

1

You have to specify <string name="action_settings">Some string</string> in strings.xml file.

michal.z
  • 2,025
  • 1
  • 15
  • 10
0

Oftentimes when R.java is not working properly, it is because you are having an issue in one of your XML files. In this case, your menu.xml file is causing the issue. It states that you are referencing a String named action_settings, but this String has not yet been defined.

To fix this, open your strings.xml file and define a String, using <string name="action_settings">MyString</string>.

Example in response to your comment:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Masukkan nama dan hobi</string>
    <string name="app_name">Database Android #1</string>
    <string name="btnAddtxt">Add</string>
    <string name="namaLabel">Nama</string>
    <string name="hobiLabel">hobi</string>
    <string name="nomorLabel">No.</string>
    <string name="nomorLabel">No.</string>
    <string name="action_settings">Settings</string>
</resources>
RogueBaneling
  • 4,331
  • 4
  • 22
  • 33
  • this is what in my string.xml can you check them? Masukkan nama dan hobi Database Android #1 Add Nama hobi No. No. – Ethanhunt Dec 03 '14 at 16:19
  • Yes, so you need to add in the action_strings. I updated the answer with an example. – RogueBaneling Dec 03 '14 at 16:22
  • anyway why when I'm about to run this app it say unfortunately "app name" has stop. why is it like that? – Ethanhunt Dec 03 '14 at 16:37
  • Check your `LogCat`. It will contain the stack trace that is printed when the application is crashing. However, that sounds like a separate issue and if you need continued assistance with it, it should be posted in a separate question. – RogueBaneling Dec 03 '14 at 16:39