2012-11-02 87 views
2
@Override 
public boolean onOptionsItemSelected(MenuItem item) {  
RelativeLayout screen = (RelativeLayout) findViewById(R.id.RelativeLayout01); 
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    switch (item.getItemId()) { 
    case R.id.menu_control: { 
    inflater.inflate(R.layout.adv_video, screen, true); 
    adapter = new ArrayAdapter<String>(screen.getContext(), R.id.spinner1, new String[]{"Author","ISBN","Keyword","Title"}); 
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
spinner = (Spinner) screen.findViewById(R.id.spinner1); 
spinner.setAdapter(adapter); 

進一步在代碼按鈕,edittext等如果評論spinner.setAdapter(adapter); - 一切正常,與空的微調列表。

這裏的日誌:

logcat: 
11-02 14:02:01.735: E/AndroidRuntime(1865): FATAL EXCEPTION: main 
11-02 14:02:01.735: E/AndroidRuntime(1865): android.content.res.Resources$NotFoundException: Resource ID #0x7f06000e type #0x12 is not valid 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:1874) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.content.res.Resources.getLayout(Resources.java:731) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.view.LayoutInflater.inflate(LayoutInflater.java:318) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:192) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.view.View.measure(View.java:8173) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1015) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.TableRow.measureChildBeforeLayout(TableRow.java:243) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:699) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.TableRow.onMeasure(TableRow.java:112) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.view.View.measure(View.java:8173) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1015) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:384) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:307) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.view.View.measure(View.java:8173) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1015) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:699) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:309) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.view.View.measure(View.java:8173) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:581) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:365) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.view.View.measure(View.java:8173) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.view.View.measure(View.java:8173) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.view.View.measure(View.java:8173) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.view.ViewRoot.performTraversals(ViewRoot.java:801) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1727) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.os.Handler.dispatchMessage(Handler.java:99) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.os.Looper.loop(Looper.java:123) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at java.lang.reflect.Method.invokeNative(Native Method) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at java.lang.reflect.Method.invoke(Method.java:521) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
11-02 14:02:01.735: E/AndroidRuntime(1865):  at dalvik.system.NativeStart.main(Native Method) 
11-02 14:02:01.743: W/ActivityManager(1306): Force finishing activity de.mjpegsample/.MjpegSample 
+1

請從logcat發佈日誌... –

+0

您應該將此更改爲特定問題,而不是僅發佈錯誤日誌。 – Boeckm

回答

5

代替提供佈局文件爲ArrayAdapter使用的ID,您設置的SpinnerR.id.spinner1)的ID。該ArrayAdapter實例應該是這樣的:

adapter = new ArrayAdapter<String>(screen.getContext(), android.R.layout.simple_spinner_item, new String[]{"Author","ISBN","Keyword","Title"}); 

,或者提供其他配置文件(R.layout.layout_file_name)所組成的只有一個TextViewid

相關問題