Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have this bug in my app only on Android 4.4.</p> <p>In the debugger it shows the same message as the question asker. However when not debugging the full stacktrace in DDMS is:</p> <p>Full stacktrace:</p> <pre><code>11-13 16:34:53.088: E/AndroidRuntime(1964): FATAL EXCEPTION: main 11-13 16:34:53.088: E/AndroidRuntime(1964): Process: appname, PID: 1964 11-13 16:34:53.088: E/AndroidRuntime(1964): java.lang.NullPointerException 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.widget.TextView.makeNewLayout(TextView.java:6124) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.widget.TextView.onMeasure(TextView.java:6419) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.View.measure(View.java:16458) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.widget.Spinner.setUpChild(Spinner.java:632) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.widget.Spinner.makeView(Spinner.java:585) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.widget.Spinner.getBaseline(Spinner.java:431) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1262) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.widget.LinearLayout.onMeasure(LinearLayout.java:590) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.View.measure(View.java:16458) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.View.measure(View.java:16458) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.View.measure(View.java:16458) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 11-13 16:34:53.088: E/AndroidRuntime(1964): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.View.measure(View.java:16458) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 11-13 16:34:53.088: E/AndroidRuntime(1964): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2289) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.View.measure(View.java:16458) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1914) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1111) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1293) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5582) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.Choreographer.doCallbacks(Choreographer.java:562) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.Choreographer.doFrame(Choreographer.java:532) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.os.Handler.handleCallback(Handler.java:733) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.os.Handler.dispatchMessage(Handler.java:95) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.os.Looper.loop(Looper.java:137) 11-13 16:34:53.088: E/AndroidRuntime(1964): at android.app.ActivityThread.main(ActivityThread.java:4998) 11-13 16:34:53.088: E/AndroidRuntime(1964): at java.lang.reflect.Method.invokeNative(Native Method) 11-13 16:34:53.088: E/AndroidRuntime(1964): at java.lang.reflect.Method.invoke(Method.java:515) 11-13 16:34:53.088: E/AndroidRuntime(1964): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777) 11-13 16:34:53.088: E/AndroidRuntime(1964): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 11-13 16:34:53.088: E/AndroidRuntime(1964): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>Looking through the 4.4 sourcecode of TextView at line 6124, it turns out that this is caused by missing layout params when ellipsing. This is strange, since the code is failing inside a <code>ListAdapter</code>, where you don't supply layout params in <code>getView</code>. </p> <p>I used to inflate <code>android.R.layout.simple_spinner_item</code> for standard spinner items. It looks like this item uses <code>ellipsing</code>. So in my <code>getView</code> I now call:</p> <pre><code>view.setEllipsize(null); </code></pre> <p>This fixes my problems on Android 4.4.</p> <p><strong>Edit</strong></p> <p>It turns out the problem is not the ellipsing, but improper inflating of a view in <code>getView</code>.</p> <pre><code>inflater.inflate(android.R.layout.simple_spinner_item, null);//WRONG inflater.inflate(android.R.layout.simple_spinner_item, parent, false);//GOOD </code></pre> <p>Note that you supply <code>false</code> to not attach the view immediately to the parent, because this is in a adapter that attaches children when needed. Otherwise you will get errors. </p> <p>When you inflate properly, you don't need to set <code>ellipseSize</code> to <code>null</code>. This is because when you inflate the good way, with a parent, it handles the <code>LayoutParams</code> properly, causing the ellipse code not to raise <code>NullPointerException</code>.</p> <p>So, inflate properly, and then you don't have to worry anymore.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload