- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个组 Activity ,其中用户连接的所有组都可以通过此 Activity 显示。我已经创建了组 Activity 并在其中插入了回收器 View ,并尝试从数据库中检索数据,但不幸的是,当我在 Android 手机上运行应用程序时遇到错误。应用程序崩溃,在 logcat 中,我收到消息“无法将 java.lang.String 类型的对象转换为 com.nanb.alpha.modelclass 类型”。如果您不介意,请帮助我,以便我完成我的 Activity 。
下面的代码是用户可以创建群组的代码。
private void groupmethos(final String groupname) {
DatabaseReference groupref = rootref.child("Group").push();
final String grouppushid = groupref.getKey();
Map groupmap = new HashMap<>();
groupmap.put("GroupprofileName",groupname);
groupmap.put("Creater",currentUser.getUid());
groupmap.put("StatusGroup","");
groupmap.put("profileimage","");
groupmap.put("id",grouppushid);
rootref.child("Group").child(grouppushid).updateChildren(groupmap).addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
rootref.child("GroupMessage").child(grouppushid).setValue("").addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()){
rootref.child("userconnectedtogroup").child(currentUser.getUid()).child(grouppushid).setValue("Added").addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(MainActivity.this,groupname + "group Created successfully",Toast.LENGTH_SHORT).show();
}
});
}
}
});
}
});
}
在上面的代码中,用户请求创建一个组。下面给出的是使用 getter 和 setter 从数据库获取数据的代码。
package com.nanb.alpha;
public class modelclass {
private String GroupprofileName,StatusGroup,profileimage;
public modelclass() {
}
public modelclass(String groupprofileName, String statusGroup, String profileimage) {
this.GroupprofileName = groupprofileName;
this.StatusGroup = statusGroup;
this.profileimage = profileimage;
}
public String getGroupprofileName() {
return GroupprofileName;
}
public void setGroupprofileName(String groupprofileName) {
GroupprofileName = groupprofileName;
}
public String getStatusGroup() {
return StatusGroup;
}
public void setStatusGroup(String statusGroup) {
StatusGroup = statusGroup;
}
public String getProfileimage() {
return profileimage;
}
public void setProfileimage(String profileimage) {
this.profileimage = profileimage;
}
}
给定的代码是 recyclerview 将值设置为给定布局的代码。
public class group extends AppCompatActivity {
private RecyclerView recyclerView;
private DatabaseReference conref,groupref;
private FirebaseAuth mAuth;
private String Currentuserid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_group);
intialiation();
mAuth = FirebaseAuth.getInstance();
Currentuserid = mAuth.getCurrentUser().getUid();
conref = FirebaseDatabase.getInstance().getReference().child("userconnectedtogroup").child(Currentuserid);
groupref = FirebaseDatabase.getInstance().getReference().child("Group");
}
private void intialiation() {
recyclerView = findViewById(R.id.recyclerview);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
}
@Override
protected void onStart() {
super.onStart();
FirebaseRecyclerOptions option = new FirebaseRecyclerOptions.Builder<modelclass>().setQuery(conref,modelclass.class).build();
FirebaseRecyclerAdapter<modelclass,group_viewHolder> adapter = new FirebaseRecyclerAdapter<modelclass, group_viewHolder>(option) {
@Override
protected void onBindViewHolder(@NonNull final group_viewHolder group_viewHolder, int i, @NonNull modelclass modelclass) {
String userid = getRef(i).getKey();
groupref.child(userid).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.hasChild("profileimage")){
String profileimage = dataSnapshot.child("profileimage").getValue().toString();
String groupname = dataSnapshot.child("GroupprofileName").getValue().toString();
String groupStatus = dataSnapshot.child("StatusGroup").getValue().toString();
group_viewHolder.groupname.setText(groupname);
group_viewHolder.groupStatus.setText(groupStatus);
Picasso.get().load(profileimage).into(group_viewHolder.profileimage);
}else{
String groupname = dataSnapshot.child("GroupprofileName").getValue().toString();
String groupStatus = dataSnapshot.child("StatusGroup").getValue().toString();
group_viewHolder.groupname.setText(groupname);
group_viewHolder.groupStatus.setText(groupStatus);
Picasso.get().load(R.mipmap.groupicon).into(group_viewHolder.profileimage);
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
@NonNull
@Override
public group_viewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.grouplayout,parent,false);
group_viewHolder groupholder = new group_viewHolder(view);
return groupholder;
}
};
recyclerView.setAdapter(adapter);
adapter.startListening();
}
public static class group_viewHolder extends RecyclerView.ViewHolder{
TextView groupname,groupStatus;
CircleImageView profileimage;
public group_viewHolder(@NonNull View itemView) {
super(itemView);
groupname = itemView.findViewById(R.id.Group_name);
groupStatus = itemView.findViewById(R.id.Group_Status);
profileimage = itemView.findViewById(R.id.group_profile_dp);
}
}
}
下面给出的是我的 Firebase 数据库的图像。其中显示了与团体 Activity 相关的所有结构。
下面是应用程序崩溃后显示的 logcat 消息。
com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.String to type com.nanb.alpha.modelclass at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@19.1.0:418) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@19.1.0:214) at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database@@19.1.0:79) at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:firebase-database@@19.1.0:203) at com.firebase.ui.database.ClassSnapshotParser.parseSnapshot(ClassSnapshotParser.java:29) at com.firebase.ui.database.ClassSnapshotParser.parseSnapshot(ClassSnapshotParser.java:15) at com.firebase.ui.common.BaseCachingSnapshotParser.parseSnapshot(BaseCachingSnapshotParser.java:35) at com.firebase.ui.common.BaseObservableSnapshotArray.get(BaseObservableSnapshotArray.java:52) at com.firebase.ui.database.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:106) at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:122) at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6781) at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6823) at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5752) at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6019) at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858) at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854) at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230) at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557) at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517) at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612) at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924) at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641) at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4194) at android.view.View.layout(View.java:15689) at android.view.ViewGroup.layout(ViewGroup.java:5048) at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1915) at android.view.View.layout(View.java:15689) at android.view.ViewGroup.layout(ViewGroup.java:5048) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579) at android.widget.FrameLayout.onLayout(FrameLayout.java:514) at android.view.View.layout(View.java:15689) at android.view.ViewGroup.layout(ViewGroup.java:5048) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557) at android.widget.LinearLayout.onLayout(LinearLayout.java:1466) at android.view.View.layout(View.java:15689) at android.view.ViewGroup.layout(ViewGroup.java:5048) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579) at android.widget.FrameLayout.onLayout(FrameLayout.java:514) at android.view.View.layout(View.java:15689) at android.view.ViewGroup.layout(ViewGroup.java:5048) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557) at android.widget.LinearLayout.onLayout(LinearLayout.java:1466) at android.view.View.layout(View.java:15689) at android.view.ViewGroup.layout(ViewGroup.java:5048) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579) at android.widget.FrameLayout.onLayout(FrameLayout.java:514) at android
最佳答案
在选项对象中使用 groupref 而不是 conref
关于java - 我正在尝试使用 getter 和 setter 从我的 firebase 数据库中检索数据,但收到错误消息说无法转换对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59208109/
如果我使用下面的代码,数据将为零 dispatch_async(dispatch_get_global_queue(0,0), ^{ UIImage *img = [[UIImage allo
fread来自 data.table包一般可以在读取文件时自动确定列分隔符( sep )。 例如,这里fread自动检测 |作为列分隔符: library(data.table) fread(past
因此,如果我有一个如下所示的数据框: A B C rowname1 4.5 4 3.2 rowname2 3 23
我有一个汽车模型的搜索数据库:“日产Gtr”,“Huynday Elantra”,“Honda Accord”等。 现在我还有一个用户列表和他们喜欢的汽车类型 user1喜欢:carId:1234,c
我正在使用 Javamail 来获取一些电子邮件数据。我将用户输入作为电子邮件 ID、imap 地址和密码并连接到 imap。然后我监视收件箱的电子邮件并查明此人是否在“收件人”或“抄送”中。 Ema
我有一些数据,我想根据差距统计来评估最佳簇数。 我阅读了 gap statistic 上的页面在 r 中给出了以下示例: gs.pam.RU Number of clusters (method '
我有一个用户名和密码组合,我将使用它通过 java 代码访问安全服务器。 我的想法是: 在外部存储加密凭据 执行时提示用户输入解密密码 在使用前将解密的凭据直接存储在字符数组中 使用凭据连接到数据库
这是 Firebase 数据:[Firebase 数据][1] 我必须从员工那里检索所有字段并将其存储在一个数组中。 现在数据更改 toast 消息即将到来,但已经很晚了。 Firebase.setA
我是 iOS 的新手,正在开发一个基本的应用程序,它目前正在使用 SSKeychain 和 AFNetworking 与 API 进行交互。当您使用我检索的应用程序登录并在我的 CredentialS
编辑:这个问题已经在 apphacker 和 ConcernedOfTunbridgeWells 的帮助下得到解决。我已更新代码以反射(reflect)我将使用的解决方案。 我目前正在编写一个群体智能
我是 C 的新手,我想编写一个程序来检查用户输入的单词是否合法。我已经在 stackoverflow 上搜索了建议,但很多都是针对特定情况的。请在我被激怒之前,我知道这个语法不正确,但正在寻找一些关于
我相信你们中的一些人编写过 C# 类,这些类必须从数据库设置密码/从数据库获取密码。 我假设敏感细节不会以明文形式显示。处理此类数据的推荐程序是什么?检索到的文本是否加密?您是否将 pws 存储在加密
我在 linux 上使用 2.7 之前的 python 版本,想知道如何检索 RUID? 2.7 及更高版本从 os 包中获得了 getresuid,但我似乎找不到 2.6 的等效项 最佳答案 您可以
我已经在 Android 中实现了一个存储对象的标准 LRUCache。每个键都是与存储的对象关联的唯一 ObjectId。我的问题是从缓存中检索对象的唯一方法是通过 ObjectId(无迭代器)。实
这已经被问过很多次了。解决方案(对我有用)是从 packages.config 文件(这就足够了)和 packages 文件夹中删除 *** 包。 这对我来说是一个糟糕的解决方案,因为每次我想安装一些
我有以下文字: #{king} for a ##{day}, ##{fool} for a #{lifetime} 以及以下(损坏的)正则表达式: [^#]#{[a-z]+} 我想匹配所有#{word
我正在寻找一种快速(如高性能,而不是快速修复)解决方案来持久化和检索数千万个小型(大约 1k)二进制对象。每个对象都应该有一个用于检索的唯一 ID(最好是 GUID 或 SHA)。额外的要求是它应该可
有没有办法获取 RegInit 的重置值?通过探测产生的类型的成员?我可以看到 RegInit 将返回类型(例如 UInt )。例如,我将有一个寄存器,我想通过 regmap 对其进行控制。 val
Iv 目前接手了一个项目,其中开发人员在某些表的 json 数组列中存储了 has many 关系。 产品表 ---------------------------- id | product | c
Git 会在任何地方记录推送到远程的历史吗? 我注意到我们能够在 Microsoft VSTS 中查看 Git 存储库的推送历史记录以及每次推送的相关提交。它甚至显示旧的、过时的提交,由于后来的强制推
我是一名优秀的程序员,十分优秀!