0

I tried to add pictures from the Drawble to the Scrollview this is the code I wrote and the emulator shows me an error. it shows that the image is a null object. Someone can help me fix the problem?(the problem is in the line with the ** **)

public void restartGame() {
    Deck x = players[0].getMyDeck();
    Log.d("my deck", x.showDeck() + "");
    Card c;

   ImageButton image = new ImageButton(this);
    View view =inflater.inflate(R.layout.activity_game, hand1, false);
     image = view.findViewById(R.id.image);
    //ImageButton image = view.findViewById(R.id.image);
    for( int i=0; i<8;i++)
    {

        c = x.getCard(i);

       int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics());
       int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics());
       LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height);
        Card str = c;
        Log.d(" **** player 0 ",str+"");
        int str2 = c.getIndex();
        Log.d(" **** player 2 ",str2+"");
   



**image.setImageResource(pics[c.getIndex()]);**



        image.setScaleType(ImageView.ScaleType.FIT_CENTER);
        image.setPadding(0, 1, 0, 0);
        params.setMargins(0, 1, 1, 0);
        image.setOnClickListener(this);
        image.setLayoutParams(params);

        image.setId(c.getIndex());
        image.setTag("xxx");
        hand1.addView(view);
    }
GO2
  • 1
  • 1

0 Answers0