App crashing in Desire HD

2019-07-22 10:05发布

My app for some inexplicable reasons is crashing on an HTC Desire HD. It's working fine in other phones as well as the emulator. Here is the crash report:

"java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.HomeActivity}: android.view.InflateException: Binary XML file line #30: Error inflating class android.widget.EditText
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2833)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2854)
    at android.app.ActivityThread.access$2300(ActivityThread.java:136)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2179)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:143)
    at android.app.ActivityThread.main(ActivityThread.java:5068)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #30: Error inflating class android.widget.EditText
    at android.view.LayoutInflater.createView(LayoutInflater.java:513)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:215)
    at android.app.Activity.setContentView(Activity.java:1686)
    at com.myapp.HomeActivity.onCreate(HomeActivity.java:165)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1066)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2797)
    ... 11 more
Caused by: java.lang.reflect.InvocationTargetException
    at android.widget.EditText.<init>(EditText.java:53)
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
    at android.view.LayoutInflater.createView(LayoutInflater.java:500)
    ... 26 more
Caused by: java.lang.NullPointerException
    at com.htc.textselection.TextSelectionMethodImpl.initAnchorAndMagnifier(TextSelectionMethodImpl.java:300)
    at com.htc.textselection.TextSelectionMethodImpl.initialize(TextSelectionMethodImpl.java:287)
    at android.widget.TextView.setText(TextView.java:2712)
    at android.widget.TextView.setText(TextView.java:2590)
    at android.widget.EditText.setText(EditText.java:84)
    at android.widget.TextView.setText(TextView.java:2565)
    at android.widget.TextView.setTransformationMethod(TextView.java:1209)
    at android.widget.TextView.applySingleLine(TextView.java:6024)
    at android.widget.TextView.setSingleLine(TextView.java:6015)
    at android.widget.TextView.setSingleLine(TextView.java:5992)
    at android.widget.TextView.<init>(TextView.java:863)
    at android.widget.EditText.<init>(EditText.java:57)
    ... 30 more
android.view.InflateException: Binary XML file line #30: Error inflating class android.widget.EditText
    at android.view.LayoutInflater.createView(LayoutInflater.java:513)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:215)
    at android.app.Activity.setContentView(Activity.java:1686)
    at com.myapp.HomeActivity.onCreate(HomeActivity.java:165)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1066)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2797)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2854)
    at android.app.ActivityThread.access$2300(ActivityThread.java:136)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2179)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:143)
    at android.app.ActivityThread.main(ActivityThread.java:5068)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
    at android.widget.EditText.<init>(EditText.java:53)
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
    at android.view.LayoutInflater.createView(LayoutInflater.java:500)
    ... 26 more
Caused by: java.lang.NullPointerException
    at com.htc.textselection.TextSelectionMethodImpl.initAnchorAndMagnifier(TextSelectionMethodImpl.java:300)
    at com.htc.textselection.TextSelectionMethodImpl.initialize(TextSelectionMethodImpl.java:287)
    at android.widget.TextView.setText(TextView.java:2712)
    at android.widget.TextView.setText(TextView.java:2590)
    at android.widget.EditText.setText(EditText.java:84)
    at android.widget.TextView.setText(TextView.java:2565)
    at android.widget.TextView.setTransformationMethod(TextView.java:1209)
    at android.widget.TextView.applySingleLine(TextView.java:6024)
    at android.widget.TextView.setSingleLine(TextView.java:6015)
    at android.widget.TextView.setSingleLine(TextView.java:5992)
    at android.widget.TextView.<init>(TextView.java:863)
    at android.widget.EditText.<init>(EditText.java:57)
    ... 30 more
java.lang.reflect.InvocationTargetException
    at android.widget.EditText.<init>(EditText.java:53)
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
    at android.view.LayoutInflater.createView(LayoutInflater.java:500)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:215)
    at android.app.Activity.setContentView(Activity.java:1686)
    at com.myapp.HomeActivity.onCreate(HomeActivity.java:165)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1066)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2797)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2854)
    at android.app.ActivityThread.access$2300(ActivityThread.java:136)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2179)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:143)
    at android.app.ActivityThread.main(ActivityThread.java:5068)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
    at com.htc.textselection.TextSelectionMethodImpl.initAnchorAndMagnifier(TextSelectionMethodImpl.java:300)
    at com.htc.textselection.TextSelectionMethodImpl.initialize(TextSelectionMethodImpl.java:287)
    at android.widget.TextView.setText(TextView.java:2712)
    at android.widget.TextView.setText(TextView.java:2590)
    at android.widget.EditText.setText(EditText.java:84)
    at android.widget.TextView.setText(TextView.java:2565)
    at android.widget.TextView.setTransformationMethod(TextView.java:1209)
    at android.widget.TextView.applySingleLine(TextView.java:6024)
    at android.widget.TextView.setSingleLine(TextView.java:6015)
    at android.widget.TextView.setSingleLine(TextView.java:5992)
    at android.widget.TextView.<init>(TextView.java:863)
    at android.widget.EditText.<init>(EditText.java:57)
    ... 30 more
java.lang.NullPointerException
    at com.htc.textselection.TextSelectionMethodImpl.initAnchorAndMagnifier(TextSelectionMethodImpl.java:300)
    at com.htc.textselection.TextSelectionMethodImpl.initialize(TextSelectionMethodImpl.java:287)
    at android.widget.TextView.setText(TextView.java:2712)
    at android.widget.TextView.setText(TextView.java:2590)
    at android.widget.EditText.setText(EditText.java:84)
    at android.widget.TextView.setText(TextView.java:2565)
    at android.widget.TextView.setTransformationMethod(TextView.java:1209)
    at android.widget.TextView.applySingleLine(TextView.java:6024)
    at android.widget.TextView.setSingleLine(TextView.java:6015)
    at android.widget.TextView.setSingleLine(TextView.java:5992)
    at android.widget.TextView.<init>(TextView.java:863)
    at android.widget.EditText.<init>(EditText.java:57)
    at android.widget.EditText.<init>(EditText.java:53)
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
    at android.view.LayoutInflater.createView(LayoutInflater.java:500)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:215)
    at android.app.Activity.setContentView(Activity.java:1686)
    at com.myapp.HomeActivity.onCreate(HomeActivity.java:165)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1066)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2797)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2854)
    at android.app.ActivityThread.access$2300(ActivityThread.java:136)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2179)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:143)
    at android.app.ActivityThread.main(ActivityThread.java:5068)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    at dalvik.system.NativeStart.main(Native Method)
"

The crash seems to be happening when setting a value for EditText. Here is the EditText field in the XML:

<EditText style="@style/HomeInput" android:id="@+id/signin_username"
                    android:capitalize="none"
                    android:imeOptions="actionDone"
                    android:inputType="text"
                    android:text=""
                    android:maxLines="1"/>

Is anything wrong with the XML? If yes, why is it working in the emulator or other phones?

Edit 1

Here is the style XML

  <style name="HomeInput">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">wrap_content</item>      
    <item name="android:textSize">@dimen/text_size_small</item>
    <item name="android:textColor">@color/signin_input</item>
    <item name="android:layout_marginTop">10dip</item>
    <item name="android:layout_marginBottom">5dip</item>
    <item name="android:layout_marginLeft">10dip</item>
    <item name="android:layout_marginRight">10dip</item>
</style>

Edit 2

Submitted the bug report to Google: http://code.google.com/p/android/issues/detail?id=16640&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars

Edit 3

The app crashes with an EditTextPreference inflated from xml/preferences.xml. Here is the crash report:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vtcreator.android360/com.myapp.SettingsActivity}: android.view.InflateException: Binary XML file line #19: Error inflating class java.lang.reflect.Constructor
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2852)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2873)
at android.app.ActivityThread.access$2300(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2186)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:5127)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class java.lang.reflect.Constructor
at android.preference.GenericInflater.createItem(GenericInflater.java:397)
at android.preference.GenericInflater.onCreateItem(GenericInflater.java:417)
at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:428)
at android.preference.GenericInflater.rInflate(GenericInflater.java:481)
at android.preference.GenericInflater.rInflate(GenericInflater.java:493)
at android.preference.GenericInflater.inflate(GenericInflater.java:326)
at android.preference.GenericInflater.inflate(GenericInflater.java:263)
at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:254)
at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:268)
at com.myapp.SettingsActivity.onCreate(SettingsActivity.java:39)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2816)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at android.preference.EditTextPreference.<init>(EditTextPreference.java:71)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.preference.GenericInflater.createItem(GenericInflater.java:383)
... 22 more
Caused by: java.lang.NullPointerException
at com.htc.quickselection.HtcQuickSelectionWindow.<init>(HtcQuickSelectionWindow.java:164)
at com.htc.textselection.TextSelectionMethodImpl.initAnchorAndMagnifier(TextSelectionMethodImpl.java:326)
at com.htc.textselection.TextSelectionMethodImpl.initialize(TextSelectionMethodImpl.java:297)
at android.widget.TextView.setText(TextView.java:2746)
at android.widget.TextView.setText(TextView.java:2626)
at android.widget.EditText.setText(EditText.java:82)
at android.widget.TextView.<init>(TextView.java:924)
at android.widget.EditText.<init>(EditText.java:57)
at android.widget.EditText.<init>(EditText.java:53)
at android.preference.EditTextPreference.<init>(EditTextPreference.java:56)
... 26 more

3条回答
ら.Afraid
2楼-- · 2019-07-22 10:31

I finally sorted it! To start, this was my setup:

UI thread -> AsyncTask.doInBackground -> inflate

This worked perfectly fine in simulator from 1.6 to 2.3 and on other handsets (LG and Motorola), however it would blow up on HTC (Desire and Wildfire). The actual error was InflateException "Error inflating class", caused by InvocationTargetException, caused by RuntimeException "Can't create handler inside thread that has not called Looper.prepare()".

I changed this set up to

UI thread -> create Handler
UI thread -> AsyncTask.doInBackground -> Handler.sendMessage
Handler.handleMessage() -> inflate

This resulted in exactly same error. This was weird, as the code was executed from inside the handler created on the UI thread (see the lines with ** around it).

android.view.InflateException: Binary XML file line #32: Error inflating class <unknown>
    at android.view.LayoutInflater.createView(LayoutInflater.java:513)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    at com.ookl.ookllite.view.Search.createLayout(Search.java:57)
    at com.ookl.ookllite.view.Search.<init>(Search.java:44)
    at com.ookl.ookllite.OOKL.setupScreens(OOKL.java:1232)
    at com.ookl.ookllite.OOKL.access$0(OOKL.java:1199)
    **at com.ookl.ookllite.OOKL$1.handleMessage(OOKL.java:160)**
    at com.ookl.ookllite.OOKL$SetupAppTask.doInBackground(OOKL.java:281)
    at com.ookl.ookllite.OOKL$SetupAppTask.doInBackground(OOKL.java:1)
    at android.os.AsyncTask$2.call(AsyncTask.java:185)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
    at java.lang.Thread.run(Thread.java:1102)
Caused by: java.lang.reflect.InvocationTargetException
...

Finally, what did the trick was this:

UI thread -> create Runnable
UI thread -> create Handle
UI thread -> AsyncTask.doInBackground -> Handler.post(Runnable)
Runnable.run -> inflate

And this was it - it now worked on both Desire and Wildfire.

Not sure if you're having the same problem, but hopefully this will help you.

查看更多
Juvenile、少年°
3楼-- · 2019-07-22 10:33

This might be included in your style which is not shown, but most of the time you need to specify:

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
查看更多
Luminary・发光体
4楼-- · 2019-07-22 10:36

Unless your phone is completely broken, other applications are able to display EditText widgets. Hence, the problem in HTC's firmware is triggered by the definition of your EditText widget. Remove attributes one at a time from the widget or style until it works -- the last one you removed was your problem.

I would start with android:text="", since it is superfluous at best and could possibly be the source of your problem. These also seem like likely candidates:

  • android:maxLines="1"
  • android:capitalize="none"
  • android:inputType="text"

In the end, this is a bug in HTC's firmware -- it's merely a matter of trying to work around whatever the bug is.

查看更多
登录 后发表回答