RecyclerView error : what makes widget null? - java

This is my error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.blogapp, PID: 20085
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.example.together.adapter.PetchingBunyangAdapter$2.onDataChange(PetchingBunyangAdapter.java:152)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database##17.0.0:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database##17.0.0:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database##17.0.0:55)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
I know what meaning of null but in this case i can not under stand
i try to using recycler in my fragment
This is my adapater that can't find widget
package com.example.together.adapter;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.example.together.R;
import com.example.together.activities.petching.PetchingBunyangDetailInfo;
import com.example.together.common.Common;
import com.example.together.model.PetchingBunyang;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.List;
public class PetchingBunyangAdapter extends RecyclerView.Adapter<PetchingBunyangAdapter.MyViewHolder> {
private static final String TAG = "PetchingBunyangAdapter";
FirebaseUser firebaseUser;
DatabaseReference reference;
Context mContext;
List<PetchingBunyang> mPetchingBunyang;
public PetchingBunyangAdapter(Context mContext, List<PetchingBunyang> mPetchingBunyang) {
this.mContext = mContext;
this.mPetchingBunyang = mPetchingBunyang;
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.item_petching_bunyang_pet_list, parent, false);
return new PetchingBunyangAdapter.MyViewHolder(view);
}
#Override
public void onBindViewHolder(MyViewHolder viewHolder, int position)
{
Common common = new Common();
final PetchingBunyang petchingBunyang = mPetchingBunyang.get(position);
petchingBunyang.getPetBunyangId();
Log.d(TAG, "AAAAAA"+mPetchingBunyang.get(0).getPetBunyangId());
Log.d(TAG, "TTTT "+petchingBunyang.getPetBunyangId());
Log.d(TAG, "onBindViewHolder: "+Log.d(TAG, "onBindViewHolder: "));
Log.d(TAG, "onBindViewHolder: 초코우유"+mPetchingBunyang.get(0).getPetBunyangId());
Log.d(TAG, "딸기우유: "+mPetchingBunyang.get(position).getPetBunyangId());
getPetInfo(mPetchingBunyang.get(position).getPetBunyangId(), viewHolder.img_pet, viewHolder.petName, viewHolder.petAge, viewHolder.petBreed, viewHolder.gender_m, viewHolder.gender_w);
viewHolder.itemView.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent = new Intent(mContext, PetchingBunyangDetailInfo.class);
// 디테일 정보 전달....
intent.putExtra("petname", mPetchingBunyang.get(position).getPetName());
intent.putExtra("intro", mPetchingBunyang.get(position).getPetAge());
intent.putExtra("Thumbnail", mPetchingBunyang.get(position).getPetBreed());
// start the activity
mContext.startActivity(intent);
}
});
}
#Override
public int getItemCount()
{
return mPetchingBunyang.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder
{
public TextView petName, petBreed, petAge;
public ImageView gender_m, gender_w, bunyangpet_detail, img_pet;
public MyViewHolder(View itemView)
{
super(itemView);
//펫 프로필
petName = itemView.findViewById(R.id.petName);
petBreed = itemView.findViewById(R.id.petBreed);
petAge = itemView.findViewById(R.id.petAge);
img_pet = itemView.findViewById(R.id.img_pet);
//이미지들
img_pet = itemView.findViewById(R.id.img_pet);
gender_m = itemView.findViewById(R.id.gender_m);
gender_w = itemView.findViewById(R.id.gender_w);
//상세보기 넘어가는 icon
bunyangpet_detail = itemView.findViewById(R.id.bunyangpet_detail);
}
}
// 펫 정보 이름, 나이, 견종, 성별,
private void getPetInfo(String petbunyangid, final ImageView imageView, final TextView petAge, final TextView petName, final TextView petBreed, final ImageView gender_m, final ImageView gender_w)
{
Log.d(TAG, "펫분양: "+petbunyangid);
firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("PetchingBunyang").child(petbunyangid);
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
PetchingBunyang petchingBunyang = dataSnapshot.getValue(PetchingBunyang.class);
Log.d(TAG, "펫정보 가져오는지 보자: "+petchingBunyang.getPetName());
Glide.with(mContext).load(petchingBunyang.getPetImg()).into(imageView);
petName.setText(petchingBunyang.getPetName());
petBreed.setText(petchingBunyang.getPetBreed());
petAge.setText(petchingBunyang.getPetAge());
//성별표시
if (petchingBunyang.getPetGender().equals("Female"))
{
gender_w.setVisibility(View.VISIBLE);
}else
{
gender_m.setVisibility(View.VISIBLE);
}
//
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
}
but i already get the widget as u see from here
From here i already added widget
public class MyViewHolder extends RecyclerView.ViewHolder{}
I don't understand what makes it null? eventhough it already exist

Try debugging these value , as one of the value might be coming null .
petchingBunyang.getPetName();
petchingBunyang.getPetBreed();
petchingBunyang.getPetAge()
and do check if Pet Age is String or not .

Related

Can't convert object of type java.util.ArrayList to type com.example.soas.POJO.Service

I am facing error While retrieving data from firebase Here is the error that i am receiving while getting data from firebase..
com.google.firebase.database.DatabaseException: Can't convert object of type java.util.ArrayList to type com.example.soas.POJO.Service
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database##19.3.0:435)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database##19.3.0:231)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database##19.3.0:79)
at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:firebase-database##19.3.0:203)
at com.example.soas.Activities.Services$2.onDataChange(Services.java:80)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database##19.3.0:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database##19.3.0:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database##19.3.0:55)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
2020-11-03 14:53:29.178 9848-9848/com.example.soas I/Process: Sending signal. PID: 9848 SIG: 9
Firebase Database Structure:
Services.Java
package com.example.soas.Activities;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.soas.Adapters.ServiceAdapter;
import com.example.soas.POJO.Service;
import com.example.soas.R;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
public class Services extends AppCompatActivity {
RecyclerView recyclerView;
FloatingActionButton fab;
FirebaseDatabase database;
DatabaseReference reference;
ArrayList<Service> serviceList;
String user;
FirebaseAuth mAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_services);
database = FirebaseDatabase.getInstance();
recyclerView = findViewById(R.id.serviceRecycler);
fab = findViewById(R.id.fab);
mAuth = FirebaseAuth.getInstance();
user = mAuth.getCurrentUser().getUid();
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
database = FirebaseDatabase.getInstance();
reference = database.getReference("Services");
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(Services.this, AddNewService.class);
startActivity(intent);
}
});
}
#Override
protected void onStart() {
super.onStart();
if (reference != null) {
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
if (snapshot.exists()) {
serviceList = new ArrayList<>();
for (DataSnapshot ds: snapshot.getChildren()) {
if (ds.getKey().equals(user)) {
serviceList.add(ds.getValue(Service.class));
ServiceAdapter serviceAdapter = new ServiceAdapter(serviceList);
recyclerView = findViewById(R.id.serviceRecycler);
recyclerView.setAdapter(serviceAdapter);
}
}
}
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
Toast.makeText(Services.this, error.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
}
Service.class(Object)
package com.example.soas.POJO;
public class Service {
public String name;
public Service() {
}
public Service(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
ServiceAdapter.java
package com.example.soas.Adapters;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.soas.POJO.Service;
import com.example.soas.R;
import java.util.ArrayList;
public class ServiceAdapter extends RecyclerView.Adapter<ServiceAdapter.MyViewHolder> {
ArrayList<Service> serviceList;
public ServiceAdapter(ArrayList<Service> serviceList) {
this.serviceList = serviceList;
}
#NonNull
#Override
public ServiceAdapter.MyViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.service_item,viewGroup,false);
return new MyViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ServiceAdapter.MyViewHolder myViewHolder, int i) {
myViewHolder.name.setText(serviceList.get(i).getName());
// myViewHolder.price.setText(serviceList.get(i).getPrice());
}
#Override
public int getItemCount() {
return serviceList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView name, price;
public MyViewHolder(View view) {
super(view);
name = itemView.findViewById(R.id.vServiceName);
price = itemView.findViewById(R.id.servicePrice);
}
}
}
You're missing a for loop over the 1...4 children in your JSON. In addition: you're loading all Services, while you only need the ones for the current user, so your code is wasting bandwidth and likely less secure.
To fix both problems, you can listen one level lower in the JSON tree, and update the code on onDataChange to match:
reference.child(user).addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
if (snapshot.exists()) {
serviceList = new ArrayList<>();
for (DataSnapshot ds: snapshot.getChildren()) {
serviceList.add(ds.getValue(Service.class));
}
ServiceAdapter serviceAdapter = new ServiceAdapter(serviceList);
recyclerView = findViewById(R.id.serviceRecycler);
recyclerView.setAdapter(serviceAdapter);
}
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
Toast.makeText(Services.this, error.getMessage(), Toast.LENGTH_SHORT).show();
}
});

