错误信息:
java.lang.NullPointerException: Attempt to invoke virtual method ‘int android.view.View.getId()’ on a null object reference
java.lang.NullPointerException: Attempt to invoke virtual method ‘int android.view.View.getId()’ on a null object reference
at com.facebook.react.uimanager.NativeViewHierarchyManager.dropView(NativeViewHierarchyManager.java:536)
at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java:430)
at com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute(UIViewOperationQueue.java:179)
at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:821)
at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:928)
at com.facebook.react.uimanager.UIViewOperationQueue.access
2100
(
U
I
V
i
e
w
O
p
e
r
a
t
i
o
n
Q
u
e
u
e
.
j
a
v
a
:
46
)
a
t
c
o
m
.
f
a
c
e
b
o
o
k
.
r
e
a
c
t
.
u
i
m
a
n
a
g
e
r
.
U
I
V
i
e
w
O
p
e
r
a
t
i
o
n
Q
u
e
u
e
2100(UIViewOperationQueue.java:46) at com.facebook.react.uimanager.UIViewOperationQueue
2100(UIViewOperationQueue.java:46)atcom.facebook.react.uimanager.UIViewOperationQueueDispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:988)
at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:29)
at com.facebook.react.modules.core.ReactChoreographer
R
e
a
c
t
C
h
o
r
e
o
g
r
a
p
h
e
r
D
i
s
p
a
t
c
h
e
r
.
d
o
F
r
a
m
e
(
R
e
a
c
t
C
h
o
r
e
o
g
r
a
p
h
e
r
.
j
a
v
a
:
134
)
a
t
c
o
m
.
f
a
c
e
b
o
o
k
.
r
e
a
c
t
.
m
o
d
u
l
e
s
.
c
o
r
e
.
C
h
o
r
e
o
g
r
a
p
h
e
r
C
o
m
p
a
t
ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:134) at com.facebook.react.modules.core.ChoreographerCompat
ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:134)atcom.facebook.react.modules.core.ChoreographerCompatFrameCallback
1.
d
o
F
r
a
m
e
(
C
h
o
r
e
o
g
r
a
p
h
e
r
C
o
m
p
a
t
.
j
a
v
a
:
105
)
a
t
a
n
d
r
o
i
d
.
v
i
e
w
.
C
h
o
r
e
o
g
r
a
p
h
e
r
1.doFrame(ChoreographerCompat.java:105) at android.view.Choreographer
1.doFrame(ChoreographerCompat.java:105)atandroid.view.ChoreographerCallbackRecord.run(Choreographer.java:1024)
at android.view.Choreographer.doCallbacks(Choreographer.java:838)
at android.view.Choreographer.doFrame(Choreographer.java:766)
at android.view.Choreographer
F
r
a
m
e
D
i
s
p
l
a
y
E
v
e
n
t
R
e
c
e
i
v
e
r
.
r
u
n
(
C
h
o
r
e
o
g
r
a
p
h
e
r
.
j
a
v
a
:
1012
)
a
t
a
n
d
r
o
i
d
.
o
s
.
H
a
n
d
l
e
r
.
h
a
n
d
l
e
C
a
l
l
b
a
c
k
(
H
a
n
d
l
e
r
.
j
a
v
a
:
789
)
a
t
a
n
d
r
o
i
d
.
o
s
.
H
a
n
d
l
e
r
.
d
i
s
p
a
t
c
h
M
e
s
s
a
g
e
(
H
a
n
d
l
e
r
.
j
a
v
a
:
98
)
a
t
a
n
d
r
o
i
d
.
o
s
.
L
o
o
p
e
r
.
l
o
o
p
(
L
o
o
p
e
r
.
j
a
v
a
:
171
)
a
t
a
n
d
r
o
i
d
.
a
p
p
.
A
c
t
i
v
i
t
y
T
h
r
e
a
d
.
m
a
i
n
(
A
c
t
i
v
i
t
y
T
h
r
e
a
d
.
j
a
v
a
:
6699
)
a
t
j
a
v
a
.
l
a
n
g
.
r
e
f
l
e
c
t
.
M
e
t
h
o
d
.
i
n
v
o
k
e
(
M
e
t
h
o
d
.
j
a
v
a
)
a
t
c
o
m
.
a
n
d
r
o
i
d
.
i
n
t
e
r
n
a
l
.
o
s
.
Z
y
g
o
t
e
FrameDisplayEventReceiver.run(Choreographer.java:1012) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:171) at android.app.ActivityThread.main(ActivityThread.java:6699) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.Zygote
FrameDisplayEventReceiver.run(Choreographer.java:1012)atandroid.os.Handler.handleCallback(Handler.java:789)atandroid.os.Handler.dispatchMessage(Handler.java:98)atandroid.os.Looper.loop(Looper.java:171)atandroid.app.ActivityThread.main(ActivityThread.java:6699)atjava.lang.reflect.Method.invoke(Method.java)atcom.android.internal.os.ZygoteMethodAndArgsCaller.run(Zygote.java:246)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)
java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method ‘int android.view.View.getId()’ on a null object reference
at com.facebook.react.bridge.ReactContext.handleException(ReactContext.java:311)
at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:31)
at com.facebook.react.modules.core.ReactChoreographer
R
e
a
c
t
C
h
o
r
e
o
g
r
a
p
h
e
r
D
i
s
p
a
t
c
h
e
r
.
d
o
F
r
a
m
e
(
R
e
a
c
t
C
h
o
r
e
o
g
r
a
p
h
e
r
.
j
a
v
a
:
134
)
a
t
c
o
m
.
f
a
c
e
b
o
o
k
.
r
e
a
c
t
.
m
o
d
u
l
e
s
.
c
o
r
e
.
C
h
o
r
e
o
g
r
a
p
h
e
r
C
o
m
p
a
t
ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:134) at com.facebook.react.modules.core.ChoreographerCompat
ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:134)atcom.facebook.react.modules.core.ChoreographerCompatFrameCallback
1.
d
o
F
r
a
m
e
(
C
h
o
r
e
o
g
r
a
p
h
e
r
C
o
m
p
a
t
.
j
a
v
a
:
105
)
a
t
a
n
d
r
o
i
d
.
v
i
e
w
.
C
h
o
r
e
o
g
r
a
p
h
e
r
1.doFrame(ChoreographerCompat.java:105) at android.view.Choreographer
1.doFrame(ChoreographerCompat.java:105)atandroid.view.ChoreographerCallbackRecord.run(Choreographer.java:1024)
at android.view.Choreographer.doCallbacks(Choreographer.java:838)
at android.view.Choreographer.doFrame(Choreographer.java:766)
at android.view.Choreographer
F
r
a
m
e
D
i
s
p
l
a
y
E
v
e
n
t
R
e
c
e
i
v
e
r
.
r
u
n
(
C
h
o
r
e
o
g
r
a
p
h
e
r
.
j
a
v
a
:
1012
)
a
t
a
n
d
r
o
i
d
.
o
s
.
H
a
n
d
l
e
r
.
h
a
n
d
l
e
C
a
l
l
b
a
c
k
(
H
a
n
d
l
e
r
.
j
a
v
a
:
789
)
a
t
a
n
d
r
o
i
d
.
o
s
.
H
a
n
d
l
e
r
.
d
i
s
p
a
t
c
h
M
e
s
s
a
g
e
(
H
a
n
d
l
e
r
.
j
a
v
a
:
98
)
a
t
a
n
d
r
o
i
d
.
o
s
.
L
o
o
p
e
r
.
l
o
o
p
(
L
o
o
p
e
r
.
j
a
v
a
:
171
)
a
t
a
n
d
r
o
i
d
.
a
p
p
.
A
c
t
i
v
i
t
y
T
h
r
e
a
d
.
m
a
i
n
(
A
c
t
i
v
i
t
y
T
h
r
e
a
d
.
j
a
v
a
:
6699
)
a
t
j
a
v
a
.
l
a
n
g
.
r
e
f
l
e
c
t
.
M
e
t
h
o
d
.
i
n
v
o
k
e
(
M
e
t
h
o
d
.
j
a
v
a
)
a
t
c
o
m
.
a
n
d
r
o
i
d
.
i
n
t
e
r
n
a
l
.
o
s
.
Z
y
g
o
t
e
FrameDisplayEventReceiver.run(Choreographer.java:1012) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:171) at android.app.ActivityThread.main(ActivityThread.java:6699) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.Zygote
FrameDisplayEventReceiver.run(Choreographer.java:1012)atandroid.os.Handler.handleCallback(Handler.java:789)atandroid.os.Handler.dispatchMessage(Handler.java:98)atandroid.os.Looper.loop(Looper.java:171)atandroid.app.ActivityThread.main(ActivityThread.java:6699)atjava.lang.reflect.Method.invoke(Method.java)atcom.android.internal.os.ZygoteMethodAndArgsCaller.run(Zygote.java:246)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)
错误原因是:
RN的android原生bug,这个node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java文件的dropView函数:
if (view instanceof ViewGroup && viewManager instanceof ViewGroupManager) {
ViewGroup viewGroup = (ViewGroup) view;
ViewGroupManager viewGroupManager = (ViewGroupManager) viewManager;
for (int i = viewGroupManager.getChildCount(viewGroup) - 1; i >= 0; i--) {
View child = viewGroupManager.getChildAt(viewGroup, i);
if (mTagsToViews.get(child.getId()) != null) {
dropView(child);
}
}
viewGroupManager.removeAllViews(viewGroup);
}
中的这段代码 if (mTagsToViews.get(child.getId()) != null) 判断没有对child做空判断,导致问题可能出现崩溃。
解决办法:
更新RN版本到57.5,此问题已解决。
谢谢!