1***@163.com
1***@163.com
  • 发布:2021-04-28 16:22
  • 更新:2022-08-18 14:41
  • 阅读:1649

uniapp原生插件开发WXComponentFactory Exception type

分类:uni-app
E/weex: end getBundleType type:Vue time:0  
E/timeline: createInstance :1619597867918  
E/jsEngine: script_bridge_in_multi_process.cpp:473,ScriptBridgeInMultiProcess::CreateInstance and Id is : 2  
E/shutao:         UniComponent  
E/weex: WXComponentFactory Exception type:[MyBtn] com.taobao.weex.common.WXRuntimeException: Can't find constructor of component.  
        at com.taobao.weex.ui.SimpleComponentHolder$ClazzComponentCreator.getComponentConstructor(SimpleComponentHolder.java:108)  
        at com.taobao.weex.ui.SimpleComponentHolder$ClazzComponentCreator.createInstance(SimpleComponentHolder.java:121)  
        at com.taobao.weex.ui.SimpleComponentHolder.createInstance(SimpleComponentHolder.java:237)  
        at com.taobao.weex.ui.component.WXComponentFactory.newInstance(WXComponentFactory.java:66)  
        at com.taobao.weex.ui.action.GraphicActionAbstractAddElement.createComponent(GraphicActionAbstractAddElement.java:61)  
        at com.taobao.weex.ui.action.GraphicActionAddElement.<init>(GraphicActionAddElement.java:86)  
        at com.taobao.weex.bridge.WXBridgeManager.callAddElement(WXBridgeManager.java:2806)  
        at com.taobao.weex.bridge.WXBridge.callAddElement(WXBridge.java:535)  
        at com.taobao.weex.base.SystemMessageHandler.nativeRunWork(Native Method)  
        at com.taobao.weex.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:104)  
        at android.os.Handler.dispatchMessage(Handler.java:107)  
        at android.os.Looper.loop(Looper.java:224)  
        at android.os.HandlerThread.run(HandlerThread.java:67)  
    [WXBridgeManager] callAddElement exception: java.lang.NullPointerException: Attempt to invoke virtual method 'com.taobao.weex.dom.WXAttr com.taobao.weex.ui.component.basic.WXBasicComponent.getAttrs()' on a null object reference  
        at com.taobao.weex.ui.RenderContextImpl.registerComponent(RenderContextImpl.java:86)  
        at com.taobao.weex.ui.WXRenderManager.registerComponent(WXRenderManager.java:306)  
        at com.taobao.weex.ui.action.GraphicActionAbstractAddElement.createComponent(GraphicActionAbstractAddElement.java:62)  
        at com.taobao.weex.ui.action.GraphicActionAddElement.<init>(GraphicActionAddElement.java:86)  
        at com.taobao.weex.bridge.WXBridgeManager.callAddElement(WXBridgeManager.java:2806)  
        at com.taobao.weex.bridge.WXBridge.callAddElement(WXBridge.java:535)  
        at com.taobao.weex.base.SystemMessageHandler.nativeRunWork(Native Method)  
        at com.taobao.weex.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:104)  
        at android.os.Handler.dispatchMessage(Handler.java:107)  
        at android.os.Looper.loop(Looper.java:224)  
        at android.os.HandlerThread.run(HandlerThread.java:67)  
E/weex: commitCriticalExceptionRT :WX_KEY_EXCEPTION_INVOKE_BRIDGEexceptionjava.lang.NullPointerException: Attempt to invoke virtual method 'com.taobao.weex.dom.WXAttr com.taobao.weex.ui.component.basic.WXBasicComponent.getAttrs()' on a null object reference  
        at com.taobao.weex.ui.RenderContextImpl.registerComponent(RenderContextImpl.java:86)  
        at com.taobao.weex.ui.WXRenderManager.registerComponent(WXRenderManager.java:306)  
        at com.taobao.weex.ui.action.GraphicActionAbstractAddElement.createComponent(GraphicActionAbstractAddElement.java:62)  
        at com.taobao.weex.ui.action.GraphicActionAddElement.<init>(GraphicActionAddElement.java:86)  
        at com.taobao.weex.bridge.WXBridgeManager.callAddElement(WXBridgeManager.java:2806)  
        at com.taobao.weex.bridge.WXBridge.callAddElement(WXBridge.java:535)  
        at com.taobao.weex.base.SystemMessageHandler.nativeRunWork(Native Method)  
        at com.taobao.weex.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:104)  
        at android.os.Handler.dispatchMessage(Handler.java:107)  
        at android.os.Looper.loop(Looper.java:224)  
        at android.os.HandlerThread.run(HandlerThread.java:67)
2021-04-28 16:22 负责人:无 分享
已邀请:
a***@163.com

a***@163.com

UniComponent的构造函数有两个,一个4个参数的,一个3个参数的。你只实现了4个参数的构造函数,官方的TextView实现的3个参数的构造函数。估计报错的时候调用的是3个参数的,你加个3个参数的构造函数应该就可以了

  • b***@qq.com

    你是对的

    2022-05-06 10:16

  • 3***@qq.com

    确实是构造方法的问题,重写一下构造方法就可以了

    2022-06-06 13:56

1***@163.com

1***@163.com (作者) - 拉直索尔

sdk:Android-SDK@3.1.11.80806_20210425
hbuildversion:3.1.11.20210423

报错的代码

package com.uninative.mycomponent;  

import android.content.Context;  
import android.support.annotation.NonNull;  
import android.widget.Button;  

import io.dcloud.feature.uniapp.UniSDKInstance;  
import io.dcloud.feature.uniapp.ui.action.AbsComponentData;  
import io.dcloud.feature.uniapp.ui.component.AbsVContainer;  
import io.dcloud.feature.uniapp.ui.component.UniComponent;  

public class MyButton extends UniComponent<Button> {  
    public MyButton(UniSDKInstance instance, AbsVContainer parent, int type, AbsComponentData componentData) {  
        super(instance, parent, type, componentData);  
    }  

    @Override  
    protected Button initComponentHostView(@NonNull Context context) {  
        Button btn=new Button(context);  
        btn.setText("哈哈");  
        return btn;  
    }  
}  
1***@163.com

1***@163.com (作者) - 拉直索尔

呵呵,难道非得付费才能解决吗

3***@163.com

3***@163.com

同样的问题,有解决方式么?官方的例子那个Textview为啥可以?

z***@sina.com

z***@sina.com

同样的问题,有解决方式么?官方的例子那个Textview为啥可以?

w***@163.com

w***@163.com - 湾哥

是啊,为什么官方的可以

9***@qq.com

9***@qq.com

混淆问题,关闭混淆,或者把自定义扩展控件的类,加到混淆配置中;
1、build.gradle->android->buildTypes->isMinifyEnabled=false
2、proguard-rules.pro-> -keep class com.xxxxx.xxxxx.TestTextView {*;}

要回复问题请先登录注册