我正在创建相对布局,它看起来很好,当时没有给出任何错误。但是当我尝试运行此应用程序时,我在运行时遇到错误,如下所述。
错误是:
07-03 23:04:55.420: D/AndroidRuntime(20456): Shutting down VM
07-03 23:04:55.430: W/dalvikvm(20456): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-03 23:04:55.491: E/AndroidRuntime(20456): FATAL EXCEPTION: main
07-03 23:04:55.491: E/AndroidRuntime(20456): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.customdialog/com.customdialog.CustomDialogExample}: android.view.InflateException: Binary XML file line #3: Error inflating class android.widget.RelativeLayout
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.os.Handler.dispatchMessage(Handler.java:99)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.os.Looper.loop(Looper.java:123)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-03 23:04:55.491: E/AndroidRuntime(20456): at java.lang.reflect.Method.invokeNative(Native Method)
07-03 23:04:55.491: E/AndroidRuntime(20456): at java.lang.reflect.Method.invoke(Method.java:521)
07-03 23:04:55.491: E/AndroidRuntime(20456): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-03 23:04:55.491: E/AndroidRuntime(20456): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-03 23:04:55.491: E/AndroidRuntime(20456): at dalvik.system.NativeStart.main(Native Method)
07-03 23:04:55.491: E/AndroidRuntime(20456): Caused by: android.view.InflateException: Binary XML file line #3: Error inflating class android.widget.RelativeLayout
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
07-03 23:04:55.491: E/AndroidRuntime(20456): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-03 23:04:55.491: E/AndroidRuntime(20456): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.app.Dialog.setContentView(Dialog.java:421)
07-03 23:04:55.491: E/AndroidRuntime(20456): at com.customdialog.CustomizeDialog.<init>(CustomizeDialog.java:24)
07-03 23:04:55.491: E/AndroidRuntime(20456): at com.customdialog.CustomDialogExample.onCreate(CustomDialogExample.java:16)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-03 23:04:55.491: E/AndroidRuntime(20456): ... 11 more
07-03 23:04:55.491: E/AndroidRuntime(20456): Caused by: java.lang.reflect.InvocationTargetException
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.widget.RelativeLayout.<init>(RelativeLayout.java:170)
07-03 23:04:55.491: E/AndroidRuntime(20456): at java.lang.reflect.Constructor.constructNative(Native Method)
07-03 23:04:55.491: E/AndroidRuntime(20456): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
07-03 23:04:55.491: E/AndroidRuntime(20456): ... 22 more
07-03 23:04:55.491: E/AndroidRuntime(20456): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f06000b a=-1 r=0x7f06000b}
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.content.res.Resources.loadDrawable(Resources.java:1681)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.view.View.<init>(View.java:1885)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.view.View.<init>(View.java:1834)
07-03 23:04:55.491: E/AndroidRuntime(20456): at android.view.ViewGroup.<init>(ViewGroup.java:285)
07-03 23:04:55.491: E/AndroidRuntime(20456): ... 26 more
这是我的 CustomDialogExample 类。
public class CustomDialogExample extends Activity {
/** Called when the activity is first created. */
CustomizeDialog customizeDialog;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** Display Custom Dialog */
customizeDialog = new CustomizeDialog(CustomDialogExample.this);
Log.i("Log", "show method called");
customizeDialog.show();
}
}
这是创建对话框的 CustomizeDialog.class。
public class CustomizeDialog extends Dialog{
Button dialogButtonYes;
Button dialogButtonNo;
TextView textView,titleText,customtitle;
public CustomizeDialog(Context context){
super(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
/** Design the dialog in main.xml file */
setContentView(R.layout.relative);
dialogButtonYes = (Button) findViewById(R.id.buttonCustomDialogYes);
dialogButtonNo = (Button) findViewById(R.id.buttonCustomDialogNo);
textView = (TextView) findViewById(R.id.textViewCustomTitle);
//customtitle.setText(title);
textView.setText("ffg");
}
}
而relative.xml布局xml文件为:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@style/HeadingTheme"
android:layout_centerHorizontal="true" >
<TextView
android:id="@+id/textViewCustomTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="ABCD"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textViewCustomTitle"
android:orientation="horizontal"
android:paddingBottom="1.0dip"
android:paddingLeft="4.0dip"
android:paddingRight="4.0dip"
android:paddingTop="5.0dip" >
<Button
android:id="@+id/buttonCustomDialogYes"
android:layout_width="0.0dp"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:text="Yes" />
<Button
android:id="@+id/buttonCustomDialogNo"
android:layout_width="0.0dp"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:text="No" />
</LinearLayout>
</RelativeLayout>
请让我知道是否有人遇到此问题以及他们试图解决此问题的解决方案
提前致谢..