为什么我在VideoView中获得NullPointer?

时间:2015-07-30 11:31:07

标签: android android-videoview

程序启动时出错。记录行上的错误 - videoView.setVideoPath(videoSource); 在宣言中,所有权限都已注册。 帮助理解问题所在。

public class PlayVideoActivity extends Activity {
    VideoView videoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camera);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
        String videoSource = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
        Log.w("way",""+videoSource);
        videoView = (VideoView) findViewById(R.id.videoView1);
        setContentView(videoView);
        Intent intent = getIntent();
        String fName = intent.getStringExtra("source");
        videoSource = videoSource + "/1.3gp";
        videoView.setVideoPath(videoSource);
        videoView.setMediaController(new MediaController(this));
        videoView.requestFocus(0);
        videoView.start();
    }
}

我的xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <VideoView
        android:id="@+id/videoView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

我的日志:

07-30 14:40:50.626: E/AndroidRuntime(17268): FATAL EXCEPTION: main
07-30 14:40:50.626: E/AndroidRuntime(17268): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.video/com.example.video.PlayVideoActivity}: java.lang.NullPointerException
07-30 14:40:50.626: E/AndroidRuntime(17268):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
07-30 14:40:50.626: E/AndroidRuntime(17268):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2095)
07-30 14:40:50.626: E/AndroidRuntime(17268):    at android.app.ActivityThread.access$600(ActivityThread.java:135)
07-30 14:40:50.626: E/AndroidRuntime(17268):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
07-30 14:40:50.626: E/AndroidRuntime(17268):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-30 14:40:50.626: E/AndroidRuntime(17268):    at android.os.Looper.loop(Looper.java:137)
07-30 14:40:50.626: E/AndroidRuntime(17268):    at android.app.ActivityThread.main(ActivityThread.java:4849)
07-30 14:40:50.626: E/AndroidRuntime(17268):    at java.lang.reflect.Method.invokeNative(Native Method)
07-30 14:40:50.626: E/AndroidRuntime(17268):    at java.lang.reflect.Method.invoke(Method.java:511)
07-30 14:40:50.626: E/AndroidRuntime(17268):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
07-30 14:40:50.626: E/AndroidRuntime(17268):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
07-30 14:40:50.626: E/AndroidRuntime(17268):    at dalvik.system.NativeStart.main(Native Method)
07-30 14:40:50.626: E/AndroidRuntime(17268): Caused by: java.lang.NullPointerException
07-30 14:40:50.626: E/AndroidRuntime(17268):    at com.example.video.PlayVideoActivity.onCreate(PlayVideoActivity.java:26)
07-30 14:40:50.626: E/AndroidRuntime(17268):    at android.app.Activity.performCreate(Activity.java:5236)
07-30 14:40:50.626: E/AndroidRuntime(17268):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
07-30 14:40:50.626: E/AndroidRuntime(17268):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2034)
07-30 14:40:50.626: E/AndroidRuntime(17268):    ... 11 more

0 个答案:

没有答案
相关问题