英文:
android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class
问题
我到处寻找,但我找不到关于这个错误的任何解决方案。
我正在使用ExoPlayer进行直播视频流。每次运行应用程序时,我的应用程序都会崩溃。如果您可以帮助我,我会很高兴。
我猜应该是在XML文件的某个地方,但我不理解所有这些错误是什么意思。
XML:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.devbrackets.android.exomedia.ui.widget.VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:useDefaultControls="true"/>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity文件:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Please Wait");
progressDialog.setCancelable(false);
progressDialog.show();
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(Uri.parse("这里是路径"));
videoView.start();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
}
});
}
堆栈跟踪:
进程:rusiptv.net,PID:25782
java.lang.RuntimeException:无法启动组件信息{rusiptv.net/rusiptv.net.MainActivity}:android.view.InflateException:二进制XML文件行#9:二进制XML文件行#9:Error inflating class com.devbrackets.android.exomedia.ui.widget.VideoView
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)中
在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)中
在android.app.ActivityThread.-wrap11(未知来源:0)中
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1589)中
在android.os.Handler.dispatchMessage(Handler.java:106)中
在android.os.Looper.loop(Looper.java:164)中
在android.app.ActivityThread.main(ActivityThread.java:6494)中
在java.lang.reflect.Method.invoke(Native Method)中
在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:438)中
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)中
Caused by:android.view.InflateException:二进制XML文件行#9:二进制XML文件行#9:Error inflating class com.devbrackets.android.exomedia.ui.widget.VideoView
Caused by:android.view.InflateException:二进制XML文件行#9:Error inflating class com.devbrackets.android.exomedia.ui.widget.VideoView
Caused by:java.lang.reflect.InvocationTargetException
在java.lang.reflect.Constructor.newInstance0(Native Method)中
在java.lang.reflect.Constructor.newInstance(Constructor.java:334)中
在android.view.LayoutInflater.createView(LayoutInflater.java:647)中
在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)中
在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)中
在android.view.LayoutInflater.rInflate(LayoutInflater.java:863)中
在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)中
在android.view.LayoutInflater.inflate(LayoutInflater.java:515)中
在android.view.LayoutInflater.inflate(LayoutInflater.java:423)中
在android.view.LayoutInflater.inflate(LayoutInflater.java:374)中
在androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)中
在androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)中
在rusiptv.net.MainActivity.onCreate(MainActivity.java:42)中
在android.app.Activity.performCreate(Activity.java:7009)中
在android.app.Activity.performCreate(Activity.java:7000)中
在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)中
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)中
在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)中
在android.app.ActivityThread.-wrap11(未知来源:0)中
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1589)中
在android.os.Handler.dispatchMessage(Handler.java:106)中
在android.os.Looper.loop(Looper.java:164)中
在android.app.ActivityThread.main(ActivityThread.java:6494)中
在java.lang.reflect.Method.invoke(Native Method)中
在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:438)中
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)中
如果可以,请详细解释一下这个错误,因为如果我将来再遇到这个问题,我可以轻松解决它。
编辑:
谢谢大家!我解决了这个问题。
解决方案:
- `VideoView videoView = findViewById(R.id.video_view);`
- 我根据我的包名更改了VideoView的路径。
英文:
I was looking everywhere but I couldn't find any solution for this error.
I'm using ExoPlayer for live video streaming. And my app crashes every time when I run it. If you can help me I will be happy.
I guess it should be somewhere in the XML file but I can't understand what means all that error.
XML:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.devbrackets.android.exomedia.ui.widget.VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:useDefaultControls="true"/>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity file:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Please Wait");
progressDialog.setCancelable(false);
progressDialog.show();
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(Uri.parse("Here's path"));
videoView.start();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
}
});
}
}
Stacktrace:
Process: rusiptv.net, PID: 25782
java.lang.RuntimeException: Unable to start activity ComponentInfo{rusiptv.net/rusiptv.net.MainActivity}: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class com.devbrackets.android.exomedia.ui.widget.VideoView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class com.devbrackets.android.exomedia.ui.widget.VideoView
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class com.devbrackets.android.exomedia.ui.widget.VideoView
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at rusiptv.net.MainActivity.onCreate(MainActivity.java:42)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
If you can please explain to me more detailed about this error because if I will face this problem again then I can fix it easily.
Edit:
Guys thank you, everyone! I fixed this problem.
Solutions:
VideoView videoView = findViewById(R.id.video_view);
- And I changed path for VideoView according to my packageName.
答案1
得分: 0
请检查是否
<com.devbrackets.android.exomedia.ui.widget.VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:useDefaultControls="true"/>
中的<com.devbrackets.android.exomedia.ui.widget.VideoView
部分是否根据您的包名正确设置了VideoView的路径。
英文:
Please check whether
<com.devbrackets.android.exomedia.ui.widget.VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:useDefaultControls="true"/>
<com.devbrackets.android.exomedia.ui.widget.VideoView path for VideoView is correct according to your packageName.
答案2
得分: 0
根据用户反馈,我检查了一下,这个文件没有完全按照实现要求完成,请尝试另一种视频视图,类似于以下内容:
<VideoView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/VideoView" />
英文:
As i check this file is not complete implement according to user's feedback please try another video view like this
<VideoView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/VideoView" />
答案3
得分: 0
你必须重写构造函数
public VideoPlayerView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
这将解决你的问题。
英文:
You Must override the constructor
public VideoPlayerView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
This will solve your problem.
答案4
得分: -1
请确保您添加了库依赖,并且必须添加以下行:
VideoView vedioView = findViewById(R.id.video_view);
在使用 vedioView 之前。我认为这将解决您的问题。
英文:
Make sure you add the library dependency and must be added this line
VideoView vedioView = findViewById(R.id.video_view);
Before use vedioView. I think it will solve your problem
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论