小弟是初入門的菜鳥  
目前手上需要製作出一個有錄影功能的程序
只是不論我如何去修正  在編譯器上已經都沒有問題了
可是一匯入模擬器或是實體手機上
就會出現無法預期的錯誤(The application has stopped unexpectdly Please try again)然後要我強制關閉(force close)可是不論在匯入或是執行的時候 我觀察模擬器的console 也都沒有紅色的錯誤訊息阿....以下是我的程式碼部分  麻煩高手指教一下(PS.我目前已經退而求其次的想先做到Vide Preview功能就好.如果可以的話麻煩也教教我如何做到完整的錄影功能.謝謝^^)===================Recorder.java==========================package com.recorder.demo.android;import java.io.IOException;import android.app.Activity;
import android.content.Intent;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;public class Recorder extends Activity implements SurfaceHolder.Callback 
{

private static int RECORD_VIDEO = 1;
private static int HIGH_VIDEO_QUALITY = 1;
private static int MMS_VIDEO_QUALITY = 0; private void recordVideo(Uri outputpath) {
  Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);   if (outputpath != null)
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputpath);
  intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, HIGH_VIDEO_QUALITY);   startActivityForResult(intent, RECORD_VIDEO);
} @Override
protected void onActivityResult(int requestCode, 
                                int resultCode, Intent data) {
  if (requestCode == RECORD_VIDEO) {
    Uri recordedVideo = data.getData();
    // TODO Do something with the recorded video
  }
}
  private MediaRecorder mediaRecorder;   @Override    
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    
    SurfaceView surface = (SurfaceView)findViewById(R.id.surface);
    SurfaceHolder holder = surface.getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    holder.setFixedSize(400, 300);
  }
 
  public void surfaceCreated(SurfaceHolder holder) {  
    if (mediaRecorder == null) {
      try {
        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        
        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
        
        mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
        mediaRecorder.setOutputFile("/sdcard/myoutputfile.mp4");         mediaRecorder.setPreviewDisplay(holder.getSurface());        
        mediaRecorder.prepare();
      } catch (IllegalArgumentException e) {
        Log.d("MEDIA_PLAYER", e.getMessage());
      } catch (IllegalStateException e) {
        Log.d("MEDIA_PLAYER", e.getMessage());
      } catch (IOException e) {
        Log.d("MEDIA_PLAYER", e.getMessage());
      }
    }
  }   public void surfaceDestroyed(SurfaceHolder holder) {
    mediaRecorder.release();
  }    public void surfaceChanged(SurfaceHolder holder, 
                             int format, int width, int height) { }   }
====================================================================================================main.xml===========================================
<?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/surface"
    android:visibility="visible" 
    android:layout_width="400px" 
    android:layout_height="300px" android:duplicateParentState="true">
  </SurfaceView> 
</LinearLayout>
============================================================================Androidmanifest.xml=================================
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.recorder.demo.android"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Recorder"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.RECORD_VIDEO"/>
    </application>
    <uses-sdk android:minSdkVersion="8" /></manifest> 
================================================================麻煩高手了>"<....

解决方案 »

  1.   

    楼主有没有试过Android自带的摄像机功能是否可用呢?如果自带的都用不了,可能是环境问题。
      

  2.   

    Chenzhp前輩   我不大懂你的意思耶@@~  我後來覺得有可能是memory的問題  可是還是不會解決~"~..
      

  3.   

    應該不太可能@@~   我有寫入下面這兩行開啟權限的code說....
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.RECORD_VIDEO"/>
      

  4.   

    是不是 你要调用的activity没有声明呢?
    Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    类似在AndroidManifest.xml加入
    <activity android:name=".MediaStore" android:label="@string/MenuList_name"></activity>我也是菜鸟,但是由于刚才遇到类似问题,你可以试试看...
      

  5.   

    权限不太对吧,
     <uses-permission   android:name="android.permission.CAMERA"></uses-permission>
      

  6.   

    google提供的你不用