2012-09-02 8 views
0

시판되는 응용 프로그램에서 대화 상자의 TextView에 오류가 발생했습니다.대화 상자 개체에 대한 널 포인터 예외

java.lang.NullPointerException 
at com.b2creativedesigns.eyetest.ColorBlindTest1$2.onClick(ColorBlindTest1.java:324) 

부분 코드는 오류입니다 :

내 질문
  1. 인가 있습니다
    btnNext1.setOnClickListener(new View.OnClickListener() { 
    
    @Override 
    public void onClick(View v) { 
    
    
    GlobalVars.setPoints(points); 
    dialog = new Dialog(ColorBlindTest1.this); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    dialog.setContentView(R.layout.cbtdialog); 
    
    TextView dialogtext = (TextView) dialog.findViewById (R.id.tvCBTresult); 
    TextView dialogtext2 = (TextView) dialog.findViewById (R.id.tvCBTresult2); 
    Button btnQuit = (Button) dialog.findViewById (R.id.btnCTBback); 
    Button btnFB = (Button) dialog.findViewById (R.id.btnCBTFB); 
    Button btnMarket = (Button) dialog.findViewById (R.id.btnCBTMarket); 
    if (points >= 14) 
    { 
        dialogtext.setText("Your result is " + points + "/15!"); 
        dialogtext.setTextColor(Color.rgb(19, 20, 111)); 
        dialogtext2.setText("Something"); //error line 
    } 
    ... 
    

    그것은 괜찮 선언에 (경우에 텍스트 뷰) 오브젝트 여기에 로컬 및 전체적으로 외부에 없습니다 TextView dialogtext2; 여기에 쓰십시오. dialogtext2 = (TextView) dialog.findViewById (R.id.tvCBTresult2);?

  2. 4 가지 밀도를위한 4 개의 폴더가 있습니다 : layout-ldpi, layout-mdpi, layout-hdpi, layout-xhdpi. layout-xhdpi 폴더의 xml에는 dialogtext2 TextView가 포함되지 않았습니다. 이로 인해 오류가 발생할 수 있습니까? 다른 밀도 폴더의 같은 XML에서 개체가 누락 된 경우 안드로이드가 다른 밀도 폴더의 XML을 적용하지 않습니까?

그 외의 근본 원인은 무엇입니까?

답변

0

findViewById()를 사용하면 문제가 없습니다. 그러나 R.id. tvCBTresult2은 사용중인 레이아웃 (R.layout.cbtdialog)

레이아웃-xhdpi 폴더의 XML은 dialogtext2의 텍스트 뷰를 포함하지 않았다 아닙니다. 이로 인해 오류가 발생할 수 있습니까? 객체가 없을 때 아마 안드로이드 당신이 xhdpi 화면이 장치를 사용하는 (dialigtext2 찾을 수 없기 때문에 문제.

다른 밀도 폴더에서 XML을 적용 안드로이드하지 않습니다

파일이 (없는 하나의 요소)를 찾을 수없는 경우 다른 밀도 폴더에 같은 XML에서? 사실

, 어떤 안드로이드가하는 것은 다른 폴더에서 검색입니다.