1

I am trying to populate a listview from the string resources defined in the string XML file in Android. I am not getting any errors but when I run the application it asks me to force close. I am getting the following error in log cat manager 03-26 01:04:42.903: E/dalvikvm(205): Unable to open stack trace file '/data/anr/traces.txt': Permission denied

Here is the code for my program

public class MainMenu extends Activity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu);

    /*ListView menu = (ListView) findViewById(R.id.ListView_Menu);

    String[] items = { getResources().getString(R.string.today_bd),getResources().getString(R.string.Add_bd),
            getResources().getString(R.string.msg_tmplate),getResources().getString(R.string.credits),
            getResources().getString(R.string.help)
    };

    ArrayAdapter<String> adapt = new ArrayAdapter<String>(this,R.layout.menu,items);

    menu.setAdapter(adapt);*/
    ListView menuList = (ListView) findViewById(R.id.ListView_Menu);
    String[] items = { getResources().getString(R.string.today_bd),
            getResources().getString(R.string.add_bd),
            getResources().getString(R.string.msg_tmplate),
            getResources().getString(R.string.credits),
            getResources().getString(R.string.help)
            };

    ArrayAdapter<String> adapt = new ArrayAdapter<String>(this, R.layout.menu, items);
    menuList.setAdapter(adapt);
    menuList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) {

            TextView textView = (TextView) itemClicked;
            String strText = textView.getText().toString();
            if (strText.equalsIgnoreCase(getResources().getString(R.string.today_bd))) {

                //startActivity(new Intent(QuizMenuActivity.this, QuizGameActivity.class));
            } else if (strText.equalsIgnoreCase(getResources().getString(R.string.add_bd))) {
                // Launch the Help Activity
                //startActivity(new Intent(QuizMenuActivity.this, QuizHelpActivity.class));
            } else if (strText.equalsIgnoreCase(getResources().getString(R.string.msg_tmplate))) {
                // Launch the Settings Activity
                //startActivity(new Intent(QuizMenuActivity.this, QuizSettingsActivity.class));
            } else if (strText.equalsIgnoreCase(getResources().getString(R.string.credits))) {
                // Launch the Scores Activity
               // startActivity(new Intent(QuizMenuActivity.this, QuizScoresActivity.class));
            }
            else if (strText.equalsIgnoreCase(getResources().getString(R.string.help))) {
                // Launch the Scores Activity
               // startActivity(new Intent(QuizMenuActivity.this, QuizScoresActivity.class));
            }
        }


        //public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                //long arg3) {
            // TODO Auto-generated method stub

        //}
    });




}

}

Please help!!!

3
  • in AndroidMenifest did you added specified permission to read/write external files? Commented Mar 25, 2012 at 20:17
  • try adb logcat to get your stack trace Commented Mar 25, 2012 at 22:07
  • and provide your R.layout.menu .. the layout certainly causes the error. You do not use a standard layout so your custom layout must only consist of a TextView Commented Mar 25, 2012 at 22:15

2 Answers 2

2

the ArrayAdapter constructor you're calling takes three arguments -- you've got the first and third right, but the second one wants to be the item layout.

textViewResourceId The resource ID for a layout file containing a TextView to use when instantiating views.

try using android.R.layout.simple_list_item_1 and that should help...

ArrayAdapter<String> adapt = 
  new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);

ref: javadoc

Sign up to request clarification or add additional context in comments.

Comments

0

I tried with the method given above and it didn't seem to work. Here is my menu.xml file

<?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"
android:baselineAligned="false"
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="50dip"
    android:layout_weight="0.00" >

     <TextView
        android:id="@+id/TextView01"
        android:layout_height="wrap_content"
        android:text="@string/main_menu"
        android:textSize="@dimen/screen_title_size"
        android:shadowDx="0"
        android:shadowDy="0"
        android:shadowRadius="10"
        android:layout_width="wrap_content"
        android:layout_gravity="fill_horizontal|center"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:shadowColor="@android:color/white"
        android:textColor="@color/title_color"></TextView>
</RelativeLayout>

<ListView
    android:id="@+id/listView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.00" >
</ListView>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.