添加微调器后,Android应用程序崩溃

时间:2011-07-04 16:14:54

标签: java android

我在我的Android应用程序中添加了一个微调器,当我在模拟器中运行我的应用程序时崩溃了。在此之前它运行良好。这是我的微调器的代码...... 这是我的班级......

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;
}

这是我的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>

这是我从这里“借来”的代码......

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

我在微调器初始化后添加了一个断点并在调试模式下运行应用程序。调试器运行正常并到达断点,没有错误。但是在断点之后,调试器会冻结并显示...

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) 

我看到了......

image

我读到这意味着我错过了Android源代码。它是否正确?为什么我需要Android源代码? Android SDK不够用吗?还是有其他问题吗?我是Java / Android的新手(已经编程了大约一个星期了)而且我一直在搞乱我的事情所以请原谅我,如果这是一个“noob”问题。 :D谢谢!

以下是我的DDMS中显示正在发生的错误的部分......

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

1 个答案:

答案 0 :(得分:0)

Eclipse尝试访问Android源代码以帮助您调试崩溃。在线有一些指令可以将源附加到Eclipse,但它们非常冗长,最好留作其他地方的练习(我在某些时候使用过http://android.opensourceror.org/2010/01/18/android-source/)。

如果您对崩溃本身有所帮助,可以从DDMS粘贴堆栈跟踪吗? (禁用断点)。