由于一些莫名其妙的原因,我的应用程序崩溃了HTC Desire HD。它在其他手机以及模拟器中都能正常工作。这是崩溃报告:
"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)
"
在为EditText设置值时似乎发生了崩溃。这是XML中的EditText字段:
<EditText style="@style/HomeInput" android:id="@+id/signin_username"
android:capitalize="none"
android:imeOptions="actionDone"
android:inputType="text"
android:text=""
android:maxLines="1"/>
XML有什么问题吗?如果是,为什么它在模拟器或其他手机中工作?
修改1
这是样式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>
修改2
向Google提交错误报告:http://code.google.com/p/android/issues/detail?id=16640&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
编辑3
应用程序因从xml / preferences.xml中膨胀的EditTextPreference而崩溃。这是崩溃报告:
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
答案 0 :(得分:3)
我终于整理了它!首先,这是我的设置:
UI thread -> AsyncTask.doInBackground -> inflate
这在1.6到2.3以及其他手机(LG和摩托罗拉)的模拟器上运行得非常好,但它会在HTC(Desire和Wildfire)上爆炸。实际错误是由InvocationTargetException引起的InflateException“Error inflating class”,由RuntimeException导致“无法在未调用Looper.prepare()的线程内创建处理程序”。
我将此设置更改为
UI thread -> create Handler
UI thread -> AsyncTask.doInBackground -> Handler.sendMessage
Handler.handleMessage() -> inflate
这导致完全相同的错误。这很奇怪,因为代码是在UI线程上创建的处理程序内执行的(参见围绕它的**行)。
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
...
最后,诀窍是什么:
UI thread -> create Runnable
UI thread -> create Handle
UI thread -> AsyncTask.doInBackground -> Handler.post(Runnable)
Runnable.run -> inflate
就是这样 - 它现在适用于Desire和Wildfire。
不确定您是否遇到同样的问题,但希望这会对您有所帮助。
答案 1 :(得分:3)
除非您的手机完全损坏,否则其他应用程序可以显示EditText
小部件。因此,HTC固件中的问题是由EditText
小部件的定义触发的。从窗口小部件或样式中一次删除一个属性,直到它起作用 - 删除的最后一个属性是你的问题。
我会从android:text=""
开始,因为它充其量是多余的,可能是你问题的根源。这些似乎也很可能是候选人:
android:maxLines="1"
android:capitalize="none"
android:inputType="text"
最后,这是HTC固件中的一个错误 - 这只是试图解决任何错误的问题。
答案 2 :(得分:0)
这可能包含在您未显示的样式中,但大部分时间需要指定:
android:layout_width="wrap_content"
android:layout_height="wrap_content"