Using an unspecified index

Hello StackOverflow Community, I wrote a Code to Search Users in the Firebase Database and every time I try to launch the Code it doesn't Show me the users.
In my Run log I get the following Message:
W/PersistentConnection: pc_0 - Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding '".indexOn": "username"' at users to your security and Firebase Database rules for better Performance
This is the Code which I wrote:
package com.example.ts.tsp.Fragment;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import com.example.ts.tsp.Adapter.UserAdapter;
import com.example.ts.tsp.Model1.User;
import com.example.ts.tsp.R;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
public class SearchFragment extends Fragment {
private RecyclerView recyclerView;
private UserAdapter userAdapter;
private List<User> mUsers;
EditText search_bar;
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_search, container, false);
recyclerView = view.findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
search_bar = view.findViewById(R.id.search_bar);
mUsers = new ArrayList<>();
userAdapter = new UserAdapter(getContext(), mUsers);
recyclerView.setAdapter(userAdapter);
readUsers();
search_bar.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
searchUsers(s.toString().toLowerCase());
}
#Override
public void afterTextChanged(Editable s) {
}
});
return view;
}
private void searchUsers(String s){
Query query = FirebaseDatabase.getInstance().getReference("Users").orderByChild("username")
.startAt(s)
.endAt(s+"\uf8ff");
query.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
mUsers.clear();
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
User user = snapshot.getValue(User.class);
mUsers.add(user);
}
userAdapter.notifyDataSetChanged();
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
private void readUsers(){
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("User");
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
if (search_bar.getText().toString().equals("")){
mUsers.clear();
for (DataSnapshot snapshot : dataSnapshot.getChildren()){
User user = snapshot.getValue(User.class);
mUsers.add(user);
}
userAdapter.notifyDataSetChanged();
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
}
And the Other Class:
package com.example.ts.tsp.Adapter;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.example.ts.tsp.Fragment.ProfileFragment;
import com.example.ts.tsp.Model1.User;
import com.example.ts.tsp.R;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.List;
import de.hdodenhof.circleimageview.CircleImageView;
public class UserAdapter extends RecyclerView.Adapter<UserAdapter.Viewholder>{
private Context mContext;
private List<User> mUsers;
private FirebaseUser firebaseUser;
public UserAdapter(Context mContext, List<User> mUsers) {
this.mContext = mContext;
this.mUsers = mUsers;
}
#NonNull
#Override
public Viewholder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(mContext) .inflate(R.layout.user_item, viewGroup, false);
return new UserAdapter.Viewholder(view);
}
#Override
public void onBindViewHolder(#NonNull final Viewholder viewHolder, int i) {
firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
final User user = mUsers.get(i);
viewHolder.btn_follow.setVisibility(View.VISIBLE);
viewHolder.username.setText(user.getUsername());
viewHolder.fullname.setText(user.getFullname());
Glide.with(mContext) .load(user.getImageurl()) .into(viewHolder.image_Profile);
isFollowing(user.getId(), viewHolder.btn_follow);
if (user.getId().equals(firebaseUser.getUid())){
viewHolder.btn_follow.setVisibility(View.GONE);
}
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SharedPreferences.Editor editor = mContext.getSharedPreferences( "PREFS", Context.MODE_PRIVATE) .edit();
editor.putString("profileid", user.getId());
editor.apply();
((FragmentActivity)mContext).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new ProfileFragment()).commit();
}
});
viewHolder.btn_follow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (viewHolder.btn_follow.getText().toString().equals("follow")) {
FirebaseDatabase.getInstance().getReference().child("Follow").child(firebaseUser.getUid())
.child("following").child(user.getId()).setValue(true);
FirebaseDatabase.getInstance().getReference().child("Follow").child(user.getId())
.child("followers").child(firebaseUser.getUid()).setValue(true);
} else {
FirebaseDatabase.getInstance().getReference().child("Follow").child(firebaseUser.getUid())
.child("following").child(user.getId()).removeValue();
FirebaseDatabase.getInstance().getReference().child("Follow").child(user.getId())
.child("followers").child(firebaseUser.getUid()).removeValue();
}
}
});
}
#Override
public int getItemCount() {
return 0;
}
public class Viewholder extends RecyclerView.ViewHolder{
public TextView username;
public TextView fullname;
public CircleImageView image_Profile;
public Button btn_follow;
public Viewholder(#NonNull View itemView) {
super(itemView);
username = itemView.findViewById(R.id.username);
fullname = itemView.findViewById(R.id.fullname);
image_Profile = itemView.findViewById(R.id.image_Profile);
btn_follow = itemView.findViewById(R.id.btn_follow);
}
}
private void isFollowing (final String userid, final Button button) {
DatabaseReference reference = FirebaseDatabase.getInstance().getReference()
.child("Follow").child(firebaseUser.getUid()).child("following");
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.child(userid).exists()){
button.setText("following");
} else {
button.setText("follow");
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
}
I hope someone can help you
Best Regard Tim schmitt
For using orderby:
FirebaseDatabase.getInstance().getReference("Users").orderByChild("username")
you have to add index on the specific field, update your rules in the Firebase Database console.
{
"rules": {
// By default all nodes are private
".read":false,
".write":false,
"Users": {
".read": true,
".write": "(auth!=null)",
".indexOn" : ["username"]
}
}
}
I would recommend using Cloud Firestore instead of Firebase Realtime Database.

Array Adapter Crash

I am creating an app using swipecards. It is supposed to pull through data from the Bookmakers Firebase table however when I launch it it crashes the app.
The code for the 3 referenced Java filed is below but there is no bugs and I can't spot the reason why it crashes.
BETSWIPE.java
package com.example.swoddz.swoddz;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.lorentzos.flingswipe.SwipeFlingAdapterView;
import java.util.ArrayList;
import java.util.List;
public class BetSwipe extends AppCompatActivity {
private ArrayList<String> al;
private ArrayAdapter<String> arrayAdapter;
private int i;
private FirebaseAuth mAuth;
List<cards2> rowItems;
#Override
protected void onCreate(Bundle savedInstanceState) {
//add the view via xml or programmatically
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bet_swipe);
al = new ArrayList<>();
al.add("php");
arrayAdapter = new ArrayAdapter<>(this, R.layout.item2, R.id.helloText, al );
rowItems = new ArrayList<cards2>();
SwipeFlingAdapterView flingContainer = (SwipeFlingAdapterView) findViewById(R.id.frame);
flingContainer.setAdapter(arrayAdapter);
flingContainer.setFlingListener(new SwipeFlingAdapterView.onFlingListener() {
#Override
public void removeFirstObjectInAdapter() {
// this is the simplest way to delete an object from the Adapter (/AdapterView)
Log.d("LIST", "removed object!");
rowItems.remove(0);
arrayAdapter.notifyDataSetChanged();
}
#Override
public void onLeftCardExit(Object dataObject) {
//Do something on the left!
//You also have access to the original object.
//If you want to use it just cast it (String) dataObject
Toast.makeText(BetSwipe.this, "Left", Toast.LENGTH_SHORT).show();
}
#Override
public void onRightCardExit(Object dataObject) {
Toast.makeText(BetSwipe.this, "Right", Toast.LENGTH_SHORT).show();
}
#Override
public void onAdapterAboutToEmpty(int itemsInAdapter) {
// Ask for more data here
al.add("XML ".concat(String.valueOf(i)));
arrayAdapter.notifyDataSetChanged();
Log.d("LIST", "notified");
i++;
}
#Override
public void onScroll(float scrollProgressPercent) {
}
});
// Optionally add an OnItemClickListener
flingContainer.setOnItemClickListener(new SwipeFlingAdapterView.OnItemClickListener() {
#Override
public void onItemClicked(int itemPosition, Object dataObject) {
Toast.makeText(BetSwipe.this, "clicked!", Toast.LENGTH_SHORT).show();
}
});
}
public void checkBookmakers() {
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
DatabaseReference BookmakerDB = FirebaseDatabase.getInstance().getReference().child("Football-Bets");
BookmakerDB.addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(#NonNull DataSnapshot dataSnapshot, #Nullable String s) {
if (dataSnapshot.exists()){
al.add(dataSnapshot.child("Bookmaker").getValue().toString());
}
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, #Nullable String s) {
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, #Nullable String s) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
ArryayApadpter2.JAVA
package com.example.swoddz.swoddz;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
/**
* Created by manel on 9/5/2017.
*/
public class arrayAdapter2 extends ArrayAdapter<cards>{
Context context;
public arrayAdapter2(Context context, int resourceId, List<cards> items){
super(context, resourceId, items);
}
public View getView(int position, View convertView, ViewGroup parent){
cards card_item = getItem(position);
if (convertView == null){
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item, parent, false);
}
TextView Bookmaker = (TextView) convertView.findViewById(R.id.name);
ImageView image = (ImageView) convertView.findViewById(R.id.image);
Bookmaker.setText(card_item.getName());
// image.setImageResource(R.mipmap.ic_launcher);
return convertView;
}
}
CARDS2.Java
package com.example.swoddz.swoddz;
public class cards2 {
private String userId;
private String Bookmaker;
public cards2(String userId, String name){
this.userId = userId;
this.Bookmaker = Bookmaker;
}
public String getUserId(){
return userId;
}
public void setUserID(String userID){
this.userId = userId;
}
public String getBookmaker(){
return Bookmaker;
}
public void setBookmaker(String Bookmaker){
this.Bookmaker = Bookmaker;
}
}
Stack Trace
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.swoddz.swoddz, PID: 371
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.remove(ArrayList.java:477)
at com.example.swoddz.swoddz.BetSwipe$1.removeFirstObjectInAdapter(BetSwipe.java:63)
at com.lorentzos.flingswipe.SwipeFlingAdapterView$1.onCardExited(SwipeFlingAdapterView.java:223)
at com.lorentzos.flingswipe.FlingCardListener$1.onAnimationEnd(FlingCardListener.java:256)
at android.view.ViewPropertyAnimator$AnimatorEventListener.onAnimationEnd(ViewPropertyAnimator.java:1121)
at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1149)
at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1309)
at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146)
at android.animation.AnimationHandler.-wrap2(AnimationHandler.java)
at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:925)
at android.view.Choreographer.doCallbacks(Choreographer.java:702)
at android.view.Choreographer.doFrame(Choreographer.java:635)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Disconnected from the target VM, address: 'localhost:8600', transport: 'socket'
Database Structure

