简体   繁体   中英

android app craches after adding spinner

I've added a spinner to my android app and when I run my app in the emulator it crashes. Prior to that it ran fine. Here is my code for the spinner... This is in my class...

public void populateSpinners(){
    Spinner spinner = (Spinner) findViewById(R.id.spinner1);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
            this, R.array.planets_array, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);


    return;
}

This is in my string.xml...

<string name="planet_prompt">Choose a planet</string>
<string-array name="planets_array">
    <item>Mercury</item>
    <item>Venus</item>
    <item>Earth</item>
    <item>Mars</item>
    <item>Jupiter</item>
    <item>Saturn</item>
    <item>Uranus</item>
    <item>Neptune</item>
</string-array>

This is code I "borrowed" from here...

http://developer.android.com/resources/tutorials/views/hello-spinner.html

I added a break point after the spinner was initilazed and ran the app in debug mode. The debugger runs fine and reaches the breakpoint with no errors. However after the breakpoint, the debugger freezes and shows this...

myapp [Android Application] 
myapp [Android Application] 
    DalvikVM[localhost:8615]    
        Thread [<1> main] (Suspended (exception Resources$NotFoundException))   
            Resources.loadXmlResourceParser(int, String) line: 1877 
            Resources.getLayout(int) line: 731  
            PhoneLayoutInflater(LayoutInflater).inflate(int, ViewGroup, boolean) line: 318  
            ArrayAdapter.createViewFromResource(int, View, ViewGroup, int) line: 332    
            ArrayAdapter.getView(int, View, ViewGroup) line: 323    
            Spinner(AbsSpinner).onMeasure(int, int) line: 192   
            Spinner(View).measure(int, int) line: 8171  
            TableRow.getColumnsWidths(int) line: 308    
            TableLayout.findLargestCells(int) line: 497 
            TableLayout.measureVertical(int, int) line: 462 
            TableLayout.onMeasure(int, int) line: 428   
            TableLayout(View).measure(int, int) line: 8171  
            LinearLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 3132    
            LinearLayout.measureChildBeforeLayout(View, int, int, int, int, int) line: 1012 
            LinearLayout.measureVertical(int, int) line: 381    
            LinearLayout.onMeasure(int, int) line: 304  
            LinearLayout(View).measure(int, int) line: 8171 
            FrameLayout(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 3132 
            FrameLayout.onMeasure(int, int) line: 245   
            FrameLayout(View).measure(int, int) line: 8171  
            LinearLayout.measureVertical(int, int) line: 526    
            LinearLayout.onMeasure(int, int) line: 304  
            LinearLayout(View).measure(int, int) line: 8171 
            PhoneWindow$DecorView(ViewGroup).measureChildWithMargins(View, int, int, int, int) line: 3132   
            PhoneWindow$DecorView(FrameLayout).onMeasure(int, int) line: 245    
            PhoneWindow$DecorView(View).measure(int, int) line: 8171    
            ViewRoot.performTraversals() line: 801  
            ViewRoot.handleMessage(Message) line: 1727  
            ViewRoot(Handler).dispatchMessage(Message) line: 99 
            Looper.loop() line: 123 
            ActivityThread.main(String[]) line: 4627    
            Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
            Method.invoke(Object, Object...) line: 521  
            ZygoteInit$MethodAndArgsCaller.run() line: 868  
            ZygoteInit.main(String[]) line: 626 
            NativeStart.main(String[]) line: not available [native method]  
        Thread [<6> Binder Thread #2] (Running) 
        Thread [<5> Binder Thread #1] (Running) 

And I see this....

图片

I read that it means I'm missing the Android source. Is this correct? Why do I need the Android source? Isn't the Android SDK enough? Or is there some other problem? I'm new to Java/Android (been programming for about a week now) and I've been muddling my way through things so please excuse me if this is a "noob" question. :D Thanks!

Here are the parts of my DDMS that show the error that is occurring...

07-04 16:57:19.063: DEBUG/dalvikvm(134): GC_EXPLICIT freed 4275 objects / 210048 bytes in 124ms
07-04 16:57:23.311: DEBUG/AndroidRuntime(309): Shutting down VM
07-04 16:57:23.311: WARN/dalvikvm(309): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-04 16:57:23.651: ERROR/AndroidRuntime(309): FATAL EXCEPTION: main
07-04 16:57:23.651: ERROR/AndroidRuntime(309): android.content.res.Resources$NotFoundException: File res/layout/simple_spinner_item.xml from xml type layout resource ID #0x1090008
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.content.res.Resources.loadXmlResourceParser(Resources.java:1916)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.content.res.Resources.loadXmlResourceParser(Resources.java:1871)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.content.res.Resources.getLayout(Resources.java:731)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:192)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.view.View.measure(View.java:8171)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.widget.TableRow.getColumnsWidths(TableRow.java:308)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.widget.TableLayout.findLargestCells(TableLayout.java:497)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.widget.TableLayout.measureVertical(TableLayout.java:462)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.widget.TableLayout.onMeasure(TableLayout.java:428)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.view.View.measure(View.java:8171)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.view.View.measure(View.java:8171)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.view.View.measure(View.java:8171)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.view.View.measure(View.java:8171)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.view.View.measure(View.java:8171)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.os.Looper.loop(Looper.java:123)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.app.ActivityThread.main(ActivityThread.java:4627)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at java.lang.reflect.Method.invokeNative(Native Method)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at java.lang.reflect.Method.invoke(Method.java:521)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at dalvik.system.NativeStart.main(Native Method)
07-04 16:57:23.651: ERROR/AndroidRuntime(309): Caused by: java.lang.RuntimeException: Assetmanager has been closed
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:483)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     at android.content.res.Resources.loadXmlResourceParser(Resources.java:1898)
07-04 16:57:23.651: ERROR/AndroidRuntime(309):     ... 36 more
07-04 16:57:23.912: WARN/ActivityManager(58):   Force finishing activity com.newapp.practice.app/.myappActivity
07-04 16:57:24.461: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{44f86260 com.newapp.practice.app/.myappActivity}
07-04 16:57:31.261: DEBUG/dalvikvm(187): GC_EXPLICIT freed 110 objects / 4680 bytes in 117ms
07-04 16:57:36.003: WARN/ActivityManager(58): Activity destroy timeout for HistoryRecord{44f86260 com.newapp.practice.app/.myappActivity}
07-04 16:57:36.422: DEBUG/dalvikvm(261): GC_EXPLICIT freed 755 objects / 54824 bytes in 209ms

Eclipse tries to access the Android source in order to help you debug the crash. There are some instructions online to attach the source to Eclipse, but they're quite long-winded, and best left as an exercise for elsewhere (I used http://android.opensourceror.org/2010/01/18/android-source/ at some point).

If you'd like some help with the crash itself, can you paste the stacktrace from DDMS? (With the breakpoints disabled).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM