以下代码在ICS上正确运行,但当我尝试使用Gingerbread时,它生成了一个错误
AlertDialog.Builder alert3 = new AlertDialog.Builder(ReadingClass.this);
alert3.setIcon(R.drawable.pwi);
alert3.setTitle("Primewater");
alert3.setMessage("Meter Reading");
final Context context3 = alert3.getContext();
// Set an EditText view to get user input
final LinearLayout layout3 = new LinearLayout(context3);
logcat堆栈跟踪如下
06-10 11:39:19.459: E/AndroidRuntime(7922): FATAL EXCEPTION: main
06-10 11:39:19.459: E/AndroidRuntime(7922): java.lang.NoSuchMethodError: android.app.AlertDialog$Builder.getContext
06-10 11:39:19.459: E/AndroidRuntime(7922): at com.primereader.ReadingClass.onClick(ReadingClass.java:173)
06-10 11:39:19.459: E/AndroidRuntime(7922): at android.view.View.performClick(View.java:2485)
06-10 11:39:19.459: E/AndroidRuntime(7922): at android.view.View$PerformClick.run(View.java:9080)
06-10 11:39:19.459: E/AndroidRuntime(7922): at android.os.Handler.handleCallback(Handler.java:587)
06-10 11:39:19.459: E/AndroidRuntime(7922): at android.os.Handler.dispatchMessage(Handler.java:92)
06-10 11:39:19.459: E/AndroidRuntime(7922): at android.os.Looper.loop(Looper.java:130)
06-10 11:39:19.459: E/AndroidRuntime(7922): at android.app.ActivityThread.main(ActivityThread.java:3687)
06-10 11:39:19.459: E/AndroidRuntime(7922): at java.lang.reflect.Method.invokeNative(Native Method)
06-10 11:39:19.459: E/AndroidRuntime(7922): at java.lang.reflect.Method.invoke(Method.java:507)
06-10 11:39:19.459: E/AndroidRuntime(7922): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
06-10 11:39:19.459: E/AndroidRuntime(7922): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
06-10 11:39:19.459: E/AndroidRuntime(7922): at dalvik.system.NativeStart.main(Native Method)