onClick继续停止

时间:2018-03-14 06:03:23

标签: java android android-videoview

public class MandarinPage extends AppCompatActivity {
Button b01,b02,b03;
VideoView Vv01;
MediaController mediaC;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mandarin_page);
    b01=(Button)findViewById(R.id.button01);
    b02=(Button)findViewById(R.id.button02);
    b03=(Button)findViewById(R.id.button03);

    Vv01=(VideoView)findViewById(R.id.videoView);
}

public void viedeplay(View v){
    String videopath = "android.resource://a0.besta_e_learning/"+R.raw.sample_video;
    Uri uri = Uri.parse(videopath); //URI stand for Uniform Resource Identifier
    Vv01.setVideoURI(uri);
    Vv01.setMediaController(mediaC);
    mediaC.setAnchorView(Vv01);
    Vv01.start();
}

when i clicked my play button my emulator show this.

有人可以帮我这个吗?有错误吗?当我点击按钮播放我的视频它显示应用程序继续停止我不知道它的哪个部分出错了。

这里有错误。

  

E / AndroidRuntime:致命异常:主要                     处理:a0.besta_e_learning,PID:7198                     java.lang.IllegalStateException:无法执行android:onClick的方法                         在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)                         在android.view.View.performClick(View.java:5610)                         在android.view.View $ PerformClick.run(View.java:22265)                         在android.os.Handler.handleCallback(Handler.java:751)                         在android.os.Handler.dispatchMessage(Handler.java:95)                         在android.os.Looper.loop(Looper.java:154)                         在android.app.ActivityThread.main(ActivityThread.java:6077)                         at java.lang.reflect.Method.invoke(Native Method)                         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:865)                         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)                      引起:java.lang.reflect.InvocationTargetException                         at java.lang.reflect.Method.invoke(Native Method)                         在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)                         在android.view.View.performClick(View.java:5610)                         在android.view.View $ PerformClick.run(View.java:22265)                         在android.os.Handler.handleCallback(Handler.java:751)                         在android.os.Handler.dispatchMessage(Handler.java:95)                         在android.os.Looper.loop(Looper.java:154)                         在android.app.ActivityThread.main(ActivityThread.java:6077)                         at java.lang.reflect.Method.invoke(Native Method)                         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:865)                         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)                      引起:java.lang.NullPointerException:尝试调用虚方法'void   android.widget.MediaController.setAnchorView(android.view.View)'上一个   null对象引用                         at a0.besta_e_learning.MandarinPage.viedeplay(MandarinPage.java:32)                         at java.lang.reflect.Method.invoke(Native Method)                         在android.support.v7.app.AppCompatViewInflater $ DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)                         在android.view.View.performClick(View.java:5610)                         在android.view.View $ PerformClick.run(View.java:22265)                         在android.os.Handler.handleCallback(Handler.java:751)                         在android.os.Handler.dispatchMessage(Handler.java:95)                         在android.os.Looper.loop(Looper.java:154)                         在android.app.ActivityThread.main(ActivityThread.java:6077)                         at java.lang.reflect.Method.invoke(Native Method)                         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:865)                         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

2 个答案:

答案 0 :(得分:1)

我认为错误就在这一行..尝试编写视频的视频扩展名

String videopath = 
"android.resource://a0.besta_e_learning/"+R.raw.sample_video.mp4;

OR

 String videopath = 
 "android.resource://a0.besta_e_learning/"+R.raw.sample_video.3gp;

答案 1 :(得分:1)

尝试此代码可能有所帮助

MediaController mediaC = new MediaController(this);

Vv01.setMediaController(mediaC);