我已经看到了与我类似的其他问题,但问题仍然存在。提前致谢。
这是代码
package com.akk.mysecondvideo;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.widget.VideoView;
public class MySecondVideo extends Activity {
Context context;
MediaPlayer mp;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView = (VideoView)findViewById(R.id.VideoView);
//MediaController mediaController = new MediaController(this);
// mediaController.setAnchorView(videoView);
//videoView.setMediaController(mediaController);
Uri uri = Uri.parse("android.resource://com.akk.mysecondvideo/"
+ R.raw.bommarillu);
videoView.setVideoURI(uri);
//mp = new MediaPlayer();
//mp = MediaPlayer.create(context, R.raw.bommarillu);
videoView.start();
}
}
当我尝试运行它时,它显示强制关闭,并且 logcatNULLPOINTEREXCEPTION
在第 28 行显示错误,即videoView.setVideoURI(uri);
VideoView 是 main.xml 的一部分。main.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<VideoView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/VideoView" />
</LinearLayout>