Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Front Camera
    primarykey
    data
    text
    <p>i'm trying to use front camera using this tutorial</p> <p><a href="http://www.vogella.com/articles/AndroidCamera/article.html" rel="nofollow">http://www.vogella.com/articles/AndroidCamera/article.html</a></p> <p>but got a problem that is making me mad.</p> <p>1st of all, if use the code provided by example, at onClick(View view) the camera is null. is this a mine problem? however, i solved that implementing camera.open() directly in my onClick method.</p> <pre><code> public void takePhoto(View view) { if (!getPackageManager() .hasSystemFeature(PackageManager.FEATURE_CAMERA)) { Toast.makeText(this, "No camera on this device", Toast.LENGTH_LONG).show(); } else { cameraId = findFrontFacingCamera(); if (cameraId &lt; 0) { Toast.makeText(this, "No front facing camera found.", Toast.LENGTH_LONG).show(); } else { camera = Camera.open(cameraId); } } try{ PhotoHandler photoHandler = new PhotoHandler(getApplicationContext()); camera.takePicture(null, null,photoHandler); }catch(Exception c){ Log.e("error", c.toString(),c.getCause()); } } </code></pre> <p>i added</p> <pre><code>try{ PhotoHandler photoHandler = new PhotoHandler(getApplicationContext()); camera.takePicture(null, null,photoHandler); }catch(Exception c){ Log.e("error", c.toString(),c.getCause()); } </code></pre> <p>to see what's the problem and logcat tells me </p> <pre><code>05-16 17:19:00.456: E/AndroidRuntime(12638): FATAL EXCEPTION: main 05-16 17:19:00.456: E/AndroidRuntime(12638): java.lang.IllegalStateException: Could not execute method of the activity 05-16 17:19:00.456: E/AndroidRuntime(12638): at android.view.View$1.onClick(View.java:3599) 05-16 17:19:00.456: E/AndroidRuntime(12638): at android.view.View.performClick(View.java:4204) 05-16 17:19:00.456: E/AndroidRuntime(12638): at android.view.View$PerformClick.run(View.java:17354) 05-16 17:19:00.456: E/AndroidRuntime(12638): at android.os.Handler.handleCallback(Handler.java:725) 05-16 17:19:00.456: E/AndroidRuntime(12638): at android.os.Handler.dispatchMessage(Handler.java:92) 05-16 17:19:00.456: E/AndroidRuntime(12638): at android.os.Looper.loop(Looper.java:137) 05-16 17:19:00.456: E/AndroidRuntime(12638): at android.app.ActivityThread.main(ActivityThread.java:5231) 05-16 17:19:00.456: E/AndroidRuntime(12638): at java.lang.reflect.Method.invokeNative(Native Method) 05-16 17:19:00.456: E/AndroidRuntime(12638): at java.lang.reflect.Method.invoke(Method.java:511) 05-16 17:19:00.456: E/AndroidRuntime(12638): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) 05-16 17:19:00.456: E/AndroidRuntime(12638): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:561) 05-16 17:19:00.456: E/AndroidRuntime(12638): at dalvik.system.NativeStart.main(Native Method) 05-16 17:19:00.456: E/AndroidRuntime(12638): Caused by: java.lang.reflect.InvocationTargetException 05-16 17:19:00.456: E/AndroidRuntime(12638): at java.lang.reflect.Method.invokeNative(Native Method) 05-16 17:19:00.456: E/AndroidRuntime(12638): at java.lang.reflect.Method.invoke(Method.java:511) 05-16 17:19:00.456: E/AndroidRuntime(12638): at android.view.View$1.onClick(View.java:3594) 05-16 17:19:00.456: E/AndroidRuntime(12638): ... 11 more 05-16 17:19:00.456: E/AndroidRuntime(12638): Caused by: java.lang.RuntimeException: **Fail to connect to camera service** 05-16 17:19:00.456: E/AndroidRuntime(12638): at android.hardware.Camera.native_setup(Native Method) 05-16 17:19:00.456: E/AndroidRuntime(12638): at android.hardware.Camera.&lt;init&gt;(Camera.java:340) 05-16 17:19:00.456: E/AndroidRuntime(12638): at android.hardware.Camera.open(Camera.java:302) 05-16 17:19:00.456: E/AndroidRuntime(12638): at com.example.cameratest.MainActivity.takePhoto(MainActivity.java:34) 05-16 17:19:00.456: E/AndroidRuntime(12638): ... 14 more </code></pre> <p>my AndroidManifest.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.cameratest" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-permission android:name="android.permission.CAMERA" /&gt; &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt; &lt;uses-feature android:name="android.hardware.camera" /&gt; &lt;uses-feature android:name="android.hardware.camera.front" /&gt; &lt;uses-sdk android:minSdkVersion="9" android:targetSdkVersion="17" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.example.cameratest.MainActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload