Android Question NoSuchMethodException: getPreviewSize

sangee

Member
Licensed User
Longtime User
Hello All..

I am making an app which takes photos every 5 second once and saves in the SD card. It works. But I have started to notice that the photos dont get saved when I reboot the phone some times and fails with the error like below ..

java.lang.NoSuchMethodException: getPreviewSize []
java.lang.NullPointerException
java.lang.RuntimeException: Error loading bitmap.

I could trace the error to the function below ...speciellay in the line
size = r.RunMethod("getPreviewSize"). Can anyone guide me on what could have gone wrong? This was working perfectly in Android 2.2.3 and now I am on Android 4.2.2 and I upgraded the SDK for getting here.. Is there way to avoid calling that method and fix the preview size to 320 x 240 by default? Need help please...

B4X:
Public Sub PreviewImageToJpeg(data() As Byte, quality As Int) As Byte()
Try   
    Dim size, previewFormat As Object
    r.target = parameters
    size = r.RunMethod("getPreviewSize")
    previewFormat = r.RunMethod("getPreviewFormat")
    r.target = size
    Dim width = r.GetField("width"), height = r.GetField("height") As Int
    Dim yuvImage As Object = r.CreateObject2("android.graphics.YuvImage", _
        Array As Object(data, previewFormat, width, height, Null), _
        Array As String("[B", "java.lang.int", "java.lang.int", "java.lang.int", "[I"))
    r.target = yuvImage
    Dim rect1 As Rect
    rect1.Initialize(0, 0, r.RunMethod("getWidth"), r.RunMethod("getHeight"))
    Dim out As OutputStream
    out.InitializeToBytesArray(100)
    r.RunMethod4("compressToJpeg", Array As Object(rect1, quality, out), _
        Array As String("android.graphics.Rect", "java.lang.int", "java.io.OutputStream"))
    Return out.ToBytesArray
Catch
Log(LastException.Message)
    Return
End Try

End Sub
 

sangee

Member
Licensed User
Longtime User
Erel, Can you please help me with the code to set the width and height directly with out running the method. I am really stuck on this and tried to set it directly with out success. (Got only green garbled frames).
 
Upvote 0

sangee

Member
Licensed User
Longtime User
B4X:
    Dim size, previewFormat As Object
    r.target = parameters
    size = r.RunMethod("getPreviewSize")

Dont know how to do this... searched the forums but to no luck... little help would be very useful...
 
Upvote 0

sangee

Member
Licensed User
Longtime User
Erel .. anyone need help in this please.. i am not able to set the default preview size instead of querying which seems to give away errors some times... help please....

This method is not working

B4X:
    'cameraInfo = r.CreateObject("android.hardware.Camera$CameraInfo")
    'size = r.CreateObject("android.hardware.Camera$Size")
 
Last edited:
Upvote 0

sangee

Member
Licensed User
Longtime User
Thanks Erel. I still get the error

java.lang.RuntimeException: Error loading bitmap.
java.lang.NoSuchMethodException: getPreviewSize
java.lang.NullPointerException

When I recompile and push the app to the phone it works. When I restart the phone I get the above error and the images dont get saved to SD card.
 
Upvote 0

sangee

Member
Licensed User
Longtime User
LogCat connected to: 0123456789ABCDEF
--------- beginning of /dev/log/system


BDC-RECEIVER handled : 0 / ReceiverData{intent=Intent { act=com.google.android.checkin.CHECKIN_COMPLETE flg=0x10 cmp=com.google.android.gsf/.settings.GoogleLocationSettings$LocationSettingsChangedListener } packageName=com.google.android.gsf resultCode=-1 resultData=null resultExtras=null}
Death received in com.android.server.am.ActivityManagerService$AppDeathRecipient@427ca680 for thread android.os.BinderProxy@4278efe0
Start proc com.android.calendar for broadcast com.android.calendar/.widget.CalendarAppWidgetProvider: pid=2042 uid=10005 gids={50005, 3003, 1028}
Process com.google.android.gsf.login (pid 1943) has died.
MAIN-ARGS launch log: false, user build: false, booted: true, looper log: false
getContentProviderImpl: name=com.google.android.gsf.gservices, userId=0
getProviderByName: com.google.android.gsf.gservices , callingUid = 10052
getContentProviderImpl: Caller Process Info:(caller= [email protected]=10052r.userId=0r.processName=com.google.android.talk)
getContentProviderImpl: ContentProviderRecord cpr:(, cpr.uid=10023, cpr.name=ComponentInfo{com.google.android.gsf/com.google.android.gsf.gservices.GservicesProvider}, cpr.noReleaseNeeded=false) Provider Info:(, cpi.authority=com.google.android.gsf.gservices, cpi.multiprocess=false, cpi.readPermission=com.google.android.providers.gsf.permission.READ_GSERVICES, cpi.readPermission=com.google.android.providers.gsf.permission.WRITE_GSERVICES) Provider App Info:(, cpr.appInfo=com.google.android.gsf.gservices, cpi.multiprocess=false, cpi.readPermission=com.google.android.providers.gsf.permission.READ_GSERVICES, cpi.readPermission=com.google.android.providers.gsf.permission.WRITE_GSERVICES)
canRunHere: bCanRunHere=falseinfo.multiprocess=falseinfo.processName=com.google.process.gappsapp.processName=com.google.android.talkuid=10023app.info.uid10052
installProvider: context=android.app.ContextImpl@421a0458holder=android.app.IActivityManager$ContentProviderHolder@421bf0c8noisy=truenoReleaseNeeded=falsestable=false
ACT-attachApplication pid 2042 to thread android.app.ApplicationThreadProxy@42597170
Binding process pid 2042 to record ProcessRecord{426af000 2042:com.android.calendar/u0a10005}
New death recipient com.android.server.am.ActivityManagerService$AppDeathRecipient@426a5bc0 for thread android.os.BinderProxy@4271cad8
getProviderByClass: ComponentInfo{com.android.calendar/com.android.calendar.CalendarRecentSuggestionsProvider}, callingUid = 1000
putProviderByClass: ComponentInfo{com.android.calendar/com.android.calendar.CalendarRecentSuggestionsProvider} , callingUid = 1000, record uid = 10005
New app record ProcessRecord{426af000 2042:com.android.calendar/u0a10005} thread=android.os.BinderProxy@4271cad8 pid=2042
BDC-Delivered broadcast: Intent { act=com.android.calendar.APPWIDGET_UPDATE flg=0x10 cmp=com.android.calendar/.widget.CalendarAppWidgetProvider }, ordered=true, app=ProcessRecord{426af000 2042:com.android.calendar/u0a10005}, receiver=android.os.BinderProxy@4271cad8
installProvider: context=com.android.calendar.CalendarApplication@421a0d20holder=nullnoisy=falsenoReleaseNeeded=truestable=true
installProvider: context.getPackageName()=com.android.calendarai.packageName=com.android.calendar
putProviderByClass: ComponentInfo{com.android.calendar/com.android.calendar.CalendarRecentSuggestionsProvider} , callingUid = 1000, record uid = 10005
putProviderByName: com.android.calendar.CalendarRecentSuggestionsProvider , callingUid = 1000, record uid = 10005
getContentProviderImpl: name=media, userId=0
getProviderByName: media , callingUid = 10052
getContentProviderImpl: Caller Process Info:(caller= [email protected]=10052r.userId=0r.processName=com.google.android.talk)
getContentProviderImpl: ContentProviderRecord cpr:(, cpr.uid=10012, cpr.name=ComponentInfo{com.android.providers.media/com.android.providers.media.MediaProvider}, cpr.noReleaseNeeded=false) Provider Info:(, cpi.authority=media, cpi.multiprocess=false, cpi.readPermission=null, cpi.readPermission=null) Provider App Info:(, cpr.appInfo=media, cpi.multiprocess=false, cpi.readPermission=null, cpi.readPermission=null)


