»Ë»Ñ Æ÷·³
°³¹ßÀÚÆ÷·³ ÀÔ´Ï´Ù.
  • ºÏ¸¶Å© ¾ÆÀÌÄÜ

[¾Èµå·ÎÀ̵å] custom viewÀÇ xml layout Á¢±Ù ¹®Á¦.. (null pointer exception)2

¾È³çÇϼ¼¿ä ¾Èµå·ÎÀ̵å Ãʺ¸ÀÔ´Ï´Ù.

µÎ °³ÀÇ Å¬·¡½º¿Í ÇϳªÀÇ xml·Î ÀÌ·ç¾îÁø °£´ÜÇÑ ¾îÇÃÀ» ¸¸µé°í ÀÖ½À´Ï´Ù.

±× ´ë·«ÀûÀÎ ±¸¼ºÀº ´ÙÀ½°ú °°½À´Ï´Ù.

public class Axis_Main extends Activity
protected void onCreate(Bundle savedInstanceState)
  {
            View mainView = getLayoutInflater().inflate(R.layout.activity_main, null);           //xml ÆÄÀÏ inflate                
            RelativeLayout container = (RelativeLayout)mainView.findViewById(R.id.layout);          //xmlÀÇ layout¿¡ custom view ºÙÀ̱â
            draw = new Axis_Draw(this, USER_MODE_TF);
            container.addView(draw,0);
            setContentView(mainView);
  }
Áß·«....

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

public class Axis_Draw extends View
{
    public Axis_Draw(Context context, boolean TF)
        {
        super(context);
                
                if(TF == false)
                {
                data = new Data_Class(context);
                GET_DATA_FROM_DATACLASS();
                }

                else if (TF == true)
                {
                is_USER_MODE = true;

                LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View v = inflater.inflate(R.layout.activity_main, null);
                ((ImageView)v.findViewById(R.id.right_thing)).setVisibility(View.VISIBLE);
                ((ImageView)v.findViewById(R.id.left_thing)).setVisibility(View.INVISIBLE);

    Áß·«.....


Á¦°¡ ¿øÇÏ´Â °ÍÀº, extends ViewÇÑ Axis_Draw¿¡¼­ xml ¿¡ Á¤ÀÇµÈ imageviewµéÀ» º¸¿´´Ù ¾Èº¸¿´´Ù ÀÌ·¸°Ô Á¦¾îÇÏ´Â °ÍÀä,

ÀÌ»óÇÏ°Ô imageview ¼Ó¼º º¯°æÀÌ µÇÁö ¾Ê½À´Ï´Ù.

LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.activity_main, null);

¸¦ Ãß°¡ÇÔÀ¸·Î¼­ null pointer exceptionÀº ÇØ°áÇÏ¿´Áö¸¸,
((ImageView)v.findViewById(R.id.right_thing)).setVisibility(View.VISIBLE);
((ImageView)v.findViewById(R.id.left_thing)).setVisibility(View.INVISIBLE);
°¡ ¸ÔÁö ¾Ê½À´Ï´Ù;;

µµ´ëü ¿Ö ÀÌ·±°É±î¿ä?

µµ¿ò ÁÖ½Ã¸é °¨»çÇÏ°Ú½À´Ï´Ù.

0
ÃßõÇϱ⠴ٸ¥ÀÇ°ß 0
|
°øÀ¯¹öÆ°

´Ù¸¥ÀÇ°ß 0 Ãßõ 0 ¿ìÇÏÇÏÈ£
  • ¾Ë¸² ¿å¼³, »óó ÁÙ ¼ö ÀÖ´Â ¾ÇÇÃÀº »ï°¡ÁÖ¼¼¿ä.
©¹æ »çÁø  
¡â ÀÌÀü±Û¡ä ´ÙÀ½±Û ¸ñ·Ïº¸±â