gpt4 book ai didi

java - android.view.InflateException : Binary XML file line #51: Error inflating class com. android.internal.widget.DialogTitle

转载 作者:行者123 更新时间:2023-11-30 11:25:48 27 4
gpt4 key购买 nike

每次我的应用程序尝试显示对话框 fragment 或特定布局时,我都会收到以下错误或类似错误:

11-22 10:20:48.993: E/AndroidRuntime(15514): FATAL EXCEPTION: main
11-22 10:20:48.993: E/AndroidRuntime(15514): android.view.InflateException: Binary XML file line #51: Error inflating class com.android.internal.widget.DialogTitle
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-22 10:20:48.993: E/AndroidRuntime(15514): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:313)
11-22 10:20:48.993: E/AndroidRuntime(15514): at com.android.internal.app.AlertController.installContent(AlertController.java:241)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.app.AlertDialog.onCreate(AlertDialog.java:336)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.app.Dialog.dispatchOnCreate(Dialog.java:351)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.app.Dialog.show(Dialog.java:256)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.support.v4.app.DialogFragment.onStart(DialogFragment.java:385)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.support.v4.app.Fragment.performStart(Fragment.java:1484)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:941)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.os.Handler.handleCallback(Handler.java:615)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.os.Handler.dispatchMessage(Handler.java:92)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.os.Looper.loop(Looper.java:137)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.app.ActivityThread.main(ActivityThread.java:4921)
11-22 10:20:48.993: E/AndroidRuntime(15514): at java.lang.reflect.Method.invokeNative(Native Method)
11-22 10:20:48.993: E/AndroidRuntime(15514): at java.lang.reflect.Method.invoke(Method.java:511)
11-22 10:20:48.993: E/AndroidRuntime(15514): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
11-22 10:20:48.993: E/AndroidRuntime(15514): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
11-22 10:20:48.993: E/AndroidRuntime(15514): at dalvik.system.NativeStart.main(Native Method)
11-22 10:20:48.993: E/AndroidRuntime(15514): Caused by: java.lang.reflect.InvocationTargetException
11-22 10:20:48.993: E/AndroidRuntime(15514): at java.lang.reflect.Constructor.constructNative(Native Method)
11-22 10:20:48.993: E/AndroidRuntime(15514): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
11-22 10:20:48.993: E/AndroidRuntime(15514): ... 28 more
11-22 10:20:48.993: E/AndroidRuntime(15514): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=43; index=82
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.content.res.StringBlock.get(StringBlock.java:64)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.content.res.XmlBlock$Parser.getPooledString(XmlBlock.java:458)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:720)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.content.res.TypedArray.getText(TypedArray.java:96)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.widget.TextView.<init>(TextView.java:848)
11-22 10:20:48.993: E/AndroidRuntime(15514): at android.widget.TextView.<init>(TextView.java:588)
11-22 10:20:48.993: E/AndroidRuntime(15514): at com.android.internal.widget.DialogTitle.<init>(DialogTitle.java:38)
11-22 10:20:48.993: E/AndroidRuntime(15514): ... 31 more

我要显示的布局是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
android:id="@+id/titlelay"
android:layout_width="match_parent"
android:layout_height="@dimen/titlebar"
android:background="@color/green"
android:padding="@dimen/small" >

<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="@dimen/text_big"
android:textStyle="bold" />

<Button
android:id="@+id/problem_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="@dimen/ten_pad"
android:background="#F00"
android:textSize="@dimen/text_medium"
android:visibility="gone" />

<Button
android:id="@+id/logout_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp"
android:textSize="@dimen/text_medium" />
</RelativeLayout>

<!-- Login form -->

<TextView
android:id="@+id/warning_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/titlelay"
android:layout_gravity="center_horizontal"
android:textColor="#FFF"
android:visibility="gone" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/warning_text"
android:layout_margin="@dimen/padding_value"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="@dimen/padding_value" >

<Button
android:id="@+id/herds_button"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="@dimen/twenty"
android:layout_weight="1"
android:textSize="@dimen/text_medium"
android:textStyle="bold" />

<Button
android:id="@+id/livestock"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="@dimen/twenty"
android:layout_weight="1"
android:textSize="@dimen/text_medium"
android:textStyle="bold" />

<Button
android:id="@+id/addHoldings"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="@dimen/twenty"
android:layout_weight="1"
android:textSize="@dimen/text_medium"
android:textStyle="bold" />

<Button
android:id="@+id/options"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="@dimen/twenty"
android:layout_weight="1"
android:textSize="@dimen/text_medium"
android:textStyle="bold" />
</LinearLayout>

</RelativeLayout>

这是在我做了一些定义样式、颜色和尺寸资源的工作后开始出现的。我将一些布局和资源文件复制到另一个应用程序,在那里编辑它们以获得新外观,然后将它们复制回主项目。我已经(据我所知)删除了所有这些更改,但问题仍然存在。

另一个奇怪的行为是,一个正常运行的 Activity 中的 EditText 本应为空,但现在却被 res/color/search_url_text_holo.xml 填充。

我认为可能是 R.java 已损坏。我已经删除了 R,清理了我的项目并重建了项目,但这并没有解决问题。

我真的很难过。任何帮助都会很棒。只需询问您是否需要更多详细信息。

非常感谢。

编辑 1:下面是对话框中打开对应的java代码:

private void arable() {
dialogs.Arable arable = new dialogs.Arable();
arable.show(getSupportFragmentManager(), "tag");
}

package dialogs;

import rich.farming.fertiliserrecommendations.R;
import admin.reference.Crop;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import appmethods.Starters;

public class Arable extends DialogFragment {

private static Activity act;
private boolean cancelled;

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

act = getActivity();
int Items = R.array.Menu_arable;
cancelled = false;

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Select").setItems(Items,
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
System.out.println("(Dialogs.Arable.onClick which = "
+ which);
switch (which) {

default:
cancelled = true;
break;
}
dismiss();
if (!cancelled)
act.finish();
}

});

return builder.create();
}

这只是一个例子。有多个对话框以这种方式打开。直到最近他们工作得很好。如果你愿意,我也可以发布菜单资源,但它们没有改变。

最佳答案

我发现了问题。奇怪的是,这是因为我的 styles.xml 中的资源元素包含一个 namespace 引用:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

删除这样的元素:

<resources>

解决了这个问题。

关于java - android.view.InflateException : Binary XML file line #51: Error inflating class com. android.internal.widget.DialogTitle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20143006/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com