Soru & Cevap

CustomAdapter'de null pointer hatası (ArrayAdapter)

28.03.2015 - 05:06


public class UserCustomAdapter extends ArrayAdapter<User> {
 
  UserHolder holder = null;
  Context context;
  int layoutResourceId;
  ArrayList<User> data = new ArrayList<User>();
  public UserCustomAdapter(Context context, int layoutResourceId,
    ArrayList<User> data) {
    super(context, layoutResourceId, data);
    this.layoutResourceId = layoutResourceId;
    this.context = context;
    this.data = data;
    }
    @Override
    public View getView(int position, final View convertView, ViewGroup parent) {
    
     View row = convertView;
    
    if (row == null) {
     LayoutInflater inflater = ((MainActivity) context).getLayoutInflater();
     row = inflater.inflate(layoutResourceId, parent, false);
     holder = new UserHolder();
     holder.textName = (TextView) row.findViewById(R.id.textView1);
     holder.textAddress = (TextView) row.findViewById(R.id.textView2);
     holder.textLocation = (TextView) row.findViewById(R.id.textView3);
     holder.btnEdit = (Button) row.findViewById(R.id.button1);
     holder.btnDelete = (Button) row.findViewById(R.id.button2);
     holder.imageView = (ImageView) row.findViewById(R.id.imageview1);
     holder.textViewDeneme = (TextView)row.findViewById(R.id.textView1s);
     
     row.setTag(holder);
     }
    else {
     holder = (UserHolder) row.getTag();
    
     }
    
     final User user = data.get(position);
     
     holder.textName.setText(user.getName());
     holder.textAddress.setText(user.getAddress());
     holder.textLocation.setText(user.getLocation());
     holder.imageView.setImageResource(user.iconid());
  
     
     holder.btnEdit.setOnClickListener(new OnClickListener() {
    
      @Override
      public void onClick(View v) {
      // TODO Auto-generated method stub
       
       
      Log.i("Edit Button Clicked", "**********");
      Toast.makeText(context, user.getAddress().toString(),  Burası  Çalışıyor
      Toast.LENGTH_LONG).show();
      
      //String adres = user.getAddress().toString();             
      
      //holder.textViewDeneme.setText(adres);                     Null Pointer Hatası veriyor
      
      
      }
      });
      holder.btnDelete.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
      // TODO Auto-generated method stub
      Log.i("Delete Button Clicked", "**********");
      Toast.makeText(context, "Delete button Clicked",
      Toast.LENGTH_LONG).show();
      }
      });
    
        holder.imageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
        // TODO Auto-generated method stub
        Log.i("image Clicked", "**********");
        Toast.makeText(context, "image Clicked",
        Toast.LENGTH_LONG).show();
        }
        });
        
     return row;
        }
   
  
  
static class UserHolder {
      TextView textName;
      TextView textAddress;
      TextView textLocation;
      Button btnEdit;
      Button btnDelete;
      ImageView imageView;
      TextView textViewDeneme;
    }
    
    }

 

 


03-27 14:42:25.440: W/dalvikvm(6890): threadid=1: thread exiting with uncaught exception (group=0x41db8c08)
03-27 14:42:25.440: E/AndroidRuntime(6890): FATAL EXCEPTION: main
03-27 14:42:25.440: E/AndroidRuntime(6890): Process: com.example.customlistviweheman, PID: 6890
03-27 14:42:25.440: E/AndroidRuntime(6890): java.lang.NullPointerException
03-27 14:42:25.440: E/AndroidRuntime(6890):  at com.example.customlistviweheman.UserCustomAdapter$1.onClick(UserCustomAdapter.java:69)
03-27 14:42:25.440: E/AndroidRuntime(6890):  at android.view.View.performClick(View.java:4633)
03-27 14:42:25.440: E/AndroidRuntime(6890):  at android.view.View$PerformClick.run(View.java:19330)
03-27 14:42:25.440: E/AndroidRuntime(6890):  at android.os.Handler.handleCallback(Handler.java:733)
03-27 14:42:25.440: E/AndroidRuntime(6890):  at android.os.Handler.dispatchMessage(Handler.java:95)
03-27 14:42:25.440: E/AndroidRuntime(6890):  at android.os.Looper.loop(Looper.java:157)
03-27 14:42:25.440: E/AndroidRuntime(6890):  at android.app.ActivityThread.main(ActivityThread.java:5356)
03-27 14:42:25.440: E/AndroidRuntime(6890):  at java.lang.reflect.Method.invokeNative(Native Method)
03-27 14:42:25.440: E/AndroidRuntime(6890):  at java.lang.reflect.Method.invoke(Method.java:515)
03-27 14:42:25.440: E/AndroidRuntime(6890):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
03-27 14:42:25.440: E/AndroidRuntime(6890):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
03-27 14:42:25.440: E/AndroidRuntime(6890):  at dalvik.system.NativeStart.main(Native Method)

4 Görüntülenme

0 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.