Reputation: 11
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
Reputation: 1
Take the following steps:
Upvotes: 0
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
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
Reputation: 207863
ListView should have no child elements, use an adapter instead.
Upvotes: 1
Reputation: 1542
what is the editor you are using?
from my experiences parsing problems in eclipse are caused by one of the next
try to
please inform me for the actual err (written in the console ) for farther help .
Upvotes: 0