2014-07-15 3 views
1

내 앱에서 WizarDroid 라이브러리를 사용해보고 싶었습니다. 그러나 나는 인플레 이터에 대해 상당히 경험이 없기 때문에이 오류에 몇 시간 동안 고생했습니다. 에 findViewById를을하는 동안 조각에서 뷰를 부 풀리는 방법은 무엇입니까?

은 내가 NullPointerException이을 얻고 그 이유를 알아낼 수 없습니다.

public class WizardStep1 extends WizardStep { 

    //Wire the layout to the step 
    public WizardStep1() { 
    } 

    //Set your layout here 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View v = inflater.inflate(R.layout.wizard, container, false); 
     TextView tv = (TextView) v.findViewById(R.id.wizard_textView); // tv = null 
     tv.setText("This is an example of Step 1 in the wizard. Press the Next " + // NullPointerException gets thrown here 
       "button to proceed to the next step. Hit the back button to go back to the calling activity."); 

     return v; 
    } 
} 

그래서 텍스트 뷰의 TV은 어떤 이유로 null입니다. 내가 분명히 그것은 단지 더 나를 혼란 때문에이 코드는 해당 설명서에서 또한

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/wizard_textView" 
     android:layout_marginTop="10dp" 
     android:textSize="20dp" 
     android:text="gtsets" /> 
</LinearLayout> 

XML 에 R.layout.wizard을 정의하기 때문에 나는이 알아낼 수 없습니다 :/

편집 : 여기 wizardStartup 클래스는 다음과 같습니다

public class wizardStartup extends BasicWizardLayout { 

    /** 
    * Note that initially BasicWizardLayout inherits from {@link android.support.v4.app.Fragment} and therefore you must have an empty constructor 
    */ 
    public wizardStartup() { 
     super(); 
    } 

    //You must override this method and create a wizard flow by 
    //using WizardFlow.Builder as shown in this example 
    @Override 
    public WizardFlow onSetup() { 
     /* Optionally, you can set different labels for the control buttons 
     setNextButtonLabel("Advance"); 
     setBackButtonLabel("Return"); 
     setFinishButtonLabel("Finalize"); */ 

     return new WizardFlow.Builder() 
       .addStep(WizardStep1.class)   //Add your steps in the order you want them 
       .addStep(WizardStep2.class)   //to appear and eventually call create() 
       .create();        //to create the wizard flow. 
    } 
} 

로그 캣 :

07-15 : 17 : 58 : 05.491 10299-10299/ba.imasoft.dfms.app E/AndroidRuntime : 중요 예외 : 기본 java.lang.NullPointerException at ba.imasoft.dfms.app.wizards.steps.WizardStep1 .onCreateView (WizardStep1.java:28는)

라인 (28)은 'tv.setText ("이'..

나는 그것은 작동 TV 변수를 포함하지만 방법이 그것은 해야하는 라인을 주석 경우 to .. 각 단계마다보기를 편집해야합니다. 문제는 이상하게 이상한

watches

+0

XML에서 TextView를 어디에 정의했는지 알 수 없습니까? – panini

+0

게시 한 레이아웃이 R.layout.wizard XML 인 경우 ID가 R. id.wizard_textView 인 TextView가 표시되지 않습니다. 레이아웃을 다시 확인하십시오. –

+0

그래, 그 이유는 null입니다. findViewById는 ID가 없으면 null을 반환합니다. – mskw

답변

0

TV = null의 증거 ... .. 어쨌든

내가 한 모든 그것을 생각 wizard.xml wizard_step.xml 에 변화

다른 라이브러리로 wizard.xml을 사용하고있었습니다. 그것은 효과가 있었다.

+1

매우 정확합니다! 라이브러리에 이미 [wizard.xml]이라는 레이아웃 파일이 있습니다 [여기서 볼 수 있듯이 ] (https://github.com/Nimrodda/WizarDroid/blob/develop/wizardroid/src /main/res/layout/wizard.xml). FAQ에 추가하고 향후 릴리스에서이 파일의 이름을 바꿉니다. –

관련 문제