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

undefined is not an object (evaluating 'RNBackgroundTimer.setTimeout' #35

Closed
dadsteph opened this issue Jun 28, 2017 · 19 comments
Closed

Comments

@dadsteph
Copy link

dadsteph commented Jun 28, 2017

I'm getting this error:

simulator screen shot 28 jun 2017 16 33 57

This is the source code:

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


import BackgroundTimer from 'react-native-background-timer';

class WorkerSampleApp extends Component {


  render() {

    return (
      <View style={styles.container}>
        <TouchableOpacity onPress={() => {

          // Start a timer that runs once after X milliseconds
          const timeoutId = BackgroundTimer.setTimeout(() => {
          	// this will be executed once after 10 seconds
          	// even when app is the the background
            	console.log('tac');

          }, 10000);

          // Cancel the timeout if necessary
          BackgroundTimer.clearTimeout(timeoutId);
          
        }}>
          <Text style={styles.welcome}>
            Send message
          </Text>
        </TouchableOpacity>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});


AppRegistry.registerComponent('WorkerSampleApp', () => WorkerSampleApp);

Please help...

@prayash
Copy link
Contributor

prayash commented Jun 30, 2017

Did you remember to run react-native link after installing the module? I ran into the same issue and running that command fixed it for me.

@the-simian
Copy link

the-simian commented Jul 4, 2017

I wanted to share that the link command alone did not help me, in the long run I had to link manually. In your src/main/java/com/appname/MainApplication.java

import com.ocetnik.timer.BackgroundTimerPackage;

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new VectorIconsPackage(),
          //........and so on
          new BackgroundTimerPackage()
      );
    }

good luck! android build errors in this ecosystem are frustrating sometimes :)

@JimSchofield
Copy link

I used react-native link and I checked src/main/java/com/appname/MainApplication.java for the correct links. Still getting the same error here... What might be going on?

@the-simian
Copy link

the-simian commented Jul 5, 2017

another thing to check is in your settings.gradle located in the android root has the following entries as well:


include ':react-native-background-timer'
project(':react-native-background-timer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-timer/android')

I know I mentioned it before, but the link command simply did no good for me, and I had to add this stuff myself. Finally I'd (just to cover our bases) make sure you're using latest packages as well. Hope that helps.

@JimSchofield are you getting the exact same stacktrace as this issue? Does it point to the setTimeout, or clear timeout? Just making sure I'm not overlooking something

Best of luck :)

@JimSchofield
Copy link

JimSchofield commented Jul 7, 2017

@the-simian gradle entries were identical to what you supplied, and it was identical to the op. For some reason I re-imported it and tried using it and it worked... I wish I could tell you what I was doing wrong. Thanks for the help!

@the-simian
Copy link

glad to hear its working for you :)

@ocetnik
Copy link
Owner

ocetnik commented Jul 13, 2017

@dadsteph Did previous comments help you? Can I close this issue?

@KenilDomadia
Copy link

I am working with expo integrated app, the above steps couldn't solve the issue for me. Is there anything else I can do to solve the issue?

@pencilcheck
Copy link

Works for me after adding the lines in MainApplication.java in addition to the react-native link

@natterstefan
Copy link

@the-simian thanks for your comment it did work for me as well now. Wondering why this is not properly working or in the Readme.

@the-simian
Copy link

Right on @natterstefan ~! React Native... sometimes you gotta jiggle the cables you know?

@zorobabel
Copy link

@dadsteph Check this comment

@ocetnik I think you can close this issue

@ocetnik ocetnik closed this as completed Jan 29, 2018
@akshayseth
Copy link

Not working on expo!

@ocetnik
Copy link
Owner

ocetnik commented Aug 12, 2019

@akshayseth If you use Expo you'll just need to "eject". Check the installation section in the readme.

@the-simian
Copy link

@akshayseth I'm using expo these days also, honestly, I often have problems when I stray from expo's ecosystem unless I eject (which I usually don't because there's a lot of downsides to that)

@borohhov
Copy link

One more thing to the discussion: if you are using remote debugging via Wifi with a real phone, you still need to connect via cable. Remote reloading delivers only the Javascript files, while you need the new app build, which can only be delivered through a cable.

@haratmalli
Copy link

if you were just install this and testing with
BackgroundTimer.runBackgroundTimer(() => { //code that will be called every 3 seconds }, 3000);
and got null is not an object (evaluating 'RNBackgroundTimer.start') error.
You should rebuild app like react-native run-android

@prajna-h
Copy link

prajna-h commented Oct 5, 2020

Not working for me even after linking the module manually. Please help : (

@terrynguyen255
Copy link

I'm also facing this problem although I already followed the README (manual linking included) :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests