Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unfortunately App has stopped (crashed) #367

Closed
abdelwehed opened this issue Oct 24, 2016 · 5 comments
Closed

Unfortunately App has stopped (crashed) #367

abdelwehed opened this issue Oct 24, 2016 · 5 comments

Comments

@abdelwehed
Copy link

Hello everyone,
i had installed and implemented the react-native-image-picker correctly, but when testing it on the emulator or the device the app crashes badly and i get this error "Unfortunately app has stopped".

I'm using react native v0.31 / RN-image-picker latest version 0.22.10 / testing device (android 5), emulator (android 7).

Here is the settings.gradle:
`ootProject.name = 'NativeStarterKit'

include ':app'
include ':react-native-datetime'
project(':react-native-datetime').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-datetime/android')
include ':react-native-contacts'
project(':react-native-contacts').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-contacts/android')
include ':cordovaplugin'
project(':cordovaplugin').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cordova-plugin/framework/android')
include ':react-native-datetime-picker'
project(':react-native-datetime-picker').projectDir = new File(rootProject.projectDir, '../node_modules/@remobile/react-native-datetime-picker/android')
include ':react-native-vector-icons'
project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android')
include ':react-native-splash-screen'
project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android')
include ':react-native-spinkit'
project(':react-native-spinkit').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-spinkit/android')
include ':react-native-image-picker'
project(':react-native-image-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-picker/android')
include ':react-native-fetch-blob'
project(':react-native-fetch-blob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fetch-blob/android')`

Here is the manifest file:
`

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />




<uses-permission android:name="android.permission.CAMERA" />

<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="22" />

<application
    android:name=".MainApplication"
  android:allowBackup="true"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:theme="@style/AppTheme"
    >
  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
    </intent-filter>
  </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" /><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
 App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information. -->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
</application>
` and finally this is how i implemented this plugin inside mycode:

<Button style={{height:75, marginTop:50, marginLeft:40, width:75, borderRadius: 100/2}} onPress={() => this.launchCamera()}> <Icon name='camera' size={45} style={{color:'white'}}/> </Button>

` launchCamera() {

      ImagePicker.launchCamera(options, (response)  => {

     console.log('Response = ', response);

        if (response.didCancel) {
          console.log('User cancelled image picker');
        }
        else if (response.error) {
          console.log('ImagePicker Error: ', response.error);
        }
        else if (response.customButton) {
          console.log('User tapped custom button: ', response.customButton);
        }
        else {
          // You can display the image using either data...
          const source = {uri: 'data:image/jpeg;base64,' + response.data, isStatic: true};

          // or a reference to the platform specific asset location
          if (Platform.OS === 'ios') {
            const source = {uri: response.uri.replace('file://', ''), isStatic: true};
          } else {
            const source = {uri: response.uri, isStatic: true};
          }
             this.setState({
              image: source
            });

    }

    });
 }

 launchFromLibrary() {

    ImagePicker.launchImageLibrary(options, (response)  => {

            console.log('Response = ', response);

                  if (response.didCancel) {
                    console.log('User cancelled image picker');
                  }
                  else if (response.error) {
                    console.log('ImagePicker Error: ', response.error);
                  }
                  else if (response.customButton) {
                    console.log('User tapped custom button: ', response.customButton);
                  }
                  else {
                    // You can display the image using either data...
                    const source = {uri: 'data:image/jpeg;base64,' + response.data, isStatic: true};

                    // or a reference to the platform specific asset location
                    if (Platform.OS === 'ios') {
                      const source = {uri: response.uri.replace('file://', ''), isStatic: true};
                    } else {
                      const source = {uri: response.uri, isStatic: true};
            this.state.FileUri = source.uri;
                    }
                         this.setState({
                          image: source
                        });

            }

    });
 }`
@yfuks
Copy link
Contributor

yfuks commented Oct 24, 2016

Can you put your stack trace ? adb logcat

@abdelwehed
Copy link
Author

this is the stack trace from logcat when i clicked the button that launches the camera:

