在Android studio里直接debug調(diào)試正常坝冕,但發(fā)布出來安裝就不正常危喉。在安裝后連接adb可以看到如下錯(cuò)誤日志
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)
報(bào)錯(cuò)點(diǎn)為如下
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;
}
原因:對(duì)應(yīng)的構(gòu)造方法沒有設(shè)置public袭祟,導(dǎo)致反射構(gòu)造器報(bào)錯(cuò)。但為啥子Debug時(shí)會(huì)正常呢谦秧?