2011-11-26 9 views
0

나는 간단한 손전등 응용 프로그램을 쓰고 있는데, 하나의보기 (flashOn)에서 다른보기 (flashOff)로 이동할 수 있기를 원합니다. FlipView 사용에 관한 게시물을 보았습니다. 이것이 가장 좋은 방법입니까? (나는 활동에 사용하고 싶지 않다. ..) 나는 이것을 아주 잘 알고 있었으므로 나를 교정 해주십시오!NullPointerException FlipView 안드로이드

:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
<LinearLayout 
    android:id="@+id/linearLayout" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
     </LinearLayout> 

<ViewFlipper 
    android:id="@+id/viewflipper" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:autoStart= "true"> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 
     <ImageButton 
       android:id="@+id/light_on" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/light_on" 
       android:layout_centerInParent="true"/> 

    <!-- To be used With Strobe Light Feature 
     <SeekBar android:id="@+id/seek" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:max="20" 
      android:progress="0" /> --> 

     <TextView 
      android:id="@+id/editText1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/light_on" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="35dp" 
      android:text="@string/lightOff" /> 
    </RelativeLayout> 
    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 
     <ImageButton 
      android:id="@+id/light_off" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/light_off" 
      android:layout_centerInParent="true"/> 

     <TextView 
      android:id="@+id/editText1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/light_off" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="35dp" 
      android:text="@string/lightOn" /> 
    </RelativeLayout> 

</ViewFlipper> 
여기

는 NullPointerException이 로그 캣 결과입니다 : 여기

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.no_torch); 

    ImageButton lightBtnOn = (ImageButton) findViewById(R.id.light_on); 
    ImageButton lightBtnOff = (ImageButton) findViewById(R.id.light_off); 


    final ViewFlipper viewFlipper = (ViewFlipper)findViewById(R.id.viewflipper); 
    final Animation animFlipInNext = AnimationUtils.loadAnimation(this, R.anim.flipinnext); 
    final Animation animFlipOutNext = AnimationUtils.loadAnimation(this, R.anim.flipoutnext); 
    final Animation animFlipInPrevious = AnimationUtils.loadAnimation(this, R.anim.flipinprevious); 
    final Animation animFlipOutPrevious = AnimationUtils.loadAnimation(this, R.anim.flipoutprevious); 

    lightBtnOn.setOnClickListener(new ImageButton.OnClickListener(){ 

      @Override 
      public void onClick(View v) { 
       viewFlipper.setInAnimation(animFlipInNext); 
       viewFlipper.setOutAnimation(animFlipOutNext); 
       viewFlipper.showNext(); 
      }}); 

    lightBtnOff.setOnClickListener(new ImageButton.OnClickListener(){ 

@Override 
public void onClick(View v) { 
    viewFlipper.setInAnimation(animFlipInPrevious); 
    viewFlipper.setOutAnimation(animFlipOutPrevious); 
    viewFlipper.showPrevious(); 
}}); 

내 XML입니다 : 내가 활동 클래스를 여기

lightBtnOn.setOnClickListener(new ImageButton.OnClickListener(){에 NullPointerException이되어 점점 계속

11-26 18:02:31.501: E/AndroidRuntime(22663): FATAL EXCEPTION: main 
11-26 18:02:31.501: E/AndroidRuntime(22663): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.marshall.meadows182/com.marshall.meadows182.LightTorch}: java.lang.NullPointerException 
11-26 18:02:31.501: E/AndroidRuntime(22663): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1821) 
11-26 18:02:31.501: E/AndroidRuntime(22663): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842) 
11-26 18:02:31.501: E/AndroidRuntime(22663): at android.app.ActivityThread.access$1500(ActivityThread.java:132) 
11-26 18:02:31.501: E/AndroidRuntime(22663): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038) 
11-26 18:02:31.501: E/AndroidRuntime(22663): at android.os.Handler.dispatchMessage(Handler.java:99) 
11-26 18:02:31.501: E/AndroidRuntime(22663): at android.os.Looper.loop(Looper.java:143) 
11-26 18:02:31.501: E/AndroidRuntime(22663): at android.app.ActivityThread.main(ActivityThread.java:4263) 
11-26 18:02:31.501: E/AndroidRuntime(22663): at java.lang.reflect.Method.invokeNative(Native Method) 
11-26 18:02:31.501: E/AndroidRuntime(22663): at java.lang.reflect.Method.invoke(Method.java:507) 
11-26 18:02:31.501: E/AndroidRuntime(22663): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
11-26 18:02:31.501: E/AndroidRuntime(22663): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
11-26 18:02:31.501: E/AndroidRuntime(22663): at dalvik.system.NativeStart.main(Native Method) 
11-26 18:02:31.501: E/AndroidRuntime(22663): Caused by: java.lang.NullPointerException 
11-26 18:02:31.501: E/AndroidRuntime(22663): at com.marshall.meadows182.LightTorch.onCreate(LightTorch.java:43) 
11-26 18:02:31.501: E/AndroidRuntime(22663): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072) 
11-26 18:02:31.501: E/AndroidRuntime(22663): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785) 
11-26 18:02:31.501: E/AndroidRuntime(22663): ... 11 more 

답변

0

"new ImageButton.OnClickListener"대신 "new OnClickListener"시도

+0

방금 ​​시도했습니다. 같은 반응. Stack Trace를 게시하고 있습니다. – comead

+0

u는 청소하고 다시 만들려고 했습니까? – dor506

+0

예, 이미 청소했습니다. id에는 flash_on 및 flash_off에 대한 참조가 있습니다. 유일한 것은 imagebutton null입니다 ..하지만 왜 .. – comead

관련 문제