麻烦使用Android简单文件选择器

时间:2015-12-13 15:27:01

标签: java android dialog

我尝试使用此处提供的简单文件选择器: http://www.ninthavenue.com.au/simple-android-file-chooser

为了让它发挥作用,我打电话给我的主要活动:

new FileChooser(myactivity.this).setFileListener(new FileSelectedListener() {
@Override public void fileSelected(final File file) {
    // do something with the file
}).showDialog();

我已经添加了类并引用了它 - 它编译好了 - 但它崩溃了:  java.lang.IllegalStateException:无法执行活动的方法

我对这个问题出了什么想法?

非常感谢

编辑:完整logcat

12-13 13:35:05.995 11029-11029/com.test.project E/AndroidRuntime: FATAL EXCEPTION: main
                                                                Process: com.test.project, PID: 11029
                                                                java.lang.IllegalStateException: Could not execute method of the activity
                                                                    at android.view.View$1.onClick(View.java:4020)
                                                                    at android.view.View.performClick(View.java:4780)
                                                                    at android.widget.CompoundButton.performClick(CompoundButton.java:120)
                                                                    at android.view.View$PerformClick.run(View.java:19866)
                                                                    at android.os.Handler.handleCallback(Handler.java:739)
                                                                    at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                    at android.os.Looper.loop(Looper.java:135)
                                                                    at android.app.ActivityThread.main(ActivityThread.java:5257)
                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                    at java.lang.reflect.Method.invoke(Method.java:372)
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
                                                                 Caused by: java.lang.reflect.InvocationTargetException
                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                    at java.lang.reflect.Method.invoke(Method.java:372)
                                                                    at android.view.View$1.onClick(View.java:4015)
                                                                    at android.view.View.performClick(View.java:4780) 
                                                                    at android.widget.CompoundButton.performClick(CompoundButton.java:120) 
                                                                    at android.view.View$PerformClick.run(View.java:19866) 
                                                                    at android.os.Handler.handleCallback(Handler.java:739) 
                                                                    at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                    at android.os.Looper.loop(Looper.java:135) 
                                                                    at android.app.ActivityThread.main(ActivityThread.java:5257) 
                                                                    at java.lang.reflect.Method.invoke(Native Method) 
                                                                    at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
                                                                 Caused by: java.lang.NullPointerException: Attempt to get length of null array
                                                                    at com.test.project.FileChooser.refresh(FileChooser.java:103)
                                                                    at com.test.project.FileChooser.<init>(FileChooser.java:62)
                                                                    at com.test.project.myactivity.onToggleClickedPlayback(myactivity.java:1200)
                                                                    at java.lang.reflect.Method.invoke(Native Method) 
                                                                    at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                    at android.view.View$1.onClick(View.java:4015) 
                                                                    at android.view.View.performClick(View.java:4780) 
                                                                    at android.widget.CompoundButton.performClick(CompoundButton.java:120) 
                                                                    at android.view.View$PerformClick.run(View.java:19866) 
                                                                    at android.os.Handler.handleCallback(Handler.java:739) 
                                                                    at android.os.Handler.dispatchMessage(Handler.java:95) 
                                                                    at android.os.Looper.loop(Looper.java:135) 
                                                                    at android.app.ActivityThread.main(ActivityThread.java:5257) 
                                                                    at java.lang.reflect.Method.invoke(Native Method) 
                                                                    at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

12-13

1 个答案:

答案 0 :(得分:0)

发现问题 - 是因为模拟器上的文件系统是空的,在真实设备上工作正常 - 会调整代码来处理!