我的应用程序崩溃了。 我想知道我的路径是否从firebase获取数据使其崩溃?
以下是我的班级:
package com.handymanapp.handymanapplication.Model;
import com.google.firebase.database.Exclude;
import java.util.HashMap;
import java.util.Map;
public class Post {
String jobname;
String jobwage;
String jobarea;
String jobenvironment;
String jobdesc;
String contactnumber;
String jobtype;
String jobtime;
public Post() {
}
public Post(String jobname, String jobwage, String jobarea, String
jobenvironment, String jobdesc, String contactnumber, String jobtype, String
jobtime, String imageUrl) {
this.jobname = jobname;
this.jobwage = jobwage;
this.jobarea = jobarea;
this.jobenvironment = jobenvironment;
this.jobdesc = jobdesc;
this.contactnumber = contactnumber;
this.jobtype = jobtype;
this.jobtime = jobtime;
}
public void setJobname(String jobname) {
this.jobname = jobname;
}
public void setJobwage(String jobwage) {
this.jobwage = jobwage;
}
public void setJobarea(String jobarea) {
this.jobarea = jobarea;
}
public void setJobenvironment(String jobenvironment) {
this.jobenvironment = jobenvironment;
}
public void setJobdesc(String jobdesc) {
this.jobdesc = jobdesc;
}
public void setContactnumber(String contactnumber) {
this.contactnumber = contactnumber;
}
public void setJobtype(String jobtype) {
this.jobtype = jobtype;
}
public void setJobtime(String jobtime) {
this.jobtime = jobtime;
}
public String getJobname() {
return jobname;
}
public String getJobwage() {
return jobwage;
}
public String getJobarea() {
return jobarea;
}
public String getJobenvironment() {
return jobenvironment;
}
public String getJobdesc() {
return jobdesc;
}
public String getContactnumber() {
return contactnumber;
}
public String getJobtime() {
return jobtime;
}
}
这是我的主要活动:
package com.handymanapp.handymanapplication;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.Toolbar;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.handymanapp.handymanapplication.Interface.ItemClickListener;
import com.handymanapp.handymanapplication.Model.Post;
import com.handymanapp.handymanapplication.ViewHolder.PostViewHolder;
import com.squareup.picasso.Picasso;
public class joblist extends AppCompatActivity {
RecyclerView recycler_menu;
RecyclerView.LayoutManager layoutManager;
FirebaseDatabase database;
DatabaseReference post;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_joblist);
post = database.getInstance().getReference().child("Advertisement-post");
recycler_menu = (RecyclerView)findViewById(R.id.recycler_job);
recycler_menu.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recycler_menu.setLayoutManager(layoutManager);
loadMenu();
}
private void loadMenu() {
FirebaseRecyclerAdapter<Post,PostViewHolder> adapter = new FirebaseRecyclerAdapter<Post, PostViewHolder>(Post.class,R.layout.job_item,PostViewHolder.class,post) {
@Override
protected void populateViewHolder(PostViewHolder viewHolder, Post model, int position) {
viewHolder.jobnameview.setText(model.getJobname());
viewHolder.jobwageview.setText(model.getJobwage());
viewHolder.jobareaview.setText(model.getJobarea());
final Post clickItem = model;
viewHolder.setItemClickListener(new ItemClickListener() {
@Override
public void onClick(View view, int position, boolean isLongClick) {
Toast.makeText(joblist.this,""+clickItem.getJobname(), Toast.LENGTH_SHORT).show();
}
});
}
};
recycler_menu.setAdapter(adapter);
}
}
我的观点持有人:
package com.handymanapp.handymanapplication.ViewHolder;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;
import com.handymanapp.handymanapplication.Interface.ItemClickListener;
import com.handymanapp.handymanapplication.R;
public class PostViewHolder extends RecyclerView.ViewHolder implements
View.OnClickListener {
public TextView jobnameview;
public TextView jobwageview;
public TextView jobareaview;
private ItemClickListener itemClickListener;
public void setItemClickListener(ItemClickListener itemClickListener) {
this.itemClickListener = itemClickListener;
}
public PostViewHolder(View itemView) {
super(itemView);
jobnameview = (TextView)itemView.findViewById(R.id.jobnameview);
jobwageview = (TextView)itemView.findViewById(R.id.jobwageview);
jobareaview = (TextView)itemView.findViewById(R.id.jobareaview);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
itemClickListener.onClick(view,getAdapterPosition(),false);
}
}
我在创建新帖子时使用push来生成id,所以我尝试在recycler视图中将其检索回来。我不知道节点的路径如何
这是我的推动:
mUserDatabase = FirebaseDatabase.getInstance().getReference().child("Advertisement-post").push();