Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugin.editing.TextInputPlugin.onProvideAutofillVirtualStructure(android.view.ViewStructure, int)' on a null object reference #2062

Open
marchlqq opened this issue Jun 6, 2024 · 12 comments

Comments

@marchlqq
Copy link

marchlqq commented Jun 6, 2024

请描述遇到的问题,以及您所期望的正确的结果

1、update flutter version from 3.3.9 to 3.16.9
2、Open the phone settings and turn on the application password book function
3、create a viewpage fragment, one is native fragment and has edit, other is flutter fragment and init
then,
When you click on the edit box of the native fragment, it will inevitably collapse and appear.

crash log:
java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugin.editing.TextInputPlugin.onProvideAutofillVirtualStructure(android.view.ViewStructure, int)' on a null object reference
at io.flutter.embedding.android.FlutterView.onProvideAutofillVirtualStructure(FlutterView.java:1525)
at android.view.View.dispatchProvideStructure(View.java:10364)
at android.view.View.dispatchProvideAutofillStructure(View.java:10356)
at android.view.ViewGroup.dispatchProvideAutofillStructure(ViewGroup.java:3708)
at android.view.ViewGroup.dispatchProvideAutofillStructure(ViewGroup.java:3728)
at android.view.ViewGroup.dispatchProvideAutofillStructure(ViewGroup.java:3728)
at android.app.assist.AssistStructure$WindowNode.(AssistStructure.java:527)
at android.app.assist.AssistStructure.(AssistStructure.java:2345)
at android.app.ActivityThread.handleRequestAssistContextExtras(ActivityThread.java:4101)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2427)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:240)
at android.os.Looper.loop(Looper.java:351)
at android.app.ActivityThread.main(ActivityThread.java:8423)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)

请说明如何操作会遇到上述问题

一定要开启密码本:
image

最好是pad或者折叠屏手机:
click_1
click_2
click_3

在下面填入关键复现代码

demo:
mtp_test_demo.zip

复现的平台

Both

Flutter SDK版本

3.16.9

FlutterBoost版本

5.0.1

是否延迟初始化FlutterBoost

No

解决方案

@marchlqq
Copy link
Author

marchlqq commented Jun 6, 2024

FlutterView 方法:
public void onProvideAutofillVirtualStructure(@nonnull ViewStructure structure, int flags) {
super.onProvideAutofillVirtualStructure(structure, flags);
this.textInputPlugin.onProvideAutofillVirtualStructure(structure, flags);
}

对该方法增加try-catch,可以加,但是比较困难,有没有其他方法处理该问题。

@marchlqq
Copy link
Author

marchlqq commented Jun 7, 2024

public boolean attachToEngineAutomatically() {
return true;
}
已处理,这个阻碍了创建。导致密码本的问题处理,这个建议你们看看怎么优化一下。

@marchlqq
Copy link
Author

仅仅修改这个,会出现view 重复加载的崩溃:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.teamtalk.im/com.kdweibo.android.flutter.activity.FlutterWebActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3872)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4014)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:111)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2470)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:240)
at android.os.Looper.loop(Looper.java:351)
at android.app.ActivityThread.main(ActivityThread.java:8423)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:5342)
at android.view.ViewGroup.addView(ViewGroup.java:5163)
at android.view.ViewGroup.addView(ViewGroup.java:5103)
at android.view.ViewGroup.addView(ViewGroup.java:5075)
at io.flutter.plugin.platform.PlatformViewsController.F(SourceFile:7)
at com.kdweibo.android.flutter.platform.FlutterBoostPlatformViewsController.F(SourceFile:1)
at io.flutter.embedding.android.FlutterView.n(SourceFile:45)
at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.r(SourceFile:15)
at io.flutter.embedding.android.FlutterActivity.c(SourceFile:3)
at io.flutter.embedding.android.FlutterActivity.onCreate(SourceFile:8)
at com.idlefish.flutterboost.containers.FlutterBoostActivity.onCreate(SourceFile:7)
at com.kdweibo.android.flutter.FlutterBoostFixedActivity.onCreate(SourceFile:1)
at com.kdweibo.android.flutter.activity.FlutterWebActivity.onCreate(SourceFile:1)
at android.app.Activity.performCreate(Activity.java:8422)
at android.app.Activity.performCreate(Activity.java:8395)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1403)

