私は supportv4 互換性ライブラリを使用しています。アプリのターゲット Api レベルは 17 で、Api レベル 4 でも動作させたいと考えています。アプリを実行すると、API レベル 4 でのみこのエラーが発生します。
03-11 16:16:01.412: E/dalvikvm(302): Could not find method android.view.Display.getSize, referenced from method com.meher.tools.menulauncher.common.MyApplicationContext.setScreenDimensions
03-11 16:16:01.412: W/dalvikvm(302): VFY: unable to resolve virtual method 3065: Landroid/view/Display;.getSize (Landroid/graphics/Point;)V
03-11 16:16:01.412: W/dalvikvm(302): VFY: rejecting opcode 0x6e at 0x0018
03-11 16:16:01.412: W/dalvikvm(302): VFY: rejected Lcom/meher/tools/menulauncher/common/MyApplicationContext;.setScreenDimensions (Landroid/view/Display;)V
03-11 16:16:01.412: W/dalvikvm(302): Verifier rejected class Lcom/meher/tools/menulauncher/common/MyApplicationContext;
03-11 16:16:01.422: D/AndroidRuntime(302): Shutting down VM
03-11 16:16:01.422: W/dalvikvm(302): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
03-11 16:16:01.422: E/AndroidRuntime(302): Uncaught handler: thread main exiting due to uncaught exception
03-11 16:16:01.422: E/AndroidRuntime(302): java.lang.VerifyError: com.meher.tools.menulauncher.common.MyApplicationContext
03-11 16:16:01.422: E/AndroidRuntime(302): at com.meher.tools.menulauncher.MainActivity.onCreate(MainActivity.java:79)
03-11 16:16:01.422: E/AndroidRuntime(302): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
03-11 16:16:01.422: E/AndroidRuntime(302): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
03-11 16:16:01.422: E/AndroidRuntime(302): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
03-11 16:16:01.422: E/AndroidRuntime(302): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
03-11 16:16:01.422: E/AndroidRuntime(302): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
03-11 16:16:01.422: E/AndroidRuntime(302): at android.os.Handler.dispatchMessage(Handler.java:99)
03-11 16:16:01.422: E/AndroidRuntime(302): at android.os.Looper.loop(Looper.java:123)
03-11 16:16:01.422: E/AndroidRuntime(302): at android.app.ActivityThread.main(ActivityThread.java:4203)
03-11 16:16:01.422: E/AndroidRuntime(302): at java.lang.reflect.Method.invokeNative(Native Method)
03-11 16:16:01.422: E/AndroidRuntime(302): at java.lang.reflect.Method.invoke(Method.java:521)
03-11 16:16:01.422: E/AndroidRuntime(302): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
03-11 16:16:01.422: E/AndroidRuntime(302): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
03-11 16:16:01.422: E/AndroidRuntime(302): at dalvik.system.NativeStart.main(Native Method)
03-11 16:16:01.422: I/dalvikvm(302): threadid=7: reacting to signal 3
03-11 16:16:01.422: E/dalvikvm(302): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
これはエラーを発生させるコードです:
MainActivity.java :
// Init application context
myApplicationContext = new MyApplicationContext(this,
getWindowManager().getDefaultDisplay());
MyApplicationContext.java :
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
@SuppressWarnings("deprecation")
public void setScreenDimensions(Display display) {
Point size = new Point();
if (android.os.Build.VERSION.SDK_INT < 13) {
this.screenWidth = display.getWidth();
this.screenHeight = display.getHeight();
} else {
try {
display.getSize(size);
this.screenWidth = size.x;
this.screenHeight = size.y;
} catch (java.lang.NoSuchMethodError ignore) { // Older device
this.screenWidth = display.getWidth();
this.screenHeight = display.getHeight();
}
}
}
AndroidManifest.mf :
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="17" />