Log in or register to post comments

Could not find method android.hardware.Camera.getNumberOfCameras

November 6, 2012 - 3:19am #1

Hi,

I am tring to build a sample application using QCAR. I did the example same like FrameMarkers example.

When I export it as Android Applicaiton I am getting "Cound Not find method android.hardware.Camera.getNumberOfCameras".

But when I build the sampe FrameMarkers example I am not getting this error.

It seems everyting is ok to me.

Does am I missing any settings?

I added QCAR.jar as referenced library from my project properties (Properties -> JavaBuildPath -> AddJars-)

I added the camera permissons to the manifest file also as follows

 <uses-feature android:name="android.hardware.camera" />
   
    <!--
        Add this permission to get access to the camera
    -->
    <uses-permission android:name="android.permission.CAMERA" />

 

Here is the log cat

11-06 16:35:13.227: D/dalvikvm(9193): Trying to load lib /data/data/com.Trikona.AR.education/lib/libQCAR.so 0x480b5f30
11-06 16:35:13.227: D/dalvikvm(9193): Added shared lib /data/data/com.Trikona.AR.education/lib/libQCAR.so 0x480b5f30
11-06 16:35:13.231: I/dalvikvm(9193): Could not find method android.hardware.Camera.getNumberOfCameras, referenced from method com.qualcomm.ar.pl.CameraPreview.getCameraDeviceIndex
11-06 16:35:13.231: W/dalvikvm(9193): VFY: unable to resolve static method 251: Landroid/hardware/Camera;.getNumberOfCameras ()I
11-06 16:35:13.231: D/dalvikvm(9193): VFY: replacing opcode 0x71 at 0x0019
11-06 16:35:13.231: D/dalvikvm(9193): VFY: dead code 0x001c-0034 in Lcom/qualcomm/ar/pl/CameraPreview;.getCameraDeviceIndex (III)I
11-06 16:35:13.231: D/dalvikvm(9193): VFY: dead code 0x0037-003e in Lcom/qualcomm/ar/pl/CameraPreview;.getCameraDeviceIndex (III)I
11-06 16:35:13.239: E/dalvikvm(9193): Could not find class 'android.hardware.Camera$CameraInfo', referenced from method com.qualcomm.ar.pl.CameraPreview.getDirection
11-06 16:35:13.239: W/dalvikvm(9193): VFY: unable to resolve new-instance 51 (Landroid/hardware/Camera$CameraInfo;) in Lcom/qualcomm/ar/pl/CameraPreview;
11-06 16:35:13.239: D/dalvikvm(9193): VFY: replacing opcode 0x22 at 0x0017
11-06 16:35:13.239: D/dalvikvm(9193): VFY: dead code 0x0019-0032 in Lcom/qualcomm/ar/pl/CameraPreview;.getDirection (I)I
11-06 16:35:13.239: I/dalvikvm(9193): Could not find method android.hardware.Camera.getNumberOfCameras, referenced from method com.qualcomm.ar.pl.CameraPreview.getNumberOfCameras
11-06 16:35:13.239: W/dalvikvm(9193): VFY: unable to resolve static method 251: Landroid/hardware/Camera;.getNumberOfCameras ()I
11-06 16:35:13.239: D/dalvikvm(9193): VFY: replacing opcode 0x71 at 0x0014
11-06 16:35:13.239: D/dalvikvm(9193): VFY: dead code 0x0017-0018 in Lcom/qualcomm/ar/pl/CameraPreview;.getNumberOfCameras ()I
11-06 16:35:13.239: I/dalvikvm(9193): Could not find method android.hardware.Camera$Parameters.getFocusDistances, referenced from method com.qualcomm.ar.pl.CameraPreview.getTypedCameraParameter
11-06 16:35:13.243: W/dalvikvm(9193): VFY: unable to resolve virtual method 225: Landroid/hardware/Camera$Parameters;.getFocusDistances ([F)V
11-06 16:35:13.243: D/dalvikvm(9193): VFY: replacing opcode 0x6e at 0x00e8
11-06 16:35:13.243: D/dalvikvm(9193): VFY: dead code 0x00eb-00fb in Lcom/qualcomm/ar/pl/CameraPreview;.getTypedCameraParameter (II)Ljava/lang/Object;
11-06 16:35:13.243: I/dalvikvm(9193): Could not find method android.hardware.Camera.open, referenced from method com.qualcomm.ar.pl.CameraPreview.open
11-06 16:35:13.250: W/dalvikvm(9193): VFY: unable to resolve static method 254: Landroid/hardware/Camera;.open (I)Landroid/hardware/Camera;
11-06 16:35:13.250: D/dalvikvm(9193): VFY: replacing opcode 0x77 at 0x00aa
11-06 16:35:13.250: D/dalvikvm(9193): VFY: dead code 0x00ad-00b1 in Lcom/qualcomm/ar/pl/CameraPreview;.open (IIILjava/lang/String;[I[I)I
11-06 16:35:13.254: D/dalvikvm(9193): DexOpt: couldn't find field Landroid/content/pm/ApplicationInfo;.nativeLibraryDir
11-06 16:35:13.254: W/dalvikvm(9193): VFY: unable to resolve instance field 16
11-06 16:35:13.258: D/dalvikvm(9193): VFY: replacing opcode 0x54 at 0x0016
11-06 16:35:13.258: D/dalvikvm(9193): VFY: dead code 0x0018-003f in Lcom/qualcomm/ar/pl/SystemTools;.getNativeLibraryPath (Landroid/app/Activity;)Ljava/lang/String;
11-06 16:35:13.270: D/dalvikvm(9193): Trying to load lib /data/data/com.Trikona.AR.education/lib/libTrikonaQCAREdu.so 0x480b5f30
11-06 16:35:13.270: D/dalvikvm(9193): Added shared lib /data/data/com.Trikona.AR.education/lib/libTrikonaQCAREdu.so 0x480b5f30
11-06 16:35:13.270: D/dalvikvm(9193): No JNI_OnLoad found in /data/data/com.Trikona.AR.education/lib/libTrikonaQCAREdu.so 0x480b5f30, skipping init
11-06 16:35:13.274: D/DEBUG---(9193): FrameMarkers::onCreate
11-06 16:35:13.348: D/DEBUG---(9193): FrameMarkers::onResume
11-06 16:35:13.356: D/DEBUG--(9193): FrameMarkers::onPause
11-06 16:35:13.360: D/DEBUG---(9193): FrameMarkers::onDestroy
11-06 16:35:13.360: D/QCAR(9193): Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkers_deinitApplicationNative
11-06 16:35:13.360: D/QCAR(9193): Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkers_deinitTracker
11-06 16:35:13.360: E/AR(9193): Failed to register callback because the given camera is invalid.
11-06 16:35:13.481: D/dalvikvm(9193): GC_EXPLICIT freed 1206 objects / 83712 bytes in 119ms
11-06 16:35:13.485: D/DEBUG---(9193): FrameMarkers::onCreate
11-06 16:35:13.500: D/DEBUG---(9193): FrameMarkers::onResume
11-06 16:35:13.504: D/skia(9193): purging 6K from font cache [1 entries]
11-06 16:35:13.504: D/SKIA_FONT(9193): stored typeface in slot 0
11-06 16:35:13.504: D/SKIA_FONT(9193): SKIA_FONT fontfile: /data/data/com.android.settings/app_fonts/default/DroidSans.ttf
11-06 16:35:13.516: D/SKIA_FONT(9193): SKIA_FONT fontfile: /data/data/com.android.settings/app_fonts/default/DroidSans.ttf
11-06 16:35:13.516: D/SKIA_FONT(9193): load_system_fonts(), name = Droid Sans, style = 0, uniqueID = 13
11-06 16:35:13.516: D/SKIA_FONT(9193): SKIA_FONT fontfile: /data/data/com.android.settings/app_fonts/default/DroidSans-Bold.ttf
11-06 16:35:13.520: D/SKIA_FONT(9193): SKIA_FONT fontfile: /data/data/com.android.settings/app_fonts/default/DroidSans-Bold.ttf
11-06 16:35:13.520: D/SKIA_FONT(9193): load_system_fonts(), name = Droid Sans, style = 1, uniqueID = 14
11-06 16:35:13.539: D/SKIA_FONT(9193): load_system_fonts(), name = Droid Serif, style = 0, uniqueID = 15
11-06 16:35:13.563: D/SKIA_FONT(9193): load_system_fonts(), name = Droid Serif, style = 1, uniqueID = 16
11-06 16:35:13.578: D/SKIA_FONT(9193): load_system_fonts(), name = Droid Serif, style = 2, uniqueID = 17
11-06 16:35:13.590: D/SKIA_FONT(9193): load_system_fonts(), name = Droid Serif, style = 3, uniqueID = 18
11-06 16:35:13.610: D/SKIA_FONT(9193): load_system_fonts(), name = Droid Sans Mono, style = 0, uniqueID = 19
11-06 16:35:13.610: D/SKIA_FONT(9193): load_system_fonts(), name = Droid Sans Arabic, style = 0, uniqueID = 20
11-06 16:35:13.610: D/SKIA_FONT(9193): load_system_fonts(), name = Droid Sans Hebrew, style = 0, uniqueID = 21
11-06 16:35:13.610: D/SKIA_FONT(9193): load_system_fonts(), name = Droid Sans Thai, style = 0, uniqueID = 22
11-06 16:35:13.614: D/SKIA_FONT(9193): load_system_fonts(), name = Droid Sans, style = 0, uniqueID = 23
11-06 16:35:13.621: D/SKIA_FONT(9193): load_system_fonts(), name = Droid Sans Fallback, style = 0, uniqueID = 24
11-06 16:35:13.621: D/SKIA_FONT(9193): load_system_fonts(), oldSansUID = 1, newSansUID = 13
11-06 16:35:13.621: D/SKIA_FONT(9193): load_system_fonts(), oldSansBoldUID = 2, newSansBoldUID = 14
11-06 16:35:14.489: I/AR(9193): QCAR has been initialized successfully
11-06 16:35:14.489: I/AR(9193): QCAR SDK version 1.5.9
11-06 16:35:14.493: I/AR(9193): QCAR has already been initialized
11-06 16:35:14.493: I/AR(9193): QCAR SDK version 1.5.9
11-06 16:35:14.707: D/InitQCARTask::onPostExecute: QCAR initialization(9193):  successful
11-06 16:35:14.707: D/QCAR(9193): Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkers_initTracker
11-06 16:35:14.707: D/QCAR(9193): Successfully initialized MarkerTracker.
11-06 16:35:14.707: I/AR(9193): Creating FrameID marker detector
11-06 16:35:14.707: D/QCAR(9193): Successfully created frame markers.
11-06 16:35:14.735: D/dalvikvm(9193): GC_EXPLICIT freed 481 objects / 28000 bytes in 20ms
11-06 16:35:15.497: D/QCAR(9193): Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkers_startCamera
11-06 16:35:15.653: D/dalvikvm(9193): GC_EXPLICIT freed 1721 objects / 101144 bytes in 24ms
11-06 16:35:17.129: I/AR(9193): Setting the torch mode not supported
11-06 16:35:17.129: D/QCAR(9193): Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkers_setProjectionMatrix
11-06 16:35:17.250: D/libEGL(9193): loaded /system/lib/egl/libEGL_POWERVR_SGX540_120.so
11-06 16:35:17.262: D/libEGL(9193): loaded /system/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
11-06 16:35:17.270: D/libEGL(9193): loaded /system/lib/egl/libGLESv2_POWERVR_SGX540_120.so
11-06 16:35:17.399: D/DEBUG---(9193): OnSurfaceCreated
11-06 16:35:17.399: D/QCAR(9193): Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkersRenderer_initRendering
11-06 16:35:17.399: D/MAIN_Render(9193): In onSurfaceChanged
11-06 16:35:17.399: D/QCAR(9193): Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkersRenderer_updateRendering
11-06 16:35:17.399: D/QCAR(9193): Configure Video Background : Video (320,240), Screen (800,404), mSize (800,600)
11-06 16:35:17.399: D/QCAR(9193): Rendering ---------------

 

Could not find method android.hardware.Camera.getNumberOfCameras

November 9, 2012 - 5:29am #6

Hi, if you setup correctly JNI (as you say),

then the problem must be with the fact that getNumberOfCameras() function belongs to API level 9, i.e. Android 2.3,

while your device is on Android 2.2, so it does not support that functions;

so, please adjust your AndroidManifest.xml so that BOTH the minSDK and the targetSDK are set to API level 8 (i.e. Android 2.2), by including this:

 

   <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>

 

Also, if that alone does not solve it,

add the following as well (front camera NOT required):

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
<uses-permission android:name="android.permission.CAMERA" />

 

And, finally, make sure your project target is also android level 8:

in project.properties:

target=android-8

 

Hopefully that should fix it.

Could not find method android.hardware.Camera.getNumberOfCameras

November 8, 2012 - 8:53pm #5

Hi,

Thank you for the nice help.

I already implemented that, if not I will get like "xyz function implementation is not found" error.

I am able to execute the final APK in my android device and getting desired output also. But when I first started/exported as Android Applicaiton then I am getting this error.

I ma using Android2.2 in my Samsung GTI9000 Device.

Can you please help me why am I geeting this error.

Thanks and Regards

Wizards2020.

Could not find method android.hardware.Camera.getNumberOfCameras

November 7, 2012 - 4:08am #4

As you say, you changed the package name and some file names;

this will impact the native JNI C++ code (which is in the JNI directory); in fact, the function names defined in C++ (in JNI) must reflect the package and class names where the Java methods belong;

for instance, consider the method startCamera() declared in FrameMarkers.java; the method in Java is declared as follows:

   private void native startCamera(); 

Then, if you now look at the native (C++) code in FrameMarkers.cpp, you will find the actual definition of the startCamera() method, which is:

JNIEXPORT

void JNICALL  Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkers_startCamera(JNIEnv *, jobject) { ... }

As you can see, the function name above contains the following sequence:

"com_qualcomm_QCARSamples_FrameMarkers_FrameMarkers"

which corresponds to the fully qualified name of the FrameMarkers class (where the method is declared), i.e.:

package name (com.qualcomm.QCARSamples.FrameMarkers)  +  class name (FrameMarkers) =

com.qualcomm.QCARSamples.FrameMarkers.FrameMarkers

Just replacing the dots (".") with underscores ("_") gives you the function name com_qualcomm_QCARSamples_FrameMarkers_FrameMarkers

So, you need to update the JNI C++ code to reflect your modified package name and class names.

That should fix the problem (and do not forget to rebuild with ndk-build after changing the code)

 

 

 

 

Could not find method android.hardware.Camera.getNumberOfCameras

November 7, 2012 - 3:52am #3

Hi ,

Thank you very much for the help.

I did not observed till now that the same error is coming for "FrameMarkers" sample also.

I did another example exactly as FrameMarkers except that the package and file names are different.

Now I am able to activate camera and getting camera as backgroud for AR project.

But still I am getting the same error for both the exampels (FrameMarkers example and my example ) when I export as "Android Application".

My device is Samsung GTI9000 and using Android2.2

Can you please help me why am i getting this error.

 

Could not find method android.hardware.Camera.getNumberOfCameras

November 6, 2012 - 6:57am #2

Hi,

have you added all of the following permissions (not just the camera one):

  • android.permission.ACCESS_NETWORK_STATE

  • android.permission.ACCESS_WIFI_STATE

  • android.permission.CAMERA

  • android.permission.INTERNET

  • android.permission.READ_PHONE_STATE

    Also, check for any difference between your AndroidManifest.xml (e.g. things like minSDK, targetSDK, etc.) and the sample manifest, as well as for differences between your Android.mk file and the sample one.

Log in or register to post comments