我正在尝试在 AlertBox 中填充 XML(Layout)。
这是我要膨胀的 XML...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/update_information" />
<CheckBox
android:id="@+id/chbDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Don't Show Again"
android:checked="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel" />
<Button
android:id="@+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok" />
</LinearLayout>
</LinearLayout>
这是我用来膨胀 XML 的代码...
private void display_Update_Info() {
// TODO Auto-generated method stub
LayoutInflater in = new LayoutInflater(this) {
@Override
public LayoutInflater cloneInContext(Context newContext) {
// TODO Auto-generated method stub
return null;
}//This code is auto generated. I have no idea what is this...
};
final View update = in.inflate(R.layout.updateinformation, null);
AlertDialog.Builder updateInfo = new Builder(this);
updateInfo.setView(update);
updateInfo.show();
}
这是 Logcat 跟踪...
03-12 16:15:38.929: E/AndroidRuntime(9021): FATAL EXCEPTION: main
03-12 16:15:38.929: E/AndroidRuntime(9021): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobilevoiceapps.advancedvoicecalculatorfree/com.mobilevoiceapps.advancedvoicecalculatorfree.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class CheckBox
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.os.Handler.dispatchMessage(Handler.java:99)
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.os.Looper.loop(Looper.java:130)
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-12 16:15:38.929: E/AndroidRuntime(9021): at java.lang.reflect.Method.invokeNative(Native Method)
03-12 16:15:38.929: E/AndroidRuntime(9021): at java.lang.reflect.Method.invoke(Method.java:507)
03-12 16:15:38.929: E/AndroidRuntime(9021): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
03-12 16:15:38.929: E/AndroidRuntime(9021): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
03-12 16:15:38.929: E/AndroidRuntime(9021): at dalvik.system.NativeStart.main(Native Method)
03-12 16:15:38.929: E/AndroidRuntime(9021): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class CheckBox
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
03-12 16:15:38.929: E/AndroidRuntime(9021): at com.mobilevoiceapps.advancedvoicecalculatorfree.MainActivity.display_Update_Info(MainActivity.java:469)
03-12 16:15:38.929: E/AndroidRuntime(9021): at com.mobilevoiceapps.advancedvoicecalculatorfree.MainActivity.onCreate(MainActivity.java:160)
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-12 16:15:38.929: E/AndroidRuntime(9021): ... 11 more
03-12 16:15:38.929: E/AndroidRuntime(9021): Caused by: java.lang.ClassNotFoundException: android.view.CheckBox in loader dalvik.system.PathClassLoader[/data/app/com.mobilevoiceapps.advancedvoicecalculatorfree-1.apk]
03-12 16:15:38.929: E/AndroidRuntime(9021): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
03-12 16:15:38.929: E/AndroidRuntime(9021): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
03-12 16:15:38.929: E/AndroidRuntime(9021): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
03-12 16:15:38.929: E/AndroidRuntime(9021): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
03-12 16:15:38.929: E/AndroidRuntime(9021): ... 19 more
另外,如果有人可以告诉我,自动生成的代码有什么用...
@Override
public LayoutInflater cloneInContext(Context newContext) {
// TODO Auto-generated method stub
return null;
}
当我尝试运行应用程序时,我被强制关闭...