Robby
Robby

Reputation: 11

error parsing XML: No element found. and it won't generate R.java because of it

I am getting a parsing error and I do not know why (I am new to programing). Because of this error, R.java disappears and I end up having more errors. Hopefully someone can help me out. Here is where the error comes from: list.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"
    android:orientation="vertical"
    >
  <ListView android:id="@+id/ListView01" android:layout_height="wrap_content"
  android:layout_width="fill_parent">
  <TextView android:text="@+id/TextView01" android:id="@+id/TextView01"
  android:layout_width="wrap_content" android:layout_height="wrap_content"
  android:layout_marginLeft="10px" android:textColor="#0099CC"></TextView>

 </ListView>

</LinearLayout>

and here is where the xml file is called: list.java

package com.aha;

import java.util.HashMap;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.SimpleAdapter;
import android.widget.SimpleAdapter.ViewBinder; 
import android.widget.Adapter; 
import android.widget.BaseAdapter; 

public class list extends ListActivity {

  private HashMap<String, Class<?>> yourMap;
  @Override
  public void onCreate(Bundle b) {
   yourMap = new HashMap<String, Class<?>>();
   yourMap.put("Matches", matches.class);
   yourMap.put("Economy", finances.class);
  }

  public void onCreate1(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String[] menu = getResources().getStringArray(R.array.menu_array);
    setListAdapter(new ArrayAdapter<String>(this, R.layout.list, menu));

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(new OnItemClickListener() {
      public <View> void onItemClick(AdapterView<?> parent, View view,
          int position, long id) {
        // When clicked, show a toast with the TextView text
             Object o = this.getListAdapter().getItem(position);
             String keyword = o.toString();
             Intent intent = new Intent(this, yourMap.get(keyword));
             startActivity(intent);

      }
    });
  }
 }

also at this line I am getting an error saying I must implement an abstract method :

    lv.setOnItemClickListener(new OnItemClickListener() {

I am just wondering what this means, not necessarily a solution. Hopefully I can figure that one out on my own. The parsing error I have had for a day or two and can't figure it out alone.

Thanks for any help

Upvotes: 1

Views: 12487

Answers (5)

tonsit
tonsit

Reputation: 1

Take the following steps:

  1. Save and Close .xml
  2. Delete .out.xml and/or .out.out.xml
  3. Click Project in the menu and select Clean...
  4. Select radio button for 'Clean selected projects below'
  5. Click check box for your project, and click OK
  6. Run your program.

Upvotes: 0

Lalit Poptani
Lalit Poptani

Reputation: 67286

Your problem seems to be in the layout file itself,

you have added TextView inside the ListView tag in the layout file. Just move the TextView outside the ListView.

Your layout file should be like this,

<?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:orientation="vertical"
    >
  <ListView android:id="@+id/ListView01" android:layout_height="wrap_content"
  android:layout_width="fill_parent">
  </ListView>

  <TextView android:text="@+id/TextView01" android:id="@+id/TextView01"
  android:layout_width="wrap_content" android:layout_height="wrap_content"
  android:layout_marginLeft="10px" android:textColor="#0099CC"></TextView>

</LinearLayout>

Upvotes: 0

deepkimo
deepkimo

Reputation: 3197

I had a similar problem and it turned out because Eclipse added "import android.R;" (this can happen if you tend to use Ctrl-Shift-O for importing files) in my .java file hiding declarations in R.java. After removing this import line, R.java was seen again as expected.

Upvotes: 0

Pentium10
Pentium10

Reputation: 207863

ListView should have no child elements, use an adapter instead.

Upvotes: 1

yoav.str
yoav.str

Reputation: 1542

what is the editor you are using?

from my experiences parsing problems in eclipse are caused by one of the next

  1. your view name is camel case *Don't use A use a NO CAPSLOCK *
  2. the R file is not "refreshed " and therefore new elements doesn't appear

try to

  1. write the *.xml (in view folder ) in small letters.
  2. clean all the project and then build
  3. maybe you didnt declared the project properly notice for this table for the SDK version

please inform me for the actual err (written in the console ) for farther help .

Upvotes: 0

Related Questions