how to get the post key with position in Firebase Android

package com.novela.minha.novela;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.firebase.client.Firebase;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
public class MyAdapter extends RecyclerView.Adapter<MyHolder> {
Context c;
ArrayList<Beaches> beaches;
private long itemId;
private Firebase firebase;
Firebase likeRef;
FirebaseAuth user;
public com.firebase.client.Firebase Ref ;
private DatabaseReference Database = FirebaseDatabase.getInstance().getReference();
private DatabaseReference mDatabaseLike = FirebaseDatabase.getInstance().getReference().child("Likes");
private boolean mProcessLike = false;
public MyAdapter(Context c, ArrayList<Beaches> beaches){
this.c= c;
this.beaches=beaches;
}
#Override
public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v= LayoutInflater.from(parent.getContext()).inflate(R.layout.card,parent,false);
final MyHolder holder= new MyHolder(v);
return holder;
}
#Override
public void onBindViewHolder(final MyHolder holder, final int position) {
final String post_key = Database.getRef(position).getKey().toString(); // <- Error
mDatabaseLike.keepSynced(true);
holder.nameTxt.setText(beaches.get(position).getName());
holder.textoTxt.setText(beaches.get(position).getTexto());
holder.siteTxt.setText(beaches.get(position).getSite());
holder.emissoraTxt.setText(beaches.get(position).getEmissora());
holder.enderecoTxt.setText(beaches.get(position).getEndereco());
PicassoClient.downloadimg(c, beaches.get(position).getUrl(),holder.img);
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String url = beaches.get(position).getEndereco().toString();
Intent intent = new Intent( v.getContext().getApplicationContext(), Web.class);
intent.putExtra("VALOR", url);
v.getContext().getApplicationContext().startActivity(intent);
}
});
holder.like.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(final View v) {
Toast.makeText(v.getContext(), post_key, Toast.LENGTH_SHORT).show();
mProcessLike = true ;
if (mProcessLike) {
mDatabaseLike.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
});
}
#Override
public int getItemCount() {
return beaches.size();
}
}
Note that getRef does not accept position,
returns an error, which could be done in the code, I already searched here in the Forum but I did not find a solution, thank you ,Note that getRef does not accept position,
returns an error, which could be done in the code, I already searched here in the Forum
 but I did not find a solution, I'm new to programming, thank you
final String post_key = Database.push().getKey();

How to remove Card View from Recycler View, from a separate Activity

Here's the situation:
I am trying to remove a users information from an ArrayList(populated via Firebase Database) on a Card View.
This Card View is populated in the Recycler View. When the user clicks on a Card in the Recycler view, they are brought to a detail activity via an Intent.
In the intent, there is more user data as well as the option to approve or reject the user.
I want to be able to reject the user and then remove their card from the Recycler View.
I keep running into a null pointer error and I am not sure where else to go.
Stack trace is at the end.
Thank you very much for your time and assistance in this matter.
Relevant code below:
Fragment:
package org.codefordenver.encorelink;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import java.util.ArrayList;
import java.util.Objects;
public class OrganizerDashboardPendingTab extends Fragment {
private String userId;
//Arraylist to hold our list of volunteer musicians
public static ArrayList<String> volunteerSmallView = new ArrayList<>();
public static ArrayList<String> volunteerDetail = new ArrayList<>();
public static ArrayList<String> volunteerLink = new ArrayList<>();
//private String field members to hold temp String data
private String tempFirst;
private String tempTalent;
private String tempLastName;
private String tempPhoneNumber;
private String tempStreetAddress;
private String tempCity;
private String tempZipcode;
public static String tempVideoLink;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
final RecyclerView musicianInfoRecycler = (RecyclerView) inflater.inflate(R.layout.tab1, container, false);
//Checking to make sure user is logged in and is not null
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
userId = user.getUid();
}
//setting DatabaseReference variable so we can search through the correct node in our DB
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference().child(CreateMusicianProfile.MUSICIAN_PROFILE);
//Instantiating and declaring our Adapter object for our Recycler View
final PendingMusicianInfoAdapter adapter = new PendingMusicianInfoAdapter(volunteerSmallView);
//this clear is a must so we aren't getting duplicated data in the cardview
volunteerSmallView.clear();
//Adding child event listener to our database object
mDatabase.addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
//iterate through each dataSnapshot inside mDatabase
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
//if we get a first name, add it to temp string
if (dataSnapshot1.getKey().equals("firstName")) {
tempFirst = Objects.requireNonNull(dataSnapshot1.getValue(String.class));
}
if (dataSnapshot1.getKey().equals("lastName")) {
tempLastName = Objects.requireNonNull(dataSnapshot1.getValue(String.class));
}
//if we get a musical talent, save it also into a temp string
if (dataSnapshot1.getKey().equals("musicalTalent")) {
tempTalent = Objects.requireNonNull("\nTalent: " + dataSnapshot1.getValue(String.class));
//in order to display all the string data together in one card,
//we have to add each temp string to the array list.
volunteerSmallView.add(tempFirst + " " + tempLastName + tempTalent);
}
if (dataSnapshot1.getKey().equals("phoneNumber")) {
tempPhoneNumber = Objects.requireNonNull( dataSnapshot1.getValue(String.class));
}
if (dataSnapshot1.getKey().equals("streetAddress")) {
tempStreetAddress = Objects.requireNonNull(dataSnapshot1.getValue(String.class));
}
if (dataSnapshot1.getKey().equals("city")) {
tempCity = Objects.requireNonNull(dataSnapshot1.getValue(String.class));
}
if (dataSnapshot1.getKey().equals("zipcode")) {
tempZipcode = Objects.requireNonNull("Zipcode: " + dataSnapshot1.getValue(String.class));
}
if (dataSnapshot1.getKey().equals("videoLink")) {
tempVideoLink = Objects.requireNonNull(dataSnapshot1.getValue(String.class));
volunteerLink.add(tempVideoLink);
volunteerDetail.add(tempFirst + " " + tempLastName +
"\n" + tempPhoneNumber +
"\n" + tempStreetAddress +
"\n" + tempCity + ", " + tempZipcode + "\n" + tempTalent + "\n");
}
}
//set adapater equal to our adapater object
musicianInfoRecycler.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
adapter.notifyDataSetChanged();
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
adapter.notifyDataSetChanged();
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
musicianInfoRecycler.setLayoutManager(linearLayoutManager);
adapter.setListener(new PendingMusicianInfoAdapter.Listener() {
#Override
public void onClick(int position) {
Intent intent = new Intent(getActivity(), MusicianDetails.class);
intent.putExtra(MusicianDetails.EXTRA_NUMBER, position);
getActivity().startActivity(intent);
}
});
return musicianInfoRecycler;
}
}
RecyclerView Adapter:
This class contains the rejectionButton and the onClickListener but it is always pointing to null.
package org.codefordenver.encorelink;
import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
public class PendingMusicianInfoAdapter extends RecyclerView.Adapter<PendingMusicianInfoAdapter.ViewHolder> {
private ArrayList<String> musicianInfo;
private Listener listener;
public interface Listener {
void onClick(int position);
}
public void setListener(Listener listener) {
this.listener = listener;
}
class ViewHolder extends RecyclerView.ViewHolder {
private CardView cardView;
Button rejectionButton;
public ViewHolder(CardView view) {
super(view);
cardView = view;
rejectionButton = view.findViewById(R.id.musician_rejection);
rejectionButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
removeAt(getAdapterPosition());
}catch (Exception e) {
e.printStackTrace();
}
}
});
}
void bind(final int position) {
TextView textView = cardView.findViewById(R.id.pending_musician_info);
textView.setText(musicianInfo.get(position));
cardView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (listener != null) {
listener.onClick(position);
}
}
});
}
void removeAt(int position) {
musicianInfo.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, musicianInfo.size());
}
}
public PendingMusicianInfoAdapter(ArrayList<String> musicianInfo) {
this.musicianInfo = musicianInfo;
}
//called when recyclerview instantiates new viewholder instance
//creates the views
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
CardView cv = (CardView) LayoutInflater.from(parent.getContext()).inflate(R.layout.card_musician_info, parent, false);
return new ViewHolder(cv);
}
//called when recycler view wants to populate data from model for the user to see
//after each view holder is created, recycler view calls onBindViewHolder to populate item
//with data
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.bind(position);
}
//returns number of items in data source
#Override
public int getItemCount() {
return musicianInfo.size();
}
}
Musician Details class that is triggered from the OrganizerDashboardPendingTab class.
package org.codefordenver.encorelink;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Patterns;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import java.util.ArrayList;
import java.util.Objects;
import java.util.regex.Matcher;
public class MusicianDetails extends AppCompatActivity {
public static final String EXTRA_NUMBER = "number";
//
// public static ArrayList<String> approvedMusicians = new ArrayList<>();
private TextView closeButton;
public static int cardNumber;
private String talentURL;
private TextView musicalTalentLink;
private Button approvalButton;
private FirebaseAuth firebaseAuth;
private DatabaseReference databaseReference;
private String userId;
public static boolean approved;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_musician_details);
closeButton = findViewById(R.id.x_button);
TextView textView = findViewById(R.id.musician_details);
musicalTalentLink = findViewById(R.id.musical_talent_link);
approvalButton = findViewById(R.id.musician_approval);
databaseReference = FirebaseDatabase.getInstance().getReference();
firebaseAuth = FirebaseAuth.getInstance();
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
userId = user.getUid();
}
cardNumber = (int) Objects.requireNonNull(getIntent().getExtras()).get(EXTRA_NUMBER);
String musicianDetails = OrganizerDashboardPendingTab.volunteerDetail.get(cardNumber);
findURL(OrganizerDashboardPendingTab.volunteerLink);
musicalTalentLink.setText(talentURL);
textView.setText(musicianDetails);
musicalTalentLink.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(talentURL));
startActivity(intent);
} catch (ActivityNotFoundException e){
Toast.makeText(MusicianDetails.this, "Bad URL!", Toast.LENGTH_SHORT).show();
}
}
});
approvalButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// approvedMusicians.add(OrganizerDashboardPendingTab.volunteerDetail.get(cardNumber));
databaseReference.child(CreateOrganizerProfile.ORGANIZER_PROFILE).child(userId).child("approved_musicians").child(String.valueOf(cardNumber)).
setValue(OrganizerDashboardPendingTab.volunteerDetail.get(cardNumber));
Toast.makeText(MusicianDetails.this, "Musician approved!", Toast.LENGTH_SHORT - 3).show();
Toast.makeText(MusicianDetails.this, "Moving musician to In Progress...", Toast.LENGTH_SHORT).show();
approved = true;
}
});
closeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
public void findURL(ArrayList<String> data) {
Matcher m = Patterns.WEB_URL.matcher(data.get (cardNumber));
while (m.find()) {
String url = m.group();
talentURL = url;
}
}
}
card_musician_info.xml :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/musician_info_cardview"
card_view:cardElevation="3.5sp"
android:layout_margin="8dp"
card_view:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/pending_musician_info"
android:textSize="25dp"
android:paddingLeft="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
Stack trace:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.codefordenver.encorelink, PID: 12123
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at org.codefordenver.encorelink.PendingMusicianInfoAdapter$ViewHolder.<init>(PendingMusicianInfoAdapter.java:41)
at org.codefordenver.encorelink.PendingMusicianInfoAdapter.onCreateViewHolder(PendingMusicianInfoAdapter.java:94)
at org.codefordenver.encorelink.PendingMusicianInfoAdapter.onCreateViewHolder(PendingMusicianInfoAdapter.java:16)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6493)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5680)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5563)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5559)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2229)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1556)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1516)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:608)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3693)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3410)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3962)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1767)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:132)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1361)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:869)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:761)
at android.view.View.layout(View.java:19659)
at android.view.ViewGroup.layout(ViewGroup.java:6075)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2496)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2212)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1392)
E/AndroidRuntime: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6752)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
In your PendingMusicianInfoAdapter you are using:-
rejectionButton = view.findViewById(R.id.musician_rejection); //here is your null pointer
Reason:-
In you card_musician_info.xml
you don't have any Button "musician_rejection"
NOTE:- Every time you face any null pointer issue it is most commonly due to wrong initialization/ id mismatch / or no reference in correct XML.
In this case, you may have "musician_rejection" earlier which was registered in your "R" class but later you may have removed it but in your "R" class it somehow stays. Or it can be quite possible that you may have "musician_rejection" in some other XML. Android Studio is not that smart enough to understand that use parent XML file for all its id references in JAVA file.
Use http://jakewharton.github.io/butterknife/ which eliminates all such issues.
Use debugger step by step, For better understanding.
I think in this situation you need to use EventBus.
Try https://github.com/greenrobot/EventBus

Categories

Resources