canRunHere: bCanRunHere=falseinfo.multiprocess=falseinfo.processName=android.process.mediaapp.processName=com.google.android.talkuid=10012app.info.uid10052
installProvider: context=android.app.ContextImpl@421a0458holder=android.app.IActivityManager$ContentProviderHolder@421ba728noisy=truenoReleaseNeeded=falsestable=false
BIND_APPLICATION handled : 0 / AppBindData{appInfo=ApplicationInfo{42197368 com.android.calendar}}
BDC-Calling onReceive: intent=Intent { act=com.android.calendar.APPWIDGET_UPDATE flg=0x10 cmp=com.android.calendar/.widget.CalendarAppWidgetProvider }, ordered=true, receiver=com.android.calendar.widget.CalendarAppWidgetProvider@421c17d0
BDC-RECEIVER handled : 0 / ReceiverData{intent=Intent { act=com.android.calendar.APPWIDGET_UPDATE flg=0x10 cmp=com.android.calendar/.widget.CalendarAppWidgetProvider } packageName=com.android.calendar resultCode=-1 resultData=null resultExtras=null}
BDC-Finishing receiver: android.os.BinderProxy@4271cad8
BDC-Delivered broadcast: Intent { act=android.intent.action.PROVIDER_CHANGED dat=content://com.android.calendar flg=0x10 cmp=com.android.calendar/.alerts.AlertReceiver }, ordered=true, app=ProcessRecord{426af000 2042:com.android.calendar/u0a10005}, receiver=android.os.BinderProxy@4271cad8
getContentProviderImpl: name=com.google.android.gsf.gservices, userId=0
getProviderByName: com.google.android.gsf.gservices , callingUid = 10052
getContentProviderImpl: Caller Process Info:(caller= [email protected]=10052r.userId=0r.processName=com.google.android.talk)
getContentProviderImpl: ContentProviderRecord cpr:(, cpr.uid=10023, cpr.name=ComponentInfo{com.google.android.gsf/com.google.android.gsf.gservices.GservicesProvider}, cpr.noReleaseNeeded=false) Provider Info:(, cpi.authority=com.google.android.gsf.gservices, cpi.multiprocess=false, cpi.readPermission=com.google.android.providers.gsf.permission.READ_GSERVICES, cpi.readPermission=com.google.android.providers.gsf.permission.WRITE_GSERVICES) Provider App Info:(, cpr.appInfo=com.google.android.gsf.gservices, cpi.multiprocess=false, cpi.readPermission=com.google.android.providers.gsf.permission.READ_GSERVICES, cpi.readPermission=com.google.android.providers.gsf.permission.WRITE_GSERVICES)
canRunHere: bCanRunHere=falseinfo.multiprocess=falseinfo.processName=com.google.process.gappsapp.processName=com.google.android.talkuid=10023app.info.uid10052
installProvider: context=android.app.ContextImpl@421a0458holder=android.app.IActivityManager$ContentProviderHolder@421dde58noisy=truenoReleaseNeeded=falsestable=false
getContentProviderImpl: name=com.google.android.providers.talk, userId=0
getProviderByName: com.google.android.providers.talk , callingUid = 10052
getContentProviderImpl: Caller Process Info:(caller= [email protected]=10052r.userId=0r.processName=com.google.android.talk)
getContentProviderImpl: ContentProviderRecord cpr:(, cpr.uid=10023, cpr.name=ComponentInfo{com.google.android.gsf/com.google.android.gsf.talk.TalkProvider}, cpr.noReleaseNeeded=false) Provider Info:(, cpi.authority=com.google.android.providers.talk, cpi.multiprocess=false, cpi.readPermission=com.google.android.providers.talk.permission.READ_ONLY, cpi.readPermission=com.google.android.providers.talk.permission.WRITE_ONLY) Provider App Info:(, cpr.appInfo=com.google.android.providers.talk, cpi.multiprocess=false, cpi.readPermission=com.google.android.providers.talk.permission.READ_ONLY, cpi.readPermission=com.google.android.providers.talk.permission.WRITE_ONLY)
canRunHere: bCanRunHere=falseinfo.multiprocess=falseinfo.processName=com.google.process.gappsapp.processName=com.google.android.talkuid=10023app.info.uid10052
installProvider: context=android.app.ContextImpl@421a0458holder=android.app.IActivityManager$ContentProviderHolder@421d39e0noisy=truenoReleaseNeeded=falsestable=false
BDC-Calling onReceive: intent=Intent { act=android.intent.action.PROVIDER_CHANGED dat=content://com.android.calendar flg=0x10 cmp=com.android.calendar/.alerts.AlertReceiver }, ordered=true, receiver=com.android.calendar.alerts.AlertReceiver@421be8d8
acquireWakeLockInternal: lock=1115349208, flags=0x1, tag="StartingAlertService", ws=null, uid=10005, pid=2042
updateWakeLockSummaryLocked: mWakefulness=Awake, mWakeLockSummary=0x23
newScreenState = 2
requestPowerState: screenState=2, useProximitySensor=false, screenBrightness=255, screenAutoBrightnessAdjustment=0.0, useAutoBrightness=false, useEcoBrightness=false, blockScreenOn=false, waitForNegativeProximity=false
requestPowerState: hct517


requestPowerState: hct528
requestPowerState: hct544
requestPowerState: hct550
requestPowerState: hct560 mDisplayReadyLocked = true
setBrightness mButtonLight 0.
updateScreenStateLocked: mDisplayReady=true, newScreenState=2, mWakefulness=1, mWakeLockSummary=0x23, mUserActivitySummary=0x1, mBootCompleted=true
handleSandman: canDream=false, mWakefulness=Awake
SVC-Sent arguments: ServiceRecord{427842b8 u0 com.android.calendar/.alerts.AlertService}, app=ProcessRecord{426af000 2042:com.android.calendar/u0a10005}, args=Intent { cmp=com.android.calendar/.alerts.AlertService (has extras) }, flags=0
BDC-RECEIVER handled : 0 / ReceiverData{intent=Intent { act=android.intent.action.PROVIDER_CHANGED dat=content://com.android.calendar flg=0x10 cmp=com.android.calendar/.alerts.AlertReceiver } packageName=com.android.calendar resultCode=-1 resultData=null resultExtras=null}
BDC-Finishing receiver: android.os.BinderProxy@4271cad8
SVC-Creating service: CreateServiceData{token=android.os.BinderProxy@421b36f0 className=com.android.calendar.alerts.AlertService packageName=com.android.calendar intent=null}
BDC-Delivered broadcast: Intent { act=android.intent.action.PROVIDER_CHANGED dat=content://com.android.calendar flg=0x10 cmp=com.android.calendar/.widget.CalendarAppWidgetService$CalendarFactory }, ordered=true, app=ProcessRecord{426af000 2042:com.android.calendar/u0a10005}, receiver=android.os.BinderProxy@4271cad8
SVC-CREATE_SERVICE handled : 0 / CreateServiceData{token=android.os.BinderProxy@421b36f0 className=com.android.calendar.alerts.AlertService packageName=com.android.calendar intent=null}
SVC-Executing service done: ServiceRecord{427842b8 u0 com.android.calendar/.alerts.AlertService}, type=0, startId=0, res=0
SVC-Executing service done: ServiceRecord{427842b8 u0 com.android.calendar/.alerts.AlertService}, type=1, startId=1, res=3
SVC-SERVICE_ARGS handled : 0 / ServiceArgsData{token=android.os.BinderProxy@421b36f0 startId=1 args=Intent { cmp=com.android.calendar/.alerts.AlertService (has extras) }}
BDC-Calling onReceive: intent=Intent { act=android.intent.action.PROVIDER_CHANGED dat=content://com.android.calendar flg=0x10 cmp=com.android.calendar/.widget.CalendarAppWidgetService$CalendarFactory }, ordered=true, receiver=com.android.calendar.widget.CalendarAppWidgetService$CalendarFactory@42197eb0
BDC-RECEIVER handled : 0 / ReceiverData{intent=Intent { act=android.intent.action.PROVIDER_CHANGED dat=content://com.android.calendar flg=0x10 cmp=com.android.calendar/.widget.CalendarAppWidgetService$CalendarFactory } packageName=com.android.calendar resultCode=0 resultData=null resultExtras=null}
getContentProviderImpl: name=com.android.calendar, userId=0
getProviderByName: com.android.calendar , callingUid = 10005
getContentProviderImpl: Caller Process Info:(caller= [email protected]=10005r.userId=0r.processName=com.android.calendar)
getContentProviderImpl: ContentProviderRecord cpr:(, cpr.uid=10007, cpr.name=ComponentInfo{com.android.providers.calendar/com.android.providers.calendar.CalendarProvider2}, cpr.noReleaseNeeded=false) Provider Info:(, cpi.authority=com.android.calendar, cpi.multiprocess=false, cpi.readPermission=android.permission.READ_CALENDAR, cpi.readPermission=android.permission.WRITE_CALENDAR) Provider App Info:(, cpr.appInfo=com.android.calendar, cpi.multiprocess=false, cpi.readPermission=android.permission.READ_CALENDAR, cpi.readPermission=android.permission.WRITE_CALENDAR)
canRunHere: bCanRunHere=falseinfo.multiprocess=falseinfo.processName=com.android.providers.calendarapp.processName=com.android.calendaruid=10007app.info.uid10005
getContentProviderImpl: updateLruProcessLocked cpr.proc=ProcessRecord{425a2a48 1971:com.android.providers.calendar/u0a10007}
installProvider: context=android.app.ContextImpl@421c3040holder=android.app.IActivityManager$ContentProviderHolder@421b3a98noisy=truenoReleaseNeeded=falsestable=false
BDC-Finishing receiver: android.os.BinderProxy@4271cad8
Start proc com.android.deskclock for broadcast com.android.deskclock/.CommonBroadcastReceiver: pid=2066 uid=10010 gids={50010, 1015, 1028}


getContentProviderImpl: name=com.android.calendar, userId=0
getProviderByName: com.android.calendar , callingUid = 10005
getContentProviderImpl: Caller Process Info:(caller= [email protected]=10005r.userId=0r.processName=com.android.calendar)
getContentProviderImpl: ContentProviderRecord cpr:(, cpr.uid=10007, cpr.name=ComponentInfo{com.android.providers.calendar/com.android.providers.calendar.CalendarProvider2}, cpr.noReleaseNeeded=false) Provider Info:(, cpi.authority=com.android.calendar, cpi.multiprocess=false, cpi.readPermission=android.permission.READ_CALENDAR, cpi.readPermission=android.permission.WRITE_CALENDAR) Provider App Info:(, cpr.appInfo=com.android.calendar, cpi.multiprocess=false, cpi.readPermission=android.permission.READ_CALENDAR, cpi.readPermission=android.permission.WRITE_CALENDAR)
canRunHere: bCanRunHere=falseinfo.multiprocess=falseinfo.processName=com.android.providers.calendarapp.processName=com.android.calendaruid=10007app.info.uid10005
installProvider: context=android.app.ContextImpl@421a0910holder=android.app.IActivityManager$ContentProviderHolder@421b58b8noisy=truenoReleaseNeeded=falsestable=false
Death received in com.android.server.am.ActivityManagerService$AppDeathRecipient@4261fd28 for thread android.os.BinderProxy@427c1ac0
Process com.google.android.googlequicksearchbox (pid 1929) has died.
Removing from providersByClass name=ComponentInfo{com.google.android.googlequicksearchbox/com.google.android.searchcommon.google.GoogleSuggestionProvider} user=0
Removing from providersByName name=com.google.android.googlequicksearchbox.google user=0
Removing from providersByClass name=ComponentInfo{com.google.android.googlequicksearchbox/com.google.android.speech.audio.AudioProvider} user=0
Removing from providersByName name=com.google.android.googlequicksearchbox.AudioProvider user=0
Removing from providersByClass name=ComponentInfo{com.google.android.googlequicksearchbox/com.google.android.velvet.gallery.ImageProvider} user=0
Removing from providersByName name=com.google.android.velvet.gallery.ImageProvider user=0
MAIN-ARGS launch log: false, user build: false, booted: true, looper log: false
ACT-attachApplication pid 2066 to thread android.app.ApplicationThreadProxy@425678b8
Binding process pid 2066 to record ProcessRecord{425d06a0 2066:com.android.deskclock/u0a10010}
New death recipient com.android.server.am.ActivityManagerService$AppDeathRecipient@4269a868 for thread android.os.BinderProxy@427aab68
getProviderByClass: ComponentInfo{com.android.deskclock/com.android.deskclock.AlarmProvider}, callingUid = 1000
putProviderByClass: ComponentInfo{com.android.deskclock/com.android.deskclock.AlarmProvider} , callingUid = 1000, record uid = 10010
New app record ProcessRecord{425d06a0 2066:com.android.deskclock/u0a10010} thread=android.os.BinderProxy@427aab68 pid=2066
BDC-Delivered broadcast: Intent { act=android.intent.action.MEDIA_SCANNER_FINISHED dat=file:///system/media flg=0x10 cmp=com.android.deskclock/.CommonBroadcastReceiver }, ordered=true, app=ProcessRecord{425d06a0 2066:com.android.deskclock/u0a10010}, receiver=android.os.BinderProxy@427aab68
getContentProviderImpl: name=com.google.android.providers.talk, userId=0
getProviderByName: com.google.android.providers.talk , callingUid = 10052
getContentProviderImpl: Caller Process Info:(caller= [email protected]=10052r.userId=0r.processName=com.google.android.talk)
getContentProviderImpl: ContentProviderRecord cpr:(, cpr.uid=10023, cpr.name=ComponentInfo{com.google.android.gsf/com.google.android.gsf.talk.TalkProvider}, cpr.noReleaseNeeded=false) Provider Info:(, cpi.authority=com.google.android.providers.talk, cpi.multiprocess=false, cpi.readPermission=com.google.android.providers.talk.permission.READ_ONLY, cpi.readPermission=com.google.android.providers.talk.permission.WRITE_ONLY) Provider App Info:(, cpr.appInfo=com.google.android.providers.talk, cpi.multiprocess=false, cpi.readPermission=com.google.android.providers.talk.permission.READ_ONLY, cpi.readPermission=com.google.android.providers.talk.permission.WRITE_ONLY)
 
Upvote 0

sangee

Member
Licensed User
Longtime User
Hi Erel.. Looks like i didnt copy properly. The attached text file is the log export. Thanks for looking in to this... :)
 

Attachments

  • Error_Log.txt
    295.5 KB · Views: 157
Upvote 0
Top