`ArrayAdapter` not working in android 2.1
i have written the following code in my application:
headers = new ArrayAdapter<String>(context,R.layout.yearlistingheader);
where the yearlistingheader.xml
file is as follows:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_header_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:paddingLeft="5dip"
style="@style/compactview"
android:textColor="#ffffff"
android:background="@drawable/mothlistingsectionhead" />
when i try and run my program i get the following error:
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): android.content.res.Resources$NotFoundException: Resource ID #0x7f070045 type #0x12 is not valid
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1874)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.content.res.Resources.getLayout(Resources.java:731)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at com.helios.NauticDates.YearListAdapter.getView(YearListAdapter.java:240)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.widget.ListView.measureHeightOfChildren(ListView.java:1198)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.widget.ListView.onMeasure(ListView.java:1109)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.view.View.measure(View.java:8171)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.view.View.measure(View.java:8171)
05-09 14:52:13.224开发者_StackOverflow社区: ERROR/AndroidRuntime(1032): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.view.View.measure(View.java:8171)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.view.View.measure(View.java:8171)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:578)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:362)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.view.View.measure(View.java:8171)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.view.View.measure(View.java:8171)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.view.View.measure(View.java:8171)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.os.Looper.loop(Looper.java:123)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at java.lang.reflect.Method.invoke(Method.java:521)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-09 14:52:13.224: ERROR/AndroidRuntime(1032): at dalvik.system.NativeStart.main(Native Method)
i am not able to understand which resource is not available. the code on line 238 is the call to getView of this arrayadapter.
Also when i use the default android layout, there seems to be no error. here is the code that gives no error:
headers = new ArrayAdapter<String>(context,android.R.layout.simple_list_item_1);
what is going wrong here? thank you in advance.
Maybe some attribute of your textview is not accessible by the Program
I saw that you called style="@style/style="@style/compactview""
.
Are u sure you have styles.xml in values folder.
If it is make sure you have resource element named "compactview".
Sometimes the Android tooling in eclipse fails to update values in R after changes are made, which can cause error messages like this. Selecting to clean the project fixes it.
精彩评论