Null object reference with Camera on Android

#1

Hello,

The following boilerplate code works fine on iOS but generates an error on Android device :

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

import { Camera } from "expo"

export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Camera
          ratio="16:9"
          style={{ flex: 1, justifyContent: "center" }} >
          <View style={{ flex: 1, justifyContent: "center" }}><Text>hello</Text></View>
        </Camera>
      </View >
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

0 Likes

#2

I also try the documentation snippet and got the same error :

import React from 'react';
import { Text, View, TouchableOpacity } from 'react-native';
import { Camera, Permissions } from 'expo';

export default class CameraExample extends React.Component {
  state = {
    hasCameraPermission: null,
    type: Camera.Constants.Type.back,
  };

  async componentWillMount() {
    const { status } = await Permissions.askAsync(Permissions.CAMERA);
    this.setState({ hasCameraPermission: status === 'granted' });
  }

  render() {
    const { hasCameraPermission } = this.state;
    if (hasCameraPermission === null) {
      return <View />;
    } else if (hasCameraPermission === false) {
      return <Text>No access to camera</Text>;
    } else {
      return (
        <View style={{ flex: 1 }}>
          <Camera style={{ flex: 1 }} type={this.state.type}>
            <View
              style={{
                flex: 1,
                backgroundColor: 'transparent',
                flexDirection: 'row',
              }}>
              <TouchableOpacity
                style={{
                  flex: 0.1,
                  alignSelf: 'flex-end',
                  alignItems: 'center',
                }}
                onPress={() => {
                  this.setState({
                    type: this.state.type === Camera.Constants.Type.back
                      ? Camera.Constants.Type.front
                      : Camera.Constants.Type.back,
                  });
                }}>
                <Text
                  style={{ fontSize: 18, marginBottom: 10, color: 'white' }}>
                  {' '}Flip{' '}
                </Text>
              </TouchableOpacity>
            </View>
          </Camera>
        </View>
      );
    }
  }
}
0 Likes

#3

Hi @softhib - thanks for providing the code example. Unfortunately I’m not able to reproduce this. @aalices - could you help?

0 Likes

#4

I can provide some informations about the phone :
Expo version 2.3.0

Device :

0 Likes

closed #5

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

0 Likes