I have an activity that has a Button. When the Button is clicked it is supposed to open a simple Popup Window that contains a TextView and a Spinner. I have the Popup Window opening up fine. My problem is when I grab a reference to the Spinner it's giving me a Resources$NotFoundException and saying that the resource ID is not valid.
I'm currently calling popupView.findViewById(R.layout.popup_create_workout) to try to get a reference to the spinner. I've also tried grabbing a reference to the parent XML layout that the Popup Window uses and invoking finViewById on it (e.g. exampleView.findViewById(R.layout.example_popup_view). I also tried plain ol' findViewById(R.layout.example_popup_view) (which I wasn't expecting to work). However, both of these techniques throw NullPointerExceptions either on the View ID or when I call setAdapter() on the Spinner. I've tried cleaning the project in Eclipse, double checked to make sure the I'm using the right reference IDs, context, etc.
What's really throwing me for a loop is that I am able to get references to the TextView from the same XML layout and manipulate it. I've searched all over this site and found somewhat similar questions, but none of them were quite what I needed. I've also Googled everything that I could think of with no luck.
So, my qeustion is: why am I getting a Resources$NotFoundException when I try to get a reference to the spinner? I know it's probably something easy, but I can't seem to figure it out. Thanks in advance for your help!
Here's the part of the activity that has to do with the spinner:
@Override
public void onClick(View v) {
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = inflater.inflate(R.layout.popup_add_goal, null);
PopupWindow popupWindow = new PopupWindow(popupView);
popupWindow.setWidth(240);
popupWindow.setHeight(447);
popupWindow.update();
popupWindow.showAtLocation(v, Gravity.CENTER, 0, 0);
ArrayList<String> list = new ArrayList<String>();
list.add("Item 1");
list.add("Item 2");
list.add("Item 3");
Spinner spinner = (Spinner) popupView.findViewById(R.id.goal_spinner);
ArrayAdapter<ArrayList<String>> arrayAdapter = new ArrayAdapter<ArrayList<String>>(WorkoutActivity.context, R.id.list_content_white);
arrayAdapter.add(list);
spinner.setAdapter(arrayAdapter);
}
});
And the XML layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#CCff0000" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Add goals"
android:textColor="#ffffff"
android:textSize="48sp" />
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="Search for a goal"
android:textColor="#ffffff"
android:textSize="40sp"
android:gravity="center" />
<Spinner android:id="@+id/goal_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff" />
</LinearLayout>
And finally, the stack trace:
12-29 03:51:14.832: E/AndroidRuntime(5216): FATAL EXCEPTION: main
12-29 03:51:14.832: E/AndroidRuntime(5216): android.content.res.Resources$NotFoundException: Resource ID #0x7f09001a type #0x12 is not valid
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.content.res.Resources.loadXmlResourceParser(Resources.java:2144)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.content.res.Resources.getLayout(Resources.java:853)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:371)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:193)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.widget.Spinner.onMeasure(Spinner.java:439)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.view.View.measure(View.java:15513)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.view.View.measure(View.java:15513)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.view.View.measure(View.java:15513)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.view.Choreographer.doFrame(Choreographer.java:532)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.os.Handler.handleCallback(Handler.java:725)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.os.Handler.dispatchMessage(Handler.java:92)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.os.Looper.loop(Looper.java:137)
12-29 03:51:14.832: E/AndroidRuntime(5216): at android.app.ActivityThread.main(ActivityThread.java:5039)
12-29 03:51:14.832: E/AndroidRuntime(5216): at java.lang.reflect.Method.invokeNative(Native Method)
12-29 03:51:14.832: E/AndroidRuntime(5216): at java.lang.reflect.Method.invoke(Method.java:511)
12-29 03:51:14.832: E/AndroidRuntime(5216): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-29 03:51:14.832: E/AndroidRuntime(5216): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-29 03:51:14.832: E/AndroidRuntime(5216): at dalvik.system.NativeStart.main(Native Method)
Here's the layout that contains list_content_white:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/list_content_white"
android:textColor="#ffffff"
android:textSize="30sp"
android:textStyle="bold"
android:layout_margin="8dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>