10-23 19:45:29.315 1477-1489/system_process I/ActivityManager: START u0 {act=android.media.action.IMAGE_CAPTURE flg=0x3 cmp=com.android.camera/.Camera clip={text/uri-list U:file:///storage/emulated/0/Pictures/image-0d228c2e-f13d-4863-88be-2b1929e6d233.jpg} (has extras)} from uid 10090 on display 0

                                                           --------- beginning of main

10-23 19:45:29.523 2322-2322/com.android.camera V/camera: Preferred camera (id= 0) missing. Defaulting to the first one
10-23 19:45:29.528 2322-8945/com.android.camera V/CameraHolder: open camera 0
10-23 19:45:29.529 1227-1227/? I/CameraService: CameraService::connect call (PID -1 "com.android.camera", camera ID 0) for HAL version default and Camera API version 1
10-23 19:45:29.529 1227-1227/? E/CameraService: CameraService::connect X (PID 2322) rejected (invalid camera ID 0)
10-23 19:45:29.534 2322-8945/com.android.camera W/CameraBase: An error occurred while connecting to camera 0: Service not available
10-23 19:45:29.534 2322-8945/com.android.camera E/CameraHolder: fail to connect Camera
java.lang.RuntimeException: Fail to connect to camera service
at android.hardware.Camera.(Camera.java:496)
at android.hardware.Camera.open(Camera.java:345)
at com.android.camera.CameraHolder.open(CameraHolder.java:131)
at com.android.camera.Util.openCamera(Util.java:267)
at com.android.camera.Camera$3.run(Camera.java:1114)
at java.lang.Thread.run(Thread.java:761)
10-23 19:45:29.539 1477-1487/system_process I/art: Background sticky concurrent mark sweep GC freed 29334(2MB) AllocSpace objects, 3(136KB) LOS objects, 18% free, 12MB/15MB, paused 286us total 140.558ms
10-23 19:45:30.529 2322-2322/com.android.camera I/Choreographer: Skipped 30 frames! The application may be doing too much work on its main thread.
10-23 19:45:30.635 2322-2322/com.android.camera V/camera: surfaceChanged. w=1440. h=1920
10-23 19:45:30.712 1477-1498/system_process I/ActivityManager: Displayed com.android.camera/.Camera: +1s315ms
10-23 19:45:31.719 1477-1489/system_process I/WindowManager: Destroying surface Surface(name=com.nativestarterkit/com.nativestarterkit.MainActivity) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.AppWindowToken.notifyAppStopped:389 com.android.server.wm.WindowManagerService.notifyAppStopped:4456 com.android.server.am.ActivityStack.activityStoppedLocked:1252 com.android.server.am.ActivityManagerService.activityStopped:6873
10-23 19:45:32.439 1477-1544/system_process E/TaskPersister: File error accessing recents directory (directory doesn't exist?).
10-23 19:45:36.533 1226-1251/? D/AudioFlinger: mixer(0xabf03640) throttle end: throttle time(11)
10-23 19:45:36.538 1477-2464/system_process I/WindowManager: Destroying surface logcatSurface(name=com.android.camera/com.android.camera.Camera) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1449 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2478 com.android.server.wm.WindowManagerService.removeWindowLocked:2436 com.android.server.wm.WindowManagerService.removeWindowLocked:2305 com.android.server.wm.WindowManagerService.removeWindow:2300 com.android.server.wm.Session.remove:193
10-23 19:45:36.544 1226-1251/? D/AudioFlinger: mixer(0xabf03640) throttle end: throttle time(11)
10-23 19:45:36.555 1226-1251/? D/AudioFlinger: mixer(0xabf03640) throttle end: throttle time(11)
10-23 19:45:36.689 19136-19136/com.nativestarterkit D/AndroidRuntime: Shutting down VM

                                                                  --------- beginning of crash

10-23 19:45:36.689 19136-19136/com.nativestarterkit E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.nativestarterkit, PID: 19136
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=13001, result=0, data=null} to activity {com.nativestarterkit/com.nativestarterkit.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void io.cordova.reactnative.CordovaPluginPackage.onActivityResult(int, int, android.content.Intent)' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:4053)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4096)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1516)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void io.cordova.reactnative.CordovaPluginPackage.onActivityResult(int, int, android.content.Intent)' on a null object reference
at com.nativestarterkit.MainActivity.onActivityResult(MainActivity.java:93)
at android.app.Activity.dispatchActivityResult(Activity.java:6917)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4049)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4096) 
at android.app.ActivityThread.-wrap20(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1516) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6077) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
10-23 19:45:36.689 19136-19162/com.nativestarterkit I/ReactNativeJS: 'Response = ', { didCancel: true }
10-23 19:45:36.782 1477-1838/system_process W/ActivityManager: Force finishing activity com.nativestarterkit/.MainActivity
10-23 19:45:37.332 1477-1491/system_process W/ActivityManager: Activity pause timeout for ActivityRecord{77f92ee u0 com.nativestarterkit/.MainActivity t128 f}
10-23 19:45:38.388 1477-1498/system_process W/art: Long monitor contention with owner Binder:1477_7 (2463) at int com.android.server.wm.WindowManagerService.relayoutWindow(com.android.server.wm.Session, android.view.IWindow, int, android.view.WindowManager$LayoutParams, int, int, int, int, android.graphics.Rect, android.graphics.Rect, android.graphics.Rect, android.graphics.Rect, android.graphics.Rect, android.graphics.Rect, android.graphics.Rect, android.content.res.Configuration, android.view.Surface)(WindowManagerService.java:2759) waiters=1 in void com.android.server.wm.WindowAnimator$1.doFrame(long) for 101ms
10-23 19:45:38.818 1477-1498/system_process I/WindowManager: Destroying surface Surface(name=SurfaceView - com.android.camera/com.android.camera.Camera) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.removeLocked:1449 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:2478 com.android.server.wm.AppWindowToken.destroySurfaces:365 com.android.server.wm.WindowStateAnimator.finishExit:565 com.android.server.wm.WindowStateAnimator.finishExit:516 com.android.server.wm.AppWindowAnimator.stepAnimationLocked:427
10-23 19:45:38.818 1477-1498/system_process I/WindowManager: Destroying surface Surface(name=com.android.camera/com.android.camera.Camera) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.WindowStateAnimator.finishExit:565 com.android.server.wm.AppWindowAnimator.stepAnimationLocked:427 com.android.server.wm.WindowAnimator.updateAppWindowsLocked:196 com.android.server.wm.WindowAnimator.animateLocked:678
10-23 19:45:42.028 1477-1544/system_process E/TaskPersister: File error accessing recents directory (directory doesn't exist?).

@yfuks
Copy link
Contributor

yfuks commented Oct 24, 2016

You have 2 errors
java.lang.RuntimeException: Fail to connect to camera service
and
io.cordova.reactnative.CordovaPluginPackage.onActivityResult(int, int, android.content.Intent)' on a null object reference

The first one probably because you are on an emulator and the second one is a cordova issue
Did you overide onActivityResult in your main Activity ?

@abdelwehed
Copy link
Author

Yes the first is due to the emulator and here is the onActivityResult in my mainActivity:

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
            super.onActivityResult(requestCode, resultCode, intent);
            cordovaPluginPackage.onActivityResult(requestCode, resultCode, intent);
        }

@abdelwehed
Copy link
Author

Thank you yfuks i solved the problem based on your help and it was due to overriding the onActivityResult.

@yfuks yfuks closed this as completed Oct 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants