Tencent/QMUI_Android · error · RuntimeException
Target already exists other parent view.
Error message
Target already exists other parent view.
What it means
QMUIPullLayout.setTargetView(view) throws when the given view's parent is neither null nor this QMUIPullLayout, meaning the view is already attached to another parent. The layout refuses to adopt a view that belongs elsewhere.
Source
Thrown at qmui/src/main/java/com/qmuiteam/qmui/widget/pullLayout/QMUIPullLayout.java:206
}else{
setHorOffsetToTargetOffsetHelper(mScroller.getCurrX());
setVerOffsetToTargetOffsetHelper(mScroller.getCurrY());
postInvalidateOnAnimation();
}
}
}
public void setStopTargetViewFlingImpl(@NonNull StopTargetViewFlingImpl stopTargetViewFlingImpl) {
mStopTargetViewFlingImpl = stopTargetViewFlingImpl;
}
public void setMinScrollDuration(int minScrollDuration) {
mMinScrollDuration = minScrollDuration;
}
public void setTargetView(@NonNull View view) {
if (view.getParent() != this) {
throw new RuntimeException("Target already exists other parent view.");
}
if (view.getParent() == null) {
LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
addView(view, lp);
}
innerSetTargetView(view);
}
private void innerSetTargetView(@NonNull View view) {
mTargetView = view;
mTargetOffsetHelper = new QMUIViewOffsetHelper(view);
}
public void setActionView(View view, LayoutParams lp) {
PullActionBuilder builder = new PullActionBuilder(view, lp.edge)
.canOverPull(lp.canOverPull)
.pullRate(lp.pullRate)
.needReceiveFlingFromTargetView(lp.needReceiveFlingFromTarget)View on GitHub (pinned to 026e7d4866)
Solutions
- Call view's current parent's removeView(view) before setTargetView(view).
- Inflate a fresh view instance for this pull layout instead of reusing an attached one.
- Only pass views that are direct XML children of this QMUIPullLayout or detached views.
Example fix
// before
pullLayout.setTargetView(recyclerView); // recyclerView still attached elsewhere
// after
if (recyclerView.getParent() instanceof ViewGroup) {
((ViewGroup) recyclerView.getParent()).removeView(recyclerView);
}
pullLayout.setTargetView(recyclerView); Defensive patterns
Strategy: type-guard
Validate before calling
Object parent = view.getParent();
if (parent == null || parent == pullLayout) {
pullLayout.setTargetView(view);
} Type guard
private static boolean canSetTarget(QMUIPullLayout layout, View v) {
return v.getParent() == null || v.getParent() == layout;
} Try / catch
try {
pullLayout.setTargetView(view);
} catch (RuntimeException e) {
ViewGroup old = (ViewGroup) view.getParent();
if (old != null) old.removeView(view);
pullLayout.setTargetView(view);
} Prevention
- Detach a view from its previous parent before assigning it as target.
- Inflate fresh view instances per pull layout instead of sharing.
- Only reuse views that are direct XML children of this pull layout.
When it happens
Trigger: Programmatically calling pullLayout.setTargetView(someView) where someView is currently attached to a different ViewGroup (e.g. still in another layout or another container).
Common situations: Reusing a view across two pull layouts; forgetting to call parentView.removeView(view) (or removeAllViews) before assigning it; moving a target view between pull layouts at runtime.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Action view already exists other parent view.
- Can not add skinChangeListener while dispatching
- Not support the type: %s
- topView must implement from IQMUIContinuousNestedTopView
- bottomView must implement from IQMUIContinuousNestedBottomVi
AI-assisted analysis of Tencent/QMUI_Android@026e7d4866 (2026-09-06).
Data as JSON: /api/errors/e3e9b3d4f174a872.
Report an issue: GitHub.