我想通过android源来了解错误原因。我的安卓设备version 4.4.4
与API 19
相同。我下载了API级别19(通过sdk管理器)的源代码,并希望找到导致错误的代码
在logcat中我有错误:
12-16 16:51:03.790: E/AndroidRuntime(10349): java.lang.NullPointerException
12-16 16:51:03.790: E/AndroidRuntime(10349): at android.widget.TextView.checkForRelayout(TextView.java:6596)
12-16 16:51:03.790: E/AndroidRuntime(10349): at android.widget.TextView.onRtlPropertiesChanged(TextView.java:8716)
12-16 16:51:03.790: E/AndroidRuntime(10349): at android.view.View.resolvePadding(View.java:12538)
但问题是TextView类的第6596行是:
} else {
第8716行是评论。所以cources不对应错误。如何找到正确的来源?
此外,如果检入设备Build.VERSION.SDK_INT is 19
。
设备 - Sony Xperia tablet
。
完整的logcat 12-16 17:30:43
.401: E/AndroidRuntime(19327): java.lang.NullPointerException
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.TextView.checkForRelayout(TextView.java:6596)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.TextView.onRtlPropertiesChanged(TextView.java:8716)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.View.resolvePadding(View.java:12538)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.View.resolveRtlPropertiesIfNeeded(View.java:12289)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.View.measure(View.java:16639)
12-16 17:30:43.401: E/AndroidRuntime(19327): at com.cooperok.gui.views.tablefixheader.TableFixHeaders.makeView(TableFixHeaders.java:741)
12-16 17:30:43.401: E/AndroidRuntime(19327): at com.cooperok.gui.views.tablefixheader.TableFixHeaders.makeAndSetup(TableFixHeaders.java:698)
12-16 17:30:43.401: E/AndroidRuntime(19327): at com.cooperok.gui.views.tablefixheader.TableFixHeaders.onLayout(TableFixHeaders.java:601)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.View.layout(View.java:14965)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.ViewGroup.layout(ViewGroup.java:4631)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.View.layout(View.java:14965)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.ViewGroup.layout(ViewGroup.java:4631)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.View.layout(View.java:14965)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.ViewGroup.layout(ViewGroup.java:4631)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.View.layout(View.java:14965)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.ViewGroup.layout(ViewGroup.java:4631)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.View.layout(View.java:14965)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.ViewGroup.layout(ViewGroup.java:4631)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.View.layout(View.java:14965)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.ViewGroup.layout(ViewGroup.java:4631)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.View.layout(View.java:14965)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.ViewGroup.layout(ViewGroup.java:4631)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.View.layout(View.java:14965)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.ViewGroup.layout(ViewGroup.java:4631)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1987)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1744)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5622)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.Choreographer.doFrame(Choreographer.java:544)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.os.Handler.handleCallback(Handler.java:733)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.os.Handler.dispatchMessage(Handler.java:95)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.os.Looper.loop(Looper.java:212)
12-16 17:30:43.401: E/AndroidRuntime(19327): at android.app.ActivityThread.main(ActivityThread.java:5135)
12-16 17:30:43.401: E/AndroidRuntime(19327): at java.lang.reflect.Method.invokeNative(Native Method)
12-16 17:30:43.401: E/AndroidRuntime(19327): at java.lang.reflect.Method.invoke(Method.java:515)
12-16 17:30:43.401: E/AndroidRuntime(19327): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
12-16 17:30:43.401: E/AndroidRuntime(19327): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
12-16 17:30:43.401: E/AndroidRuntime(19327): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
要找到合适的来源,您应该拥有一台Google Nexus设备 - 纯Android设备。
制造商为其设备更改了Android的来源。 它会导致logcat上出现错误的行号。
答案 1 :(得分:0)
为了解决我的问题,我查看了原始android源代码并发现NullPointerException只有两个可能的变体,所以很容易猜到问题出在哪里
/**
* Check whether entirely new text requires a new view layout
* or merely a new text layout.
*/
private void checkForRelayout() {
// If we have a fixed width, we can just swap in a new text layout
// if the text height stays the same or if the view height is fixed.
if ((mLayoutParams.width != LayoutParams.WRAP_CONTENT ||
(mMaxWidthMode == mMinWidthMode && mMaxWidth == mMinWidth)) &&
(mHint == null || mHintLayout != null) &&
(mRight - mLeft - getCompoundPaddingLeft() - getCompoundPaddingRight() > 0)) {
// Static width, so try making a new text layout.
int oldht = mLayout.getHeight();
int want = mLayout.getWidth();
int hintWant = mHintLayout == null ? 0 : mHintLayout.getWidth();
/*
* No need to bring the text into view, since the size is not
* changing (unless we do the requestLayout(), in which case it
* will happen at measure).
*/
makeNewLayout(want, hintWant, UNKNOWN_BORING, UNKNOWN_BORING,
mRight - mLeft - getCompoundPaddingLeft() - getCompoundPaddingRight(),
false);
if (mEllipsize != TextUtils.TruncateAt.MARQUEE) {
// In a fixed-height view, so use our new text layout.
if (mLayoutParams.height != LayoutParams.WRAP_CONTENT &&
mLayoutParams.height != LayoutParams.MATCH_PARENT) {
invalidate();
return;
}
// Dynamic height, but height has stayed the same,
// so use our new text layout.
if (mLayout.getHeight() == oldht &&
(mHintLayout == null || mHintLayout.getHeight() == oldht)) {
invalidate();
return;
}
}
// We lose: the height has changed and we have a dynamic height.
// Request a new view layout using our new text layout.
requestLayout();
invalidate();
} else {
// Dynamic width, so we have no choice but to request a new
// view layout with a new text layout.
nullLayouts();
requestLayout();
invalidate();
}
}
在我的情况下,TextView是以编程方式创建的,并且mLayoutParams为null,因此通过设置LayoutParams来查看问题。
但这很糟糕,供应商可以更改Android源代码并且不显示这些更改(实际上我没有找到有关索尼的任何信息)。我以为他们只改变内核。