마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

이거 문제가 뭔지 모르겠습니다;

0 추천
----------------------------------------------------------------------

 

public class AdapterActivity extends RecyclerView.Adapter<AdapterActivity.ViewHolder> {

    private Context context;
    private List<Chat_room> items;
    private int item_layout;
    private String name;

    private boolean check = true;

 

    public AdapterActivity(Context context, List<Chat_room> items, int item_layout, String value) {

        this.context=context;
        this.items=items;
        this.item_layout=item_layout;
        this.name = value;
    }

    public int getItemViewType(int position)
    {
        if(items.get(position).getName().equals(name))
        {
            //check = true;
            return 1;
        }
        else
        {
           // check = true;
            return 2;
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view;

        if(viewType == 1)
        {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_items, parent, false);
        }
        else
        {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_items_user, parent, false);
        }

        return new ViewHolder(view);

    }

    //@TargetApi(Build.VERSION_CODES.JELLY_BEAN)

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        if(imageCheck == true)
        {
            holder.imageBitmapView.setImageBitmap(items.get(position).getBitmap()); <-- 여기서 getBitmap을 호출하면

            imageCheck = false;
        }
        else
        {
            holder.msg.setText(items.get(position).getMsg());
        }
    }

    @Override
    public int getItemCount() {
        return this.items.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        TextView msg;
        ImageView imageBitmapView;

        public ViewHolder(View itemView) {
            super(itemView);

            msg = (TextView)itemView.findViewById(R.id.chat_name);
            imageBitmapView = (ImageView)itemView.findViewById(R.id.imageBitmapView);
        }
    }
}

 

-----------------------------

 

public class Chat_room {

    public String name ;
    public String msg ;
    public byte[] bytes ;
    public Bitmap bitmap = null ;

    public String path;
    private int num = 0;

    public String test;

    public static boolean imageCheck;

    public Chat_room() {
        // Default constructor required for calls to DataSnapshot.getValue(Comment.class)
    }

    public Chat_room(String name, String msg) {

        this.name = name;
        this.msg = msg;
    }

    public Chat_room(String name, String mCurrentPhotoPath, int num) {

        this.name = name;
        this.path = mCurrentPhotoPath;
        this.num = num;

        BitmapFactory.Options bmOptions = new BitmapFactory.Options();
        bmOptions.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(path, bmOptions);

        bmOptions.inJustDecodeBounds = false;
        bmOptions.inSampleSize = 4;
        bmOptions.inPurgeable = true;

        bitmap = BitmapFactory.decodeFile(path, bmOptions);

        Log.i("bitmap-Chat_room", String.valueOf(bitmap)); <-- 여기서는 bitmap 값이 제대로 들어오는데,

        imageCheck = true;

        test = "Free";

    }
    public String getName() {

        return name;
    }

    public String getMsg() {

        return msg;
    }

    public Bitmap getBitmap()
    {
        Log.i("bitmap-Chat_room-return", String.valueOf(bitmap)); <-- 여기서는 null을 반환합니다.
        Log.i("bitmap-TEST", test); <-- 혹시나 싶어서 test 변수도 멤버변수로 선언하고 찍어봤더니 여기서는

        java.lang.NullPointerException: println needs a message 이런 에러가 나면서 앱이 죽어버리네요

        return bitmap;
    }
}

멤버변수는 메소드에서 변수값을 변경했을때, 그 메소드에서 나오더라도 값이 유지되는거 아닌가요??
알파고 (4,320 포인트) 님이 2017년 10월 7일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...