Reputation: 6524
Whenever I do, no matter where I call it from, the app crashes with IllegalStateException: could not execute method of the activity. I only have a few classes at the moment, and they're all in the same package, including the class with the static methods causing the crash.
Is there some issue or special consideration that should be taken into account when calling static methods in an Android app?
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
ImageManager.initImageManager(this); // crash
}
EDIT
Apologies, the error is actually a VerifyError. There seems to be some conflict with the Dropbox API, which I'm using in one of the static methods, but which is not called prior to the app crashing. The following is error output after I changed the ImageManager to be an entirely static class, which I think it should be. ImageManager code follows:
01-09 19:23:51.356: W/dalvikvm(32032): VFY: unable to find class referenced in signature (Lcom/dropbox/client2/DropboxAPI;)
01-09 19:23:51.357: I/dalvikvm(32032): Could not find method com.dropbox.client2.DropboxAPI.getFile, referenced from method rfynes.moviebrowser.ImageManager.downloadImage
01-09 19:23:51.357: W/dalvikvm(32032): VFY: unable to resolve virtual method 5140: Lcom/dropbox/client2/DropboxAPI;.getFile (Ljava/lang/String;Ljava/lang/String;Ljava/io/OutputStream;Lcom/dropbox/client2/ProgressListener;)Lcom/dropbox/client2/DropboxAPI$DropboxFileInfo;
01-09 19:23:51.357: D/dalvikvm(32032): VFY: replacing opcode 0x6e at 0x0063
01-09 19:23:51.358: W/dalvikvm(32032): VFY: unable to resolve exception class 735 (Lcom/dropbox/client2/exception/DropboxServerException;)
01-09 19:23:51.358: W/dalvikvm(32032): VFY: unable to find exception handler at addr 0x8b
01-09 19:23:51.358: W/dalvikvm(32032): VFY: rejected Lrfynes/moviebrowser/ImageManager;.downloadImage (Ljava/lang/String;Ljava/io/File;Ljava/lang/String;Lcom/dropbox/client2/DropboxAPI;)V
01-09 19:23:51.358: W/dalvikvm(32032): VFY: rejecting opcode 0x0d at 0x008b
01-09 19:23:51.358: W/dalvikvm(32032): VFY: rejected Lrfynes/moviebrowser/ImageManager;.downloadImage (Ljava/lang/String;Ljava/io/File;Ljava/lang/String;Lcom/dropbox/client2/DropboxAPI;)V
01-09 19:23:51.358: W/dalvikvm(32032): Verifier rejected class Lrfynes/moviebrowser/ImageManager;
01-09 19:23:51.358: D/AndroidRuntime(32032): Shutting down VM
01-09 19:23:51.358: W/dalvikvm(32032): threadid=1: thread exiting with uncaught exception (group=0x41672898)
01-09 19:23:51.361: E/AndroidRuntime(32032): FATAL EXCEPTION: main
01-09 19:23:51.361: E/AndroidRuntime(32032): java.lang.VerifyError: rfynes/moviebrowser/ImageManager
01-09 19:23:51.361: E/AndroidRuntime(32032): at rfynes.moviebrowser.MainActivity.onCreate(MainActivity.java:16)
01-09 19:23:51.361: E/AndroidRuntime(32032): at android.app.Activity.performCreate(Activity.java:5150)
01-09 19:23:51.361: E/AndroidRuntime(32032): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-09 19:23:51.361: E/AndroidRuntime(32032): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2192)
01-09 19:23:51.361: E/AndroidRuntime(32032): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2288)
01-09 19:23:51.361: E/AndroidRuntime(32032): at android.app.ActivityThread.access$600(ActivityThread.java:148)
01-09 19:23:51.361: E/AndroidRuntime(32032): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1273)
01-09 19:23:51.361: E/AndroidRuntime(32032): at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 19:23:51.361: E/AndroidRuntime(32032): at android.os.Looper.loop(Looper.java:137)
01-09 19:23:51.361: E/AndroidRuntime(32032): at android.app.ActivityThread.main(ActivityThread.java:5222)
01-09 19:23:51.361: E/AndroidRuntime(32032): at java.lang.reflect.Method.invokeNative(Native Method)
01-09 19:23:51.361: E/AndroidRuntime(32032): at java.lang.reflect.Method.invoke(Method.java:525)
01-09 19:23:51.361: E/AndroidRuntime(32032): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-09 19:23:51.361: E/AndroidRuntime(32032): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-09 19:23:51.361: E/AndroidRuntime(32032): at dalvik.system.NativeStart.main(Native Method)
ImageManager
public class ImageManager {
private File posterDir, backdropDir;
public static void initImageManager(Activity activity) {
posterDir = activity.getDir("poster", Context.MODE_PRIVATE);
backdropDir = activity.getDir("backdrop", Context.MODE_PRIVATE);
}
...
...
public static void downloadImage(String movieId, File imageDir, String imageType, DropboxAPI<AndroidAuthSession> dropbox) {
...
...
Upvotes: 0
Views: 727
Reputation: 6524
To fix this, I actually ended up breaking the downloadImage method (and a couple others) out of the ImageManager class into their own separate non-static class. The ImageManager is still a static class now, but it's not causing any problems and the app is not crashing. So, it appears that the problem was the Dropbox API call(s) that I was making from a static context, but I don't know why exactly. I'm happy enough with what I've got now, though.
Upvotes: 1