gpt4 book ai didi

java - onClick 继续停止

转载 作者:行者123 更新时间:2023-12-02 02:16:20 27 4
gpt4 key购买 nike

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: FATAL EXCEPTION: main Process: a0.besta_e_learning, PID: 7198 java.lang.IllegalStateException: Could not execute method for android:onClick at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293) at android.view.View.performClick(View.java:5610) at android.view.View$PerformClick.run(View.java:22265) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) at android.view.View.performClick(View.java:5610)  at android.view.View$PerformClick.run(View.java:22265)  at android.os.Handler.handleCallback(Handler.java:751)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:154)  at android.app.ActivityThread.main(ActivityThread.java:6077)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.MediaController.setAnchorView(android.view.View)' on a null object reference at a0.besta_e_learning.MandarinPage.viedeplay(MandarinPage.java:32) at java.lang.reflect.Method.invoke(Native Method)  at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)  at android.view.View.performClick(View.java:5610)  at android.view.View$PerformClick.run(View.java:22265)  at android.os.Handler.handleCallback(Handler.java:751)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:154)  at android.app.ActivityThread.main(ActivityThread.java:6077)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

最佳答案

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

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

或者

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

关于java - onClick 继续停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49270715/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com