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

오류가 자꾸 뜹니다 확인해주세요...

0 추천

오류코드 중요부분 입니다

01-27 13:38:12.434 10939-10939/com.ourincheon.smartcampus1231 E/AndroidRuntime:  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTextColor(int)' on a null object reference
01-27 13:38:12.434 10939-10939/com.ourincheon.smartcampus1231 E/AndroidRuntime:     at com.ourincheon.smartcampus1231.haksa.CalendarView.drawCalendar(CalendarView.java:88)
01-27 13:38:12.434 10939-10939/com.ourincheon.smartcampus1231 E/AndroidRuntime:     at com.ourincheon.smartcampus1231.haksa.CalendarView.init(CalendarView.java:62)

 

오류가 난다고 쓰여있는 코드들입니다

먼저 calenderview

public void drawCalendar() {
    for (int i = 0; i < mItems.size(); i++) {
        int curRowPosition = (int) i / 7;
        int date[] = adapter.getDate(i);
        if (i % 7 == 0) {
            LinearLayout row = new LinearLayout(context);
            row = (LinearLayout) inflater.inflate(R.layout.calendar_item,
                    null);
            this.addView(row);
            rows.add(row);
        }
        int dayId = getResources().getIdentifier(
                "id/day" + Integer.toString(i - curRowPosition * 7), "id",
                "com.ourincheon.smartcampus123");
        int barsId = getResources().getIdentifier(
                "id/bar" + Integer.toString(i - curRowPosition * 7), "id",
                "com.ourincheon.smartcampus123");
        TextView day = (TextView) rows.get(curRowPosition).findViewById(
                dayId);
        LinearLayout barLayout = (LinearLayout) rows.get(curRowPosition)
                .findViewById(barsId);
        day.setTextColor(Color.rgb(102, 102, 102));
        if (date == null) {
            day.setBackgroundColor(Color.rgb(160, 160, 160));
            day.setTextColor(Color.WHITE);
            if (i % 7 == 0)
                day.setBackgroundColor(Color.rgb(245, 149, 115));
            if ((i + 1) % 7 == 0)
                day.setBackgroundColor(Color.rgb(142, 141, 177));
            barLayout.setVisibility(View.GONE);
        } else {
            if (date[1] != month) {
                if (i % 7 == 0)
                    day.setTextColor(Color.argb(175, 245, 149, 115));
                else if ((i + 1) % 7 == 0)
                    day.setTextColor(Color.argb(175, 142, 141, 177));
                else
                    day.setTextColor(Color.argb(175, 160, 160, 160));
            }

            else if (i % 7 == 0)
                day.setTextColor(Color.rgb(245, 149, 115));
            else if ((i + 1) % 7 == 0)
                day.setTextColor(Color.rgb(142, 141, 177));
            else
                day.setTextColor(Color.rgb(102, 102, 102));
        }
        day.setText(mItems.get(i));
        day.setGravity(Gravity.RIGHT);

    }
다음으로 HaksaActivity
public void init(){

    for(int i=0 ; i<12 ; i++) {

        if(i==0) {
            month1 = (LinearLayout) findViewById(R.id.month1);
            CalendarView calendar = new CalendarView(context, i,
                    today.get(GregorianCalendar.YEAR), getMonthlyScheduleList(i));
            ((LinearLayout) month1).addView(calendar);
        }
      
    }
돠주세염....
익명사용자 님이 2016년 1월 27일 질문

1개의 답변

0 추천

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTextColor(int)' on a null object reference
01-27 13:38:12.434 10939-10939/com.ourincheon.smartcampus1231 E/AndroidRuntime:     at com.ourincheon.smartcampus1231.haksa.CalendarView.drawCalendar(CalendarView.java:88)

->

CalendarView.java 파일 88번째줄 에서 에러

TextView.setTextColor(int) : NullPointerException

TextView object가 제대로 안잡힌거 같네요 id값으로 View를 못찾아서 그러네요..

id/day는 왜있죠? 'id/' 이부분 없이 한번 해보셔야할듯

int dayId = getResources().getIdentifier(
                "id/day" + Integer.toString(i - curRowPosition * 7), "id",
                "com.ourincheon.smartcampus123");
노예의집 (23,370 포인트) 님이 2016년 1월 27일 답변
...