在Android studio里直接debug调试正常,但发布出来安装就不正常。在安装后连接adb可以看到如下错误日志
2019-07-06 13:27:19.464 28375-28375/xxx W/System.err: java.lang.NoSuchMethodException: <init> [class android.view.View]
2019-07-06 13:27:19.464 28375-28375/xxx W/System.err: at java.lang.Class.getConstructor0(Class.java:2320)
2019-07-06 13:27:19.464 28375-28375/xxx W/System.err: at java.lang.Class.getConstructor(Class.java:1725)
2019-07-06 13:27:19.464 28375-28375/xxx W/System.err: at MessageItemHolderFactory.createMessageHolder(MessageItemHolderFactory.java:134)
2019-07-06 13:27:19.464 28375-28375/xxx W/System.err: at WechatConvListAdapter.onCreateViewHolder(WechatConvListAdapter.java:46)
2019-07-06 13:27:19.464 28375-28375/xxx W/System.err: at WechatConvListAdapter.onCreateViewHolder(WechatConvListAdapter.java:21)
2019-07-06 13:27:19.464 28375-28375/xxx W/System.err: at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6903)
2019-07-06 13:27:19.465 28375-28375/cn.ac.multiwechat W/System.err: at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6075)
报错点为如下
try {
Constructor<? extends BaseMessageItemHolder> constructor = holderClass.getConstructor(View.class);
holder = constructor.newInstance(view);
} catch (NoSuchMethodException e) {
e.printStackTrace();
holder = null;
} catch (IllegalAccessException e) {
e.printStackTrace();
holder = null;
} catch (InstantiationException e) {
e.printStackTrace();
holder = null;
} catch (InvocationTargetException e) {
e.printStackTrace();
holder = null;
}
原因:对应的构造方法没有设置public,导致反射构造器报错。但为啥子Debug时会正常呢?