@YeJiashen
Copy link

我也遇到了同样的问题, 请问解决了吗?

@joechan-cq
Copy link
Collaborator

这个问题原因是因为把有FlutterView的Fragment绑定到了界面上,但不去显示Fragment,导致FlutterView不会绑定Engine,然后在Native的EditText上弹出自动填充弹框,这个时候这个弹窗会从根view开始进行dispatch,所以FlutterView也会收到,触发onProvideAutofillVirtualStructure,导致NPE。

这个说到底是Flutter SDK中的问题,最好还是去Flutter SDK那提个issue。然后这个不是很好修改来兼容,建议业务上不要直接将不显示的FlutterFragment绑定到界面上,等需要显示的时候,再添加到界面上,以此规避掉这个问题。

@marchlqq
Copy link
Author

我也遇到了同样的问题, 请问解决了吗?

已经解决了。把它的其中一条提交,还原了。

Activity 和 Fragment 的绑定,一开始没初始化,把它改成绑定去。

flutter_boost的提交记录:
f4fcafb
Avoid unnecessary attach/detach operations of the engine. Rulong Chen(陈汝龙) 2023/12/26, 14:54
我把这个提交都还原了。

    @Override
    public boolean attachToEngineAutomatically() {
        return true;
    }

@marchlqq
Copy link
Author

我去提过了,但是他们要求先搞个不包含flutter_boost 的例子,太麻烦了,而且,他们自己的例子,没有问题,你去提,也没啥用。

@joechan-cq
Copy link
Collaborator

joechan-cq commented Jun 17, 2024

这个应该是你没讲清楚是在混合开发场景下的情况 flutter/flutter#149792 。之前3.19.x在Flutter Boost上出现兼容问题,0xZone也是提给Flutter issue然后解决的。

@marchlqq
Copy link
Author

哦哦,那应该是了吧。不过我的帖子,他们今天关掉了。也不想去问了。
我弄个帖子,demo都提供了,崩溃点,修改意见都给了,还要要求最简单demo,感觉有点过分。就只能先这样了。

@YeJiashen
Copy link

我也遇到了同样的问题, 请问解决了吗?

已经解决了。把它的其中一条提交,还原了。

Activity 和 Fragment 的绑定,一开始没初始化,把它改成绑定去。

flutter_boost的提交记录: f4fcafb Avoid unnecessary attach/detach operations of the engine. Rulong Chen(陈汝龙) 2023/12/26, 14:54 我把这个提交都还原了。

    @Override
    public boolean attachToEngineAutomatically() {
        return true;
    }

您好, 是将FlutterBoostActivity和FlutterBoostFragment这俩类中的attachToEngineAutomatically返回值都改为true吗? 我看上面您将这个返回值修改后出现了view重复加载的异常.

@marchlqq
Copy link
Author

我贴了修改的提交记录。
修改的是2点:
1、修改 attachToEngineAutomatically 返回值,FlutterBoostActivity和FlutterBoostFragment这俩类,都要改。
2、onCreate 里面删除的方法 top.detachFromEngineIfNeeded(); 添加回去。

也就是我贴的
flutter_boost的提交记录: f4fcafb

flutter boost 的提交记录,还原一下。

@YeJiashen
Copy link

我贴了修改的提交记录。 修改的是2点: 1、修改 attachToEngineAutomatically 返回值,FlutterBoostActivity和FlutterBoostFragment这俩类,都要改。 2、onCreate 里面删除的方法 top.detachFromEngineIfNeeded(); 添加回去。

也就是我贴的 flutter_boost的提交记录: f4fcafb

flutter boost 的提交记录,还原一下。

好的, 谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants