营造出NoSuchMethodException我知道,从https://github.com/firebase/FirebaseUI-Android/issues/46,修复NoSuchMethodException:FirebaseRecyclerAdapter如果使用密钥库版本
- 确保您TaskViewHolder类是公共
- 如果您TaskViewHolder是一个内部类的如你的活动,确保它是静态的
该解决方案仅在我使用调试密钥库构建应用程序时起作用。但是在使用release keystore构建应用程序之后,我仍然得到NoSuchMethodException。 minifyEnabled =假
测试Android上的一个棉花糖美图A10,荣誉6和marsmallow模拟器
堆栈跟踪错误:
Exception java.lang.RuntimeException: java.lang.NoSuchMethodException: <init> [class android.view.View]
com.firebase.ui.database.FirebaseRecyclerAdapter.onCreateViewHolder (FirebaseRecyclerAdapter.java:172)
android.support.v7.widget.RecyclerView$Adapter.createViewHolder (RecyclerView.java:5836)
android.support.v7.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:5060)
android.support.v7.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:4970)
android.support.v7.widget.LinearLayoutManager$LayoutState.next (LinearLayoutManager.java:2029)
android.support.v7.widget.LinearLayoutManager.layoutChunk (LinearLayoutManager.java:1414)
android.support.v7.widget.LinearLayoutManager.fill (LinearLayoutManager.java:1377)
android.support.v7.widget.LinearLayoutManager.onLayoutChildren (LinearLayoutManager.java:578)
android.support.v7.widget.RecyclerView.dispatchLayoutStep2 (RecyclerView.java:3315)
android.support.v7.widget.RecyclerView.onMeasure (RecyclerView.java:2843)
android.view.View.measure (View.java:18788)
android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5951)
android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1465)
android.widget.LinearLayout.measureVertical (LinearLayout.java:748)
android.widget.LinearLayout.onMeasure (LinearLayout.java:630)
android.view.View.measure (View.java:18788)
android.widget.ScrollView.measureChildWithMargins (ScrollView.java:1283)
android.widget.FrameLayout.onMeasure (FrameLayout.java:194)
android.widget.ScrollView.onMeasure (ScrollView.java:340)
android.view.View.measure (View.java:18788)
android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5951)
android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1465)
android.widget.LinearLayout.measureVertical (LinearLayout.java:748)
android.widget.LinearLayout.onMeasure (LinearLayout.java:630)
android.view.View.measure (View.java:18788)
android.widget.RelativeLayout.measureChildHorizontal (RelativeLayout.java:715)
android.widget.RelativeLayout.onMeasure (RelativeLayout.java:461)
android.view.View.measure (View.java:18788)
android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5951)
android.widget.FrameLayout.onMeasure (FrameLayout.java:194)
android.support.v7.widget.ContentFrameLayout.onMeasure (ContentFrameLayout.java:135)
android.view.View.measure (View.java:18788)
android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5951)
android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1465)
android.widget.LinearLayout.measureVertical (LinearLayout.java:748)
android.widget.LinearLayout.onMeasure (LinearLayout.java:630)
android.view.View.measure (View.java:18788)
android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5951)
android.widget.FrameLayout.onMeasure (FrameLayout.java:194)
android.view.View.measure (View.java:18788)
android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5951)
android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:1465)
android.widget.LinearLayout.measureVertical (LinearLayout.java:748)
android.widget.LinearLayout.onMeasure (LinearLayout.java:630)
android.view.View.measure (View.java:18788)
android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:5951)
android.widget.FrameLayout.onMeasure (FrameLayout.java:194)
com.android.internal.policy.PhoneWindow$DecorView.onMeasure (PhoneWindow.java:2643)
android.view.View.measure (View.java:18788)
android.view.ViewRootImpl.performMeasure (ViewRootImpl.java:2100)
android.view.ViewRootImpl.measureHierarchy (ViewRootImpl.java:1216)
android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:1452)
android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1107)
android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:6013)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:858)
android.view.Choreographer.doCallbacks (Choreographer.java:670)
android.view.Choreographer.doFrame (Choreographer.java:606)
android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:844)
android.os.Handler.handleCallback (Handler.java:739)
android.os.Handler.dispatchMessage (Handler.java:95)
我在单独CommentHolder.java文件ViewHolder公共:
public class CommentHolder extends RecyclerView.ViewHolder
implements View.OnClickListener {
TextView tvComment = null;
TextView tvUser = null;
TextView tvDate = null;
String emailComment = "";
String commentKey, catalogKey;
FirebaseAuth auth;
FirebaseDatabase database;
CommentHolder(View row) {
super(row);
auth=FirebaseAuth.getInstance();
database=FirebaseDatabase.getInstance();
tvComment = (TextView) row.findViewById(R.id.comment);
tvUser = (TextView) row.findViewById(R.id.user);
tvDate = (TextView) row.findViewById(R.id.datecomment);
row.setOnClickListener(this);
}
@Override
public void onClick(final View v) {
if (auth.getCurrentUser() == null || auth.getCurrentUser().getEmail() == null) {
Toast.makeText(v.getContext(), "Harap login terlebih dahulu", Toast.LENGTH_LONG).show();
return;
}
if (!auth.getCurrentUser().getEmail().equalsIgnoreCase(emailComment)) {
Toast.makeText(v.getContext(), "Anda hanya dapat mengedit komentar yang Anda buat", Toast.LENGTH_LONG).show();
return;
}
final View form = ((Activity) v.getContext()).getLayoutInflater().inflate(R.layout.dialog_comment, null);
EditText etComment = (EditText) form.findViewById(R.id.editTextComment);
etComment.setText(tvComment.getText().toString());
AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
builder
.setTitle("Komentar Anda")
.setView(form)
.setPositiveButton("Kirim", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
final EditText etComment = (EditText) form.findViewById(R.id.editTextComment);
DatabaseReference commentRef = database.getReference(MyConstants.FB_COMMENT)
.child(catalogKey).child(commentKey);
Comment comment = new Comment(auth.getCurrentUser().getUid()
, auth.getCurrentUser().getEmail(), etComment.getText().toString());
commentRef.setValue(comment);
}
})
.setNegativeButton("Batal", null)
.setNeutralButton("Hapus", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
DatabaseReference commentRef = database.getReference(MyConstants.FB_COMMENT)
.child(catalogKey).child(commentKey);
commentRef.removeValue();
}
})
.show();
}
void bindModel(String catalogKey, String commentKey, String comment, String emailComment, String dateComment) {
tvComment.setText(comment);
String temp = emailComment.replaceAll("(?<=.).(?=[^@]*[email protected])", "*");
tvUser.setText(temp);
tvDate.setText(dateComment);
this.emailComment = emailComment;
this.commentKey = commentKey;
this.catalogKey = catalogKey;
}
}
FirebaseRecyclerAdapter代码:
mAdapter = new FirebaseRecyclerAdapter<Comment, CommentHolder>(Comment.class, R.layout.play_row
, CommentHolder.class, commentRef) {
@Override
public void populateViewHolder(CommentHolder commentHolder, Comment comment, int position) {
Date date = new Date((long) comment.getLastUpdate().get("date"));
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
String strDate = simpleDateFormat.format(date);
commentHolder.bindModel(catalogKey, getRef(position).getKey(), comment.getComment(), comment.getEmail(), strDate);
}
};
我Comment.java:
public class Comment {
String uid;
String email;
String comment;
HashMap<String, Object> lastUpdate;
public Comment() {
}
public Comment(String uid, String email, String comment) {
this.uid=uid;
this.email = email;
this.comment = comment;
HashMap<String, Object> lastUpdateObj = new HashMap<>();
lastUpdateObj.put("date", ServerValue.TIMESTAMP);
this.lastUpdate = lastUpdateObj;
}
public String getUid() {
return uid;
}
public String getEmail() {
return email;
}
public String getComment() {
return comment;
}
public HashMap<String, Object> getLastUpdate() {
return lastUpdate;
}
}
请修改您的问题以提供[mcve],包括与您的崩溃相关的Java堆栈跟踪以及您实施的FirebaseRecyclerAdapter。 – CommonsWare
@CommonsWare是的,谢谢。刚刚添加了java堆栈跟踪和我的代码 – Plugie
只是一个猜测:尝试使'CommentHolder'构造函数'public',看看会发生什么。 – CommonsWare