写了一个android手机录像应用。。但是一模拟就说无法打开。。手机运行也是
下面是logcat里面的报错(前半部分,后半部分在二楼)05-08 17:16:56.863: E/Zygote(33): setreuid() failed. errno: 2
05-08 17:17:07.312: E/Zygote(33): setreuid() failed. errno: 17
05-08 17:17:09.302: E/BatteryService(66): usbOnlinePath not found
05-08 17:17:09.302: E/BatteryService(66): batteryVoltagePath not found
05-08 17:17:09.302: E/BatteryService(66): batteryTemperaturePath not found
05-08 17:17:09.332: E/SurfaceFlinger(66): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
05-08 17:17:16.752: E/EventHub(66): could not get driver version for /dev/input/mouse0, Not a typewriter
05-08 17:17:16.752: E/EventHub(66): could not get driver version for /dev/input/mice, Not a typewriter
05-08 17:17:17.512: E/System(66): Failure starting core service
05-08 17:17:17.512: E/System(66): java.lang.SecurityException
05-08 17:17:17.512: E/System(66):  at android.os.BinderProxy.transact(Native Method)
05-08 17:17:17.512: E/System(66):  at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
05-08 17:17:17.512: E/System(66):  at android.os.ServiceManager.addService(ServiceManager.java:72)
05-08 17:17:17.512: E/System(66):  at com.android.server.ServerThread.run(SystemServer.java:184)
05-08 17:17:18.482: E/SoundPool(66): error loading /system/media/audio/ui/Effect_Tick.ogg
05-08 17:17:18.482: E/SoundPool(66): error loading /system/media/audio/ui/KeypressStandard.ogg
05-08 17:17:18.482: E/SoundPool(66): error loading /system/media/audio/ui/KeypressSpacebar.ogg
05-08 17:17:18.493: E/SoundPool(66): error loading /system/media/audio/ui/KeypressDelete.ogg
05-08 17:17:18.493: E/SoundPool(66): error loading /system/media/audio/ui/KeypressReturn.ogg
05-08 17:17:21.173: E/ThrottleService(66): Could not open GPS configuration file /etc/gps.conf
05-08 17:17:23.602: E/logwrapper(148): executing /system/bin/tc failed: No such file or directory
05-08 17:17:23.692: E/logwrapper(149): executing /system/bin/tc failed: No such file or directory
05-08 17:17:23.782: E/logwrapper(150): executing /system/bin/tc failed: No such file or directory
05-08 17:17:40.367: E/HierarchicalStateMachine(66): TetherMaster - unhandledMessage: msg.what=3
05-08 17:18:05.448: E/AndroidRuntime(278): FATAL EXCEPTION: main
05-08 17:18:05.448: E/AndroidRuntime(278): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.camera/com.example.camera.CameraActivity}: java.lang.ClassCastException: com.example.camera.CameraActivity
05-08 17:18:05.448: E/AndroidRuntime(278):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-08 17:18:05.448: E/AndroidRuntime(278):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-08 17:18:05.448: E/AndroidRuntime(278):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-08 17:18:05.448: E/AndroidRuntime(278):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-08 17:18:05.448: E/AndroidRuntime(278):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 17:18:05.448: E/AndroidRuntime(278):  at android.os.Looper.loop(Looper.java:123)
05-08 17:18:05.448: E/AndroidRuntime(278):  at android.app.ActivityThread.main(ActivityThread.java:4627)
05-08 17:18:05.448: E/AndroidRuntime(278):  at java.lang.reflect.Method.invokeNative(Native Method)
05-08 17:18:05.448: E/AndroidRuntime(278):  at java.lang.reflect.Method.invoke(Method.java:521)
05-08 17:18:05.448: E/AndroidRuntime(278):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-08 17:18:05.448: E/AndroidRuntime(278):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-08 17:18:05.448: E/AndroidRuntime(278):  at dalvik.system.NativeStart.main(Native Method)
05-08 17:18:05.448: E/AndroidRuntime(278): Caused by: java.lang.ClassCastException: com.example.camera.CameraActivity
然后是activity
package com.example.camera;import java.io.File;
import java.io.IOException;import android.graphics.PixelFormat;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.Menu;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;public class CameraActivity extends Activity {
private SurfaceView msurfaceview;
private Button buttonstart;
private Button buttonstop;
private MediaRecorder recorder;
private SurfaceHolder surfaceholder;
private File savefile;
private File SDfile;
private String savepath;
private File recfile;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFormat(PixelFormat.TRANSLUCENT); setContentView(R.layout.main);
msurfaceview = (SurfaceView) findViewById(R.id.mysurfaceview);
buttonstart = (Button) findViewById(R.id.start);
buttonstop = (Button) findViewById(R.id.stop);
surfaceholder = msurfaceview.getHolder();
surfaceholder.addCallback((Callback) this);
surfaceholder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
SDfile = Environment.getExternalStorageDirectory();
savepath = SDfile.getAbsolutePath()+File.separator+"mvideo"+File.separator;
savefile = new File(savepath);
buttonstart.setOnClickListener(new buttonstartlistener());
buttonstop.setOnClickListener(new buttonstoplistener());


if (!savefile.exists())
{
savefile.mkdirs();
}

recorder = new MediaRecorder();
}
class buttonstartlistener implements OnClickListener{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
record();
}

}
class buttonstoplistener implements OnClickListener{ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
recorder.stop();
recorder.release();
recorder.reset();
recorder = null;
}

} public void record()
{
try{
recfile = File.createTempFile("Video",".3gp",savefile);
recorder.setPreviewDisplay(surfaceholder.getSurface());
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setVideoSize(800,480);
recorder.setVideoFrameRate(20);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setMaxDuration(60*1000);
recorder.setOutputFile(recfile.getAbsolutePath());
recorder.prepare();
recorder.start();
}catch(IOException e){
e.printStackTrace();
}
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.camera, menu);
return true;
}}
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".CameraActivity" >
    
    <SurfaceView
        android:id="@+id/mysurfaceview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:visibility="visible" />    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_alignBottom="@+id/mysurfaceview">        <Button
            android:id="@+id/stop"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="stop" />        <Button
            android:id="@+id/start"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:text="start" />    </RelativeLayout></RelativeLayout>Manifest<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.camera"
    android:versionCode="1"
    android:versionName="1.0" >    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />    <uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.camera.CameraActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    
    </application></manifest>
完全不知道是怎么回事啊,logcat看不懂。。请教高手们
Android无法运行视频录像代码

解决方案 »

  1.   

    logcat的后半部分
    05-08 17:18:05.448: E/AndroidRuntime(278):  at com.example.camera.CameraActivity.onCreate(CameraActivity.java:46)
    05-08 17:18:05.448: E/AndroidRuntime(278):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    05-08 17:18:05.448: E/AndroidRuntime(278):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
    05-08 17:18:05.448: E/AndroidRuntime(278):  ... 11 more
    05-08 17:21:21.159: E/AndroidRuntime(285): FATAL EXCEPTION: main
    05-08 17:21:21.159: E/AndroidRuntime(285): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.camera/com.example.camera.CameraActivity}: java.lang.ClassCastException: com.example.camera.CameraActivity
    05-08 17:21:21.159: E/AndroidRuntime(285):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
    05-08 17:21:21.159: E/AndroidRuntime(285):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    05-08 17:21:21.159: E/AndroidRuntime(285):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    05-08 17:21:21.159: E/AndroidRuntime(285):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    05-08 17:21:21.159: E/AndroidRuntime(285):  at android.os.Handler.dispatchMessage(Handler.java:99)
    05-08 17:21:21.159: E/AndroidRuntime(285):  at android.os.Looper.loop(Looper.java:123)
    05-08 17:21:21.159: E/AndroidRuntime(285):  at android.app.ActivityThread.main(ActivityThread.java:4627)
    05-08 17:21:21.159: E/AndroidRuntime(285):  at java.lang.reflect.Method.invokeNative(Native Method)
    05-08 17:21:21.159: E/AndroidRuntime(285):  at java.lang.reflect.Method.invoke(Method.java:521)
    05-08 17:21:21.159: E/AndroidRuntime(285):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    05-08 17:21:21.159: E/AndroidRuntime(285):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    05-08 17:21:21.159: E/AndroidRuntime(285):  at dalvik.system.NativeStart.main(Native Method)
    05-08 17:21:21.159: E/AndroidRuntime(285): Caused by: java.lang.ClassCastException: com.example.camera.CameraActivity
    05-08 17:21:21.159: E/AndroidRuntime(285):  at com.example.camera.CameraActivity.onCreate(CameraActivity.java:46)
    05-08 17:21:21.159: E/AndroidRuntime(285):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    05-08 17:21:21.159: E/AndroidRuntime(285):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
    05-08 17:21:21.159: E/AndroidRuntime(285):  ... 11 more
    05-08 17:22:22.988: E/AndroidRuntime(305): FATAL EXCEPTION: main
    05-08 17:22:22.988: E/AndroidRuntime(305): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.camera/com.example.camera.CameraActivity}: java.lang.ClassCastException: com.example.camera.CameraActivity
    05-08 17:22:22.988: E/AndroidRuntime(305):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
    05-08 17:22:22.988: E/AndroidRuntime(305):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    05-08 17:22:22.988: E/AndroidRuntime(305):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    05-08 17:22:22.988: E/AndroidRuntime(305):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    05-08 17:22:22.988: E/AndroidRuntime(305):  at android.os.Handler.dispatchMessage(Handler.java:99)
    05-08 17:22:22.988: E/AndroidRuntime(305):  at android.os.Looper.loop(Looper.java:123)
    05-08 17:22:22.988: E/AndroidRuntime(305):  at android.app.ActivityThread.main(ActivityThread.java:4627)
    05-08 17:22:22.988: E/AndroidRuntime(305):  at java.lang.reflect.Method.invokeNative(Native Method)
    05-08 17:22:22.988: E/AndroidRuntime(305):  at java.lang.reflect.Method.invoke(Method.java:521)
    05-08 17:22:22.988: E/AndroidRuntime(305):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    05-08 17:22:22.988: E/AndroidRuntime(305):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    05-08 17:22:22.988: E/AndroidRuntime(305):  at dalvik.system.NativeStart.main(Native Method)
    05-08 17:22:22.988: E/AndroidRuntime(305): Caused by: java.lang.ClassCastException: com.example.camera.CameraActivity
    05-08 17:22:22.988: E/AndroidRuntime(305):  at com.example.camera.CameraActivity.onCreate(CameraActivity.java:46)
    05-08 17:22:22.988: E/AndroidRuntime(305):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    05-08 17:22:22.988: E/AndroidRuntime(305):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
    05-08 17:22:22.988: E/AndroidRuntime(305):  ... 11 more
    : E/(): Device disconnected新手,,,看不懂这个。。想高手们求教。。到底问题出在哪儿了?
      

  2.   

    http://blog.csdn.net/shen332401890/article/details/8819564还有demo 看看
      

  3.   

    额。。为什么我新申明一个Camera变量上面的说明是android.graphics.Camera。。而你的demo里面的Camera是android.hardware.Camera而且我的那个Camera就没有unlock方法新手。很多都不懂。
      

  4.   

    额。。为什么我新申明一个Camera变量上面的说明是android.graphics.Camera。。而你的demo里面的Camera是android.hardware.Camera而且我的那个Camera就没有unlock方法新手。很多都不懂。graphics 用于处理图片的
    hardware 是真正的摄像头
      

  5.   

    额。。为什么我新申明一个Camera变量上面的说明是android.graphics.Camera。。而你的demo里面的Camera是android.hardware.Camera而且我的那个Camera就没有unlock方法新手。很多都不懂。graphics 用于处理图片的
    hardware 是真正的摄像头

    那应该怎么写才会有hardware.camera呀。。权限我都补充进去了。我的就是这个样子
      

  6.   

    可能是import有问题,声明变量的时候把前缀带上,如android.graphics.Camera camera;
      

  7.   

    你把前面的 import android.graphics.Camera 改为 import android.hardware.Camera 应该就好了
      

  8.   

    你需要了解一下 Java 的package
      

  9.   

    新手为什么不写hello word。实践证明,hello world 20行 写10次,比一次写一个200行然后调试半天效果和效率都高。log和import都不看,肯定hello world 都没真正搞懂