2014-06-09 4 views
1

나는 안드로이드에 익숙하지 않으며 지난 몇 년 동안 아무 것도 프로그램하지 않았다. 나 자신을 시작하기 위해, 나는 간단한 것들을 시도하고있다. 그 중 하나는 SeekBar와 청취자를 구현하는 것이다. 나는 ActionBarActivity 클래스 자체에서 인터페이스를 구현할뿐만 아니라 리스너를 별도의 클래스로 구현하려고 시도했지만 NPE가 발생합니다. 나는 이유에 대해 아무런 설명없이 인스턴스를 생성하지 않는 청취자에게 그것을 좁힐 수있었습니다.Null 포인터 예외 안드로이드에서 SeekBar Listener 인터페이스를 구현하는 중

다음은 제 코드입니다.

public class IntenseTorchActivity extends ActionBarActivity 
       implements SeekBar.OnSeekBarChangeListener { 

private static int seekValue = 10; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_intense_torch); 

    final SeekBar seekbar = (SeekBar) findViewById(R.id.seekBar1); 

    seekbar.setOnSeekBarChangeListener(this); 

    if (savedInstanceState == null) { 
     getSupportFragmentManager().beginTransaction() 
       .add(R.id.container, new PlaceholderFragment()).commit(); 
    } 
} 

@Override 
    public void onProgressChanged(SeekBar seekBar, int progress, 
      boolean fromUser) { 
     seekValue = progress; 
    } 

    @Override 
    public void onStartTrackingTouch(SeekBar arg0) { 
     // TODO Auto-generated method stub 
    } 

    @Override 
    public void onStopTrackingTouch(SeekBar arg0) { 
     // TODO Auto-generated method stub 
    } 


@Override 
public boolean onCreateOptionsMenu(Menu menu) { 

    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.intense_torch, menu); 
    return true; 
} 

어떤 도움이나 포인터

Fragment_xxx.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.SunShineCorp.intensetorch.IntenseTorchActivity$PlaceholderFragment" > 

<SeekBar 
     android:id="@+id/seekBar1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_marginTop="14dp" /> 

</RelativeLayout> 

실제 자바 코드는 정말 감사합니다. SeekBarFragment_xxx.xml에 있기 때문에

답변

1

변경이 ..

setContentView(R.layout.activity_intense_torch); 

setContentView(R.layout.Fragment_xxx); 

그렇게 setContentViewFragment_xxx.xml

제거를 참조해야

if (savedInstanceState == null) { 
    getSupportFragmentManager().beginTransaction() 
      .add(R.id.container, new PlaceholderFragment()).commit(); 
} 
+0

고마워, 지금 일하고있다. –

+0

@ KoushikB. 다행히 도왔습니다. 해피 코딩. – Hariharan