我遇到了一个奇怪的问题。我正在 HTC EVO 上进行测试。我写了一个针对 2.2 的演示相机应用程序,几乎一切正常。问题是拍了三四张照片后,应用程序崩溃并给我以下消息:
D/QualcommCameraHardware( 64): takePicture(479)
D/QualcommCameraHardware( 64): val_ril_status = 0,val_wimax_status = 0,val_hotspot_status = 0,val_low_temp_limit = 10.000000,val_batt_temp = 29.799999,val_low_temp_limit = 15,val_batt_cap = 96
D/QualcommCameraHardware( 64): FLASHLIGHT is ENABLED
D/QualcommCameraHardware( 64): stopPreviewInternal E: 1
D/QualcommCameraHardware( 64): cancelAutoFocusInternal E
D/QualcommCameraHardware( 64): cancelAutoFocusInternal X: 0
I/QualcommCameraHardware( 64): deinitPreview E
D/QualcommCameraHardware( 64): launch_watchdog_thread:
D/QualcommCameraHardware( 64): watchdog_thread_id = 369048
I/QualcommCameraHardware( 64): register_buf: camfd = 35, reg = 1 buffer = 0x4153f000
I/QualcommCameraHardware( 64): register_buf: camfd = 35, reg = 1 buffer = 0x415bf000
I/QualcommCameraHardware( 64): register_buf: camfd = 35, reg = 1 buffer = 0x4163f000
I/QualcommCameraHardware( 64): register_buf: camfd = 35, reg = 1 buffer = 0x416bf000
I/QualcommCameraHardware( 64): register_buf: camfd = 38, reg = 1 buffer = 0x4331d000
I/QualcommCameraHardware( 64): register_buf: camfd = 38, reg = 1 buffer = 0x4351d000
I/QualcommCameraHardware( 64): register_buf: camfd = 38, reg = 1 buffer = 0x4371d000
I/QualcommCameraHardware( 64): register_buf: camfd = 38, reg = 1 buffer = 0x4391d000
I/QualcommCameraHardware( 64): register_buf: camfd = 38, reg = 1 buffer = 0x43b1d000
I/QualcommCameraHardware( 64): register_buf: camfd = 38, reg = 1 buffer = 0x43d1d000
I/QualcommCameraHardware( 64): register_buf: camfd = 38, reg = 1 buffer = 0x43f1d000
I/QualcommCameraHardware( 64): register_buf: camfd = 38, reg = 1 buffer = 0x4411d000
I/QualcommCameraHardware( 64): deinitPreview X
D/QualcommCameraHardware( 64): stopPreviewInternal X: 0
D/QualcommCameraHardware( 64): initRaw E: raw size=3264x2448
D/QualcommCameraHardware( 64): initRaw: raw ration = 0.750000, display size=768x432
D/QualcommCameraHardware( 64): initRaw: thumbnail_width=768, thumbnail_height=576, thumbnail_buffer_size=663552
D/QualcommCameraHardware( 64): native_access_parm: fd 24, type 1, length 32
D/mm-camera-ov8810_u( 64): andy cam_mode_sel 0
D/QualcommCameraHardware( 64): initRaw: initializing mRawHeap.
E/MemoryHeapBase( 64): error opening /dev/pmem_camera: No such file or directory
E/QualcommCameraHardware( 64): failed to construct master heap for pmem pool /dev/pmem_camera
E/QualcommCameraHardware( 64): initRaw X failed with pmem_camera, trying with pmem_adsp
D/QualcommCameraHardware( 64): frame_thread X
D/QualcommCameraHardware( 64): watchdog_thread_id = 369048
D/QualcommCameraHardware( 64): release_watchdog_thread: frame_thread_released = 1
E/MemoryHeapBase( 64): mmap(fd=38, size=11988992) failed (Invalid argument)
E/QualcommCameraHardware( 64): failed to construct master heap for pmem pool /dev/pmem_adsp
E/QualcommCameraHardware( 64): initRaw X: error initializing mRawHeap
E/QualcommCameraHardware( 64): initRaw failed. Not taking picture.
D/AndroidRuntime( 2650): Shutting down VM
W/dalvikvm( 2650): threadid=1: thread exiting with uncaught exception (group=0x400259f8)
E/AndroidRuntime( 2650): FATAL EXCEPTION: main
E/AndroidRuntime( 2650): java.lang.RuntimeException: takePicture failed
E/AndroidRuntime( 2650): at android.hardware.Camera.native_takePicture(Native Method)
E/AndroidRuntime( 2650): at android.hardware.Camera.takePicture(Camera.java:535)
E/AndroidRuntime( 2650): at android.hardware.Camera.takePicture(Camera.java:503)
E/AndroidRuntime( 2650): at spikes.cameraSpike03.MainActivity.takePicture(MainActivity.java:90)
E/AndroidRuntime( 2650): at spikes.cameraSpike03.MainActivity.access$3(MainActivity.java:87)
E/AndroidRuntime( 2650): at spikes.cameraSpike03.MainActivity$3.onClick(MainActivity.java:80)
E/AndroidRuntime( 2650): at android.view.View.performClick(View.java:2408)
E/AndroidRuntime( 2650): at android.view.View$PerformClick.run(View.java:8817)
E/AndroidRuntime( 2650): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 2650): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 2650): at android.os.Looper.loop(Looper.java:144)
E/AndroidRuntime( 2650): at android.app.ActivityThread.main(ActivityThread.java:4937)
E/AndroidRuntime( 2650): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2650): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 2650): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 2650): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 2650): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 107): Force finishing activity spikes.cameraSpike03/.MainActivity
D/QualcommCameraHardware( 64): void* watchdog(void*), frame_thread_released = 1, cnt = 0
D/QualcommCameraHardware( 64): void* watchdog(void*), exit, frame_thread_released=1
D/QualcommCameraHardware( 64): void release_watchdog_thread(): pthread_join succeeded on watchdog.
这可能是内存管理问题吗?
下面是我使用的所有代码。
[AndroidManifest.xml]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="spikes.cameraSpike03"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<activity android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.flash" />
</manifest>
[主.xml]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<SurfaceView android:id="@+id/svCameraView" android:layout_width="fill_parent" android:layout_height="fill_parent" />
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:background="#3000" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:gravity="center_horizontal">
<Button android:id="@+id/btnCapture" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="capture" />
<CheckBox android:id="@+id/chkAutofocus" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Autofocus" />
</LinearLayout>
</RelativeLayout>
[主 Activity .java]
package spikes.cameraSpike03;
import java.util.List;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.AutoFocusCallback;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.ShutterCallback;
import android.hardware.Camera.Size;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
public class MainActivity extends Activity implements SurfaceHolder.Callback {
private static final String LOG_TAG = MainActivity.class.getName();
private static final String LOG_LINE = "---------------------------------";
private Camera _camera;
private boolean _previewIsRunning = false;
private SurfaceView _svCameraView;
private SurfaceHolder _surfaceHolder;
private Button _btnCapture;
private CheckBox _chkAutofocus;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
_svCameraView = (SurfaceView)findViewById(R.id.svCameraView);
_surfaceHolder = _svCameraView.getHolder();
_surfaceHolder.addCallback(this);
_surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
_chkAutofocus = (CheckBox)findViewById(R.id.chkAutofocus);
_btnCapture = (Button)findViewById(R.id.btnCapture);
_btnCapture.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(_camera != null){
//Decide whether or not to use autofocus
if(_chkAutofocus.isChecked()){
Log.d(LOG_TAG, LOG_LINE + "Preparing to take the picture using autofocus...");
_camera.autoFocus(new AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
Log.d(LOG_TAG, LOG_LINE + "_camera.autoFocus.onAutoFocus(...) entered.");
takePicture();
Log.d(LOG_TAG, LOG_LINE + "_camera.autoFocus.onAutoFocus(...) finished.");
}
});
}
else{
Log.d(LOG_TAG, LOG_LINE + "Preparing to take the picture without autofocus...");
takePicture();
}
}
}
});
}
private void takePicture(){
Log.d(LOG_TAG, LOG_LINE + "takePicture() entered.");
_camera.takePicture(_shutterCallback, null, _jpegCallback);
_previewIsRunning = false;
Log.d(LOG_TAG, LOG_LINE + "takePicture() finished.");
}
private ShutterCallback _shutterCallback = new ShutterCallback() {
@Override
public void onShutter() {
Log.d(LOG_TAG, LOG_LINE + "_shutterCallback.onShutter() called.");
}
};
private PictureCallback _jpegCallback = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Log.d(LOG_TAG, LOG_LINE + "_jpegCallback.onPictureTaken() called.");
_camera.startPreview();
_previewIsRunning = true;
}
};
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if(_previewIsRunning){
Log.d(LOG_TAG, LOG_LINE + "About to stop preview...");
_camera.stopPreview();
Log.d(LOG_TAG, LOG_LINE + "Stopped preview.");
}
try{
Log.d(LOG_TAG, LOG_LINE + "About to set up camera parameters...");
Camera.Parameters parameters = _camera.getParameters();
//Get the optimal preview size so we don't get an exception when setting the parameters
List<Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes();
Size optimalPreviewSize = CameraUtil.getOptimalPreviewSize(supportedPreviewSizes, width, height);
parameters.setPreviewSize(optimalPreviewSize.width, optimalPreviewSize.height);
parameters.setFocusMode(Parameters.FOCUS_MODE_AUTO);
parameters.setFlashMode(Parameters.FLASH_MODE_AUTO);
_camera.setDisplayOrientation(90);
_camera.setParameters(parameters);
_camera.setPreviewDisplay(holder);
Log.d(LOG_TAG, LOG_LINE + "Finished setting up camera parameters.");
}
catch(Exception ex){
ex.printStackTrace();
Log.e(LOG_TAG, ex.toString());
}
Log.d(LOG_TAG, LOG_LINE + "About to start preview...");
_camera.startPreview();
_previewIsRunning = true;
Log.d(LOG_TAG, LOG_LINE + "Started preview.");
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
_camera = Camera.open();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
Log.d(LOG_TAG, LOG_LINE + "Tearing down camera because surface was destroyed...");
_camera.stopPreview();
_previewIsRunning = false;
_camera.release();
Log.d(LOG_TAG, LOG_LINE + "Finished tearing down camera because surface was destroyed.");
}
@Override
public void onConfigurationChanged(Configuration newConfig){
Log.d(LOG_TAG, LOG_LINE + "About to set request orientation to SCREEN_ORIENTATION_PORTRAIT...");
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Log.d(LOG_TAG, LOG_LINE + "Successfully set request orientation to SCREEN_ORIENTATION_PORTRAIT.");
}
}
[CameraUtil.java]
package spikes.cameraSpike03;
import java.util.List;
import android.hardware.Camera.Size;
public class CameraUtil {
private CameraUtil(){}
/**
* Returns a Size object containing the dimensions for an optimal preview size for the current hardware.
* This code is based on that found at: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html
*
* @param supportedSizes
* A list of Size objects representing all the known preview sizes supported by this hardware.
*
* @param w
* The surface width.
*
* @param h
* The surface height.
*
* @return
* Returns a Size object containing the dimensions for an optimal preview size for the current hardware.
*/
public static Size getOptimalPreviewSize(List<Size> supportedSizes, int w, int h) {
final double ASPECT_TOLERANCE = 0.05;
double targetRatio = (double) w / h;
if (supportedSizes == null) return null;
Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = h;
// Try to find an size match aspect ratio and size
for (Size size : supportedSizes) {
double ratio = (double) size.width / size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
// Cannot find the one match the aspect ratio, ignore the requirement
if (optimalSize == null) {
minDiff = Double.MAX_VALUE;
for (Size size : supportedSizes) {
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
return optimalSize;
}
}
如有任何建议,我们将不胜感激。
谢谢。
最佳答案
我也遇到了类似的问题。后来发现startPreview很重要。
_camera.startPreview() 在 takePicutre 检查此链接中的第 5 点和第 6 点之前非常重要。
http://developer.android.com/reference/android/hardware/Camera.html
关于安卓: "Camera.takePicture failed"异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4830772/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我正在学习Rails,并阅读了关于乐观锁的内容。我已将类型为integer的lock_version列添加到我的articles表中。但现在每当我第一次尝试更新记录时,我都会收到StaleObjectError异常。这是我的迁移:classAddLockVersionToArticle当我尝试通过Rails控制台更新文章时:article=Article.first=>#我这样做:article.title="newtitle"article.save我明白了:(0.3ms)begintransaction(0.3ms)UPDATE"articles"SET"title"='dwdwd
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
我早就知道Ruby中的“常量”(即大写的变量名)不是真正常量。与其他编程语言一样,对对象的引用是唯一存储在变量/常量中的东西。(侧边栏:Ruby确实具有“卡住”引用对象不被修改的功能,据我所知,许多其他语言都没有提供这种功能。)所以这是我的问题:当您将一个值重新分配给常量时,您会收到如下警告:>>FOO='bar'=>"bar">>FOO='baz'(irb):2:warning:alreadyinitializedconstantFOO=>"baz"有没有办法强制Ruby抛出异常而不是打印警告?很难弄清楚为什么有时会发生重新分配。 最佳答案