[英]Resources$NotFoundException when trying to play a video on Android?
E/AndroidRuntime( 5751): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.Android/com.example.Android.OpenByApiActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030001
E/AndroidRuntime(5751):java.lang.RuntimeException:无法启动活动组件信息{com.example.Android/com.example.Android.OpenByApiActivity}:android.content.res.Resources$NotFoundException:资源ID#0x7f030001
E/AndroidRuntime( 5751): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
E/AndroidRuntime(5751): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
E/AndroidRuntime( 5751): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
E/AndroidRuntime(5751): 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
E/AndroidRuntime( 5751): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime(5751):在 android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime( 5751): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
E/AndroidRuntime(5751): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
E/AndroidRuntime( 5751): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030001
E/AndroidRuntime(5751):引起:android.content.res.Resources$NotFoundException:资源 ID #0x7f030001
Does anybody know why this is being thrown?有谁知道为什么会抛出这个? This is my code for the video and xml
这是我的视频和 xml 代码
public class OpenByApiActivity extends Activity implements Callback {
MediaPlayer mp = new MediaPlayer();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.video);
StringBuilder log = new StringBuilder();
String[] clearLogcat = new String[] { "logcat", "-c",};
try {
Runtime.getRuntime().exec(clearLogcat);
}
catch (IOException e) {
e.printStackTrace();
}
File location = new File("/sdcard/MediaTestFiles/sample.mp4");
Uri path = Uri.fromFile(location);
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
getWindow().setFormat(PixelFormat.UNKNOWN);
surfaceView = (SurfaceView)findViewById(R.id.surfaceview);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
surfaceHolder.setFixedSize(176, 144);
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setDisplay(surfaceHolder);
mp= MediaPlayer.create(this, path);
if(mp!=null){
mp.start();
}}}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder arg0) {
// TODO Auto-generated method stub
}
@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
// TODO Auto-generated method stub
}}
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<SurfaceView
android:id="@+id/surfaceview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
can you try this and tell me if you still have the same problem你能试试这个并告诉我你是否还有同样的问题
final File location = new File(Environment.getExternalStorageDirectory(), "/MediaTestFiles/sample.mp4");
i guess the problem may be with your path.我想问题可能出在你的路径上。
UPDATE更新
can you move this line你能移动这条线吗
@Override
public void surfaceCreated(SurfaceHolder arg0) {
//mp.setDisplay(surfaceHolder);
mp.setDisplay(arg0);
}
inside the onSurfaceCreated.在 onSurfaceCreated 里面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.