question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unfortunately App has stopped (crashed)

See original GitHub issue

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: `<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.nativestarterkit" android:versionCode="1" android:versionName="1.0">

<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>
</manifest> ` 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
                        });

            }

    });
 }`

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
abdelwehedcommented, Oct 24, 2016

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);
        }
0reactions
abdelwehedcommented, Oct 24, 2016

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

8 Quick Ways to Fix “Unfortunately App Has Stopped” On ...
Restart your phone · Check for low storage and RAM · Update the Android system WebView app · Ensure the affected app is...
Read more >
7 Ways to Fix 'Unfortunately, App Has Stopped' Error on Android
Fix Unfortunately App Has Stopped Error on Android · 1. Restart Your Phone · 2. Force Stop the App · 3. Update the...
Read more >
Fix Error Unfortunately App Has Stopped on Android - EaseUS
Common Ways to Fix The Error "Unfortunately app has stopped" · Method 1. Re-install the app. We suggest you take the method for...
Read more >
How to Eliminate the "Unfortunately, App Has Stopped ...
The “Unfortunately, App has stopped” message can also be caused by a corrupted SD card. To check, remove the SD card and try...
Read more >
How to fix "unfortunately app has stopped" error on Android?
1. Clear the cache fix unfortunately app has stopped · 2. Restart the device · 3. Update the app · 4. Uninstall and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found