Я хочу отправить свое строковое значение из My recyclerview в JobDetail Activity с помощью Recyclerview onClick Listerner. но когда я использую putExtra и получаю намерение, используя getStringExtrast, он всегда возвращает ноль.
это мой адаптер RecyclerView
DiscoverAdapter.java
public class DiscoverAdapter extends RecyclerView.Adapter<DiscoverAdapter.ViewHolder>{
public List<JobPost> jobsList;
public Context context;
private Intent jobDetailActivity;
private FirebaseAuth mAuth ;
private FirebaseUser user;
public DiscoverAdapter(Context context, List<JobPost> jobsList){
this.context = context;
this.jobsList = jobsList;
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser();
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.job_list,parent,false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.tittle_text.setText(jobsList.get(position).getTittle());
holder.budget_text.setText(jobsList.get(position).getBudget());
final String description = jobsList.get(position).getDescription();
final String email = jobsList.get(position).getEmail();
final String status = jobsList.get(position).getStatus();
final String username = jobsList.get(position).getUsername();
final String titlle = holder.tittle_text.getText().toString();
final String budget = holder.budget_text.getText().toString();
final String coba="";
//get post id
final String post_id = jobsList.get(position).postId;
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
jobDetailActivity=null;
int post = position;
try {
String current_email = user.getEmail();
FirebaseUser user = mAuth.getCurrentUser();
if(user !=null ){
jobDetailActivity = new Intent(v.getContext(), JobDetailActivityLogin.class);
}
}
catch(Exception e){
jobDetailActivity = new Intent(v.getContext(), JobDetailActivity.class);
}
jobDetailActivity.putExtra("coba",coba);
jobDetailActivity.putExtra("postId",post_id);
jobDetailActivity.putExtra("username",username);
jobDetailActivity.putExtra("description",description);
jobDetailActivity.putExtra("tittle",titlle);
jobDetailActivity.putExtra("email",email);
jobDetailActivity.putExtra("budget",budget);
jobDetailActivity.putExtra("status",status);
v.getContext().startActivity(jobDetailActivity);
Toast.makeText(v.getContext(), "CLICKED " + post_id + ", " + description + ", " + titlle + ", " + email + ", " + budget+","+status, Toast.LENGTH_SHORT).show();
}
});
}
@Override
public int getItemCount() {
return jobsList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
View mView;
public TextView tittle_text;
public TextView budget_text;
/**
public TextView description_text,email_text, status_text,username_text;
**/
public ViewHolder(View itemView) {
super(itemView);
mView = itemView;
tittle_text = (TextView)mView.findViewById(R.id.tittle_text);
budget_text = (TextView)mView.findViewById(R.id.budget_text);
}
}
}
и это мой JobDetailActivity
public class JobDetailActivity extends AppCompatActivity {
private String tittle,description,status,username,budget,postId,email = "Null";
private Intent intent =getIntent();
private TextView txtTittle, txtDesc, txtStatus, txtUsername, txtBudget, txtPostId, txtEmail;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_job_detail);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
tittle= intent.getStringExtra("tittle");
description= intent.getStringExtra("description");
status= intent.getStringExtra("status");
username= intent.getStringExtra("username");
budget= intent.getStringExtra("budget");
postId= intent.getStringExtra("postId");
email= intent.getStringExtra("email");
txtTittle = (TextView)findViewById(R.id.txt_detailTittle);
txtDesc = (TextView)findViewById(R.id.txt_desc);
txtStatus = (TextView)findViewById(R.id.txt_status);
txtUsername = (TextView)findViewById(R.id.txt_username);
txtBudget = (TextView)findViewById(R.id.txt_budget);
txtTittle.setText(tittle);
txtDesc.setText(description);
txtStatus.setText(status);
txtUsername.setText(username);
txtBudget.setText(budget);
Toast.makeText(getApplicationContext(), "CLICKED " + postId + ", " + description + ", " + tittle + ", " + email + ", " + budget+","+status, Toast.LENGTH_SHORT).show();
}
@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}
}
this myError:
java.lang.RuntimeException: Невозможно запустить действие ComponentInfo {com.example.kodingsquad.lancerlots / com.example.kodingsquad.lancerlots.JobDetailActivity}: java.lang.NullPointerException: попытка вызвать виртуальный метод 'java.lang. String android.content.Intent.getStringExtra (java.lang.String) 'для ссылки на пустой объект