2011-08-29 73 views
0

E/AndroidRuntime(5751):java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.Android/com.example.Android.OpenByApiActivity}:android.content.res.Resources $ NotFoundException:资源ID#0x7f030001

E/AndroidRuntime(5751):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)

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 $ H.handleMessage(ActivityThread.java:931)

E/AndroidRuntime(5751):android.content.res.Resources $ NotFoundException:致:资源ID#0x7f030001

有没有人知道为什么会被抛出?这是我的视频和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> 

回答

0

代码,你可以试试这个,告诉我,如果你仍然有同样的问题

final File location = new File(Environment.getExternalStorageDirectory(), "/MediaTestFiles/sample.mp4"); 

我想这个问题可能是您的路径。

UPDATE

你能移动此行

@Override 
public void surfaceCreated(SurfaceHolder arg0) { 
    //mp.setDisplay(surfaceHolder); 
    mp.setDisplay(arg0); 
} 

的onSurfaceCreated内。

+0

哇音频作品,但视频不出来?只有音频):知道什么是错的? – Sith

+0

@Master:如果这项工作可以,你可以考虑将此标记为答案。 – Samuel

+0

我很抱歉,onSurfaceCreated在哪里? – Sith

相关问题