且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在EditText上Android应用程序崩溃时,长按文本

更新时间:2023-01-24 23:37:51

解决了我们的问题通过的感谢洛里什这里回答:Inflate有关设置长按事件侦听器异常

基本上更名为应用程序的一部分有些款式有安卓fontFamily中添加物品。奇怪的是这不仅造成长期的点击崩溃的nexus7片,继续对三星Galaxy Tab做工精细,一加手机等。

I have a dialog fragment with editable text. When you long press on the text it crashes the app. Not sure why this has suddenly started happening as it used to work fine but now crashes consistently, and not too sure where to look as logcat seems to imply it's trying to inflate a view for a long click.

Here's the simple dialog fragment creation (MobileAlertDialog inherits from DialogFragment with a few defaults set)

var alertDialog = new Widgets.MobileAlertDialogFragment();
            alertDialog.Title = s.Name;
            EditText input = new EditText(this);
            (input as EditText).Text = s.Value;
            alertDialog.MessageView = input;
            alertDialog.PositiveCallback = () =>
            {
              s.Value = input.Text;
              RefreshSettings();
            };
            alertDialog.CancelCallback = () =>
            {
              //Do nothing...
            };
            alertDialog.Show(this.SupportFragmentManager, "ENTER_VALUE_DIALOG");

And here's the logcat:

--------- beginning of /dev/log/main

07-20 11:55:10.459 D/AndroidRuntime( 4886): Shutting down VM

07-20 11:55:10.459 W/dalvikvm( 4886): threadid=1: thread exiting with uncaught exception (group=0x41fe8930)

--------- beginning of /dev/log/system

07-20 11:55:10.467 E/AndroidRuntime( 4886): FATAL EXCEPTION: main

07-20 11:55:10.467 E/AndroidRuntime( 4886): android.view.InflateException: Binary XML file line #31: Error inflating class <unknown>

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.view.LayoutInflater.createView(LayoutInflater.java:613)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at com.android.internal.widget.ActionBarContextView.initForMode(ActionBarContextView.java:206)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2305)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2243)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:623)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:623)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:623)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:623)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:623)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.view.View.startActionMode(View.java:4302)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.widget.Editor.startSelectionActionMode(Editor.java:1517)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.widget.Editor.performLongClick(Editor.java:839)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.widget.TextView.performLongClick(TextView.java:8066)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.view.View$CheckForLongPress.run(View.java:17351)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.os.Handler.handleCallback(Handler.java:725)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.os.Handler.dispatchMessage(Handler.java:92)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.os.Looper.loop(Looper.java:137)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.app.ActivityThread.main(ActivityThread.java:5041)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at java.lang.reflect.Method.invokeNative(Native Method)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at java.lang.reflect.Method.invoke(Method.java:511)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at dalvik.system.NativeStart.main(Native Method)

07-20 11:55:10.467 E/AndroidRuntime( 4886): Caused by: java.lang.reflect.InvocationTargetException

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at java.lang.reflect.Constructor.constructNative(Native Method)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.view.LayoutInflater.createView(LayoutInflater.java:587)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     ... 28 more

07-20 11:55:10.467 E/AndroidRuntime( 4886): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=24; index=2231

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.content.res.StringBlock.get(StringBlock.java:64)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.content.res.XmlBlock$Parser.getPooledString(XmlBlock.java:458)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.content.res.TypedArray.loadStringValueAt(TypedArray.java:720)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.content.res.TypedArray.getString(TypedArray.java:124)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.widget.TextView.<init>(TextView.java:928)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     at android.widget.TextView.<init>(TextView.java:578)

07-20 11:55:10.467 E/AndroidRuntime( 4886):     ... 31 more

07-20 11:55:10.475 W/ActivityManager(  459):   Force finishing activity AndroidApp/AndroidBase.SettingsView

07-20 11:55:10.998 W/ActivityManager(  459): Activity pause timeout for ActivityRecord{4294d660 u0 AndroidApp/AndroidBase.SettingsView}

Solved our issue thanks to answer by Loures here: Inflate Exception on setting up a long click event listener

Basically as part of rebranding app some styles got android:fontFamily items added. Weird thing was this only caused long-click crashing for nexus7 tablets, continued to work fine on Samsung Galaxy Tab, OnePlus One etc.