runtime error 대해 ㅠㅠ
부루
안녕하세요 이번에 동영상 재생 어플을 만들어보고자 하는데요코드는 이러합니다.그런데 이게 갤럭시s에서 실행을 하는데 어플 아이콘 까지 생성이 되나 runtime오류로 인한 강제 종료가 되네요우선 밑은 코드구요//---------------------------------------------------------------------------------------------public class MediaTestActivity extends Activity implements SurfaceHolder.Callback{
private SurfaceView mPreview;
private SurfaceHolder mHolder;
MediaPlayer mPlayer; //미디어변수 선
Button mPlayBtn; //플레이버
private String path =
Environment.getExternalStorageDirectory().getAbsolutePath()+/res/raw/back.mp4;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
mPreview = (SurfaceView)findViewById(R.id.surface);
mHolder = mPreview.getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mPlayBtn = (Button)findViewById(R.id.play);
mPlayBtn.setOnClickListener(mClickPlay);
findViewById(R.id.stop).setOnClickListener(mClickStop);
}
Button.OnClickListener mClickPlay = new View.OnClickListener() {
public void onClick(View v) {
if(mPlayer.isPlaying()==false){
mPlayer.start();
mPlayBtn.setText(Pause);
}else{
mPlayer.pause();
mPlayBtn.setText(Play);
}
}
};
Button.OnClickListener mClickStop = new View.OnClickListener() {
public void onClick(View v) {
mPlayer.stop();
try{
mPlayer.prepare();
}catch(Exception e){;}
}
};
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
public void surfaceCreated(SurfaceHolder holder) {
if(mPlayer==null){
mPlayer=new MediaPlayer();
}else{
mPlayer.reset();
}
try{
mPlayer.setDataSource(path);
mPlayer.setDisplay(holder);
mPlayer.prepare();
mPlayer.setOnCompletionListener(mComplete);
mPlayer.setOnVideoSizeChangedListener(mSizeChange);
}catch(Exception e){
Toast.makeText(MediaTestActivity.this, error : +e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
MediaPlayer.OnCompletionListener mComplete = new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) { mPlayBtn.setText(Play);
}
};
&n
MediaPlayer.OnVideoSizeChangedListener mSizeChange = new MediaPlayer.OnVideoSizeChangedListener() {
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
}
};
public void surfaceDestroyed(SurfaceHolder holder) {
}
protected void onDestroy(){
super.onDestroy();
if(mPlayer!=null){
mPlayer.release();
}
}
}---------------------------------------------------------------------------------------------//밑은 에러 내용입니다.---------------------------------------------------------------------------------------------
04-18 05:44:30.505: D/AndroidRuntime(4313): Shutting down VM
04-18 05:44:30.505: W/dalvikvm(4313): threadid=1: thread exiting with uncaught exception (group=0x4001d828)
04-18 05:44:30.509: E/AndroidRuntime(4313): FATAL EXCEPTION: main
04-18 05:44:30.509: E/AndroidRuntime(4313): java.lang.RuntimeException: Unable to start activity ComponentInfo{Exam.MediaTest/Exam.MediaTest.MediaTestActivity}: java.lang.NullPointerException
04-18 05:44:30.509: E/AndroidRuntime(4313): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2668)
04-18 05:44:30.509: E/AndroidRuntime(4313): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2684)
04-18 05:44:30.509: E/AndroidRuntime(4313): at android.app.ActivityThread.access$2300(ActivityThread.java:126)
04-18 05:44:30.509: E/AndroidRuntime(4313): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
04-18 05:44:30.509: E/AndroidRuntime(4313): at android.os.Handler.dispatchMessage(Handler.java:99)
04-18 05:44:30.509: E/AndroidRuntime(4313): at android.os.Looper.loop(Looper.java:123)
04-18 05:44:30.509: E/AndroidRuntime(4313): at android.app.ActivityThread.main(ActivityThread.java:4632)
04-18 05:44:30.509: E/AndroidRuntime(4313): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 05:44:30.509: E/AndroidRuntime(4313): at java.lang.reflect.Method.invoke(Method.java:521)
04-18 05:44:30.509: E/AndroidRuntime(4313): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
04-18 05:44:30.509: E/AndroidRuntime(4313): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-18 05:44:30.509: E/AndroidRuntime(4313): at dalvik.system.NativeStart.main(Native Method)
04-18 05:44:30.509: E/AndroidRuntime(4313): Caused by: java.lang.NullPointerException
04-18 05:44:30.509: E/AndroidRuntime(4313): at Exam.MediaTest.MediaTestActivity.onCreate(MediaTestActivity.java:30)
04-18 05:44:30.509: E/AndroidRuntime(4313): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-18 05:44:30.509: E/AndroidRuntime(4313): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2632)
04-18 05:44:30.509: E/AndroidRuntime(4313): ... 11 more
04-18 05:44:32.857: I/Process(4313): Sending signal. PID: 4313 SIG: 9
---------------------------------------------------------------------------------------------
에러를 찾아가 보면 코드에
mHolder.addCallback(this);이부분에서 에러가 나는데 어떤게 문제인거죠 ㅠㅠ;;하루종일 머리싸메다가 질문드려요
-
파라
MediaTestActivity를 인플레이션 해주는 부분이 빠진거같은데요? MediaTestActivity 레이아웃 xml을 매개변수로 setContentView(R.layout.XXXXX) 이렇게 해줘야하지 않나요?