mehcode / rn-splash-screen

A JavaScript-controlled splash-screen for React Native designed to be run directly after the native splash-screen.
MIT License
350 stars 95 forks source link

Error: cannot find symbol SplashScreen #47

Closed name-industry closed 7 years ago

name-industry commented 7 years ago

Im not well versed in JAVA, attempting to use the component and currently stuck at :

rn-splash-screen ^4.0.1 react-native v : 46 link was positive for both IOS and Android building from terminal

error: cannot find symbol SplashScreen.show(this); ^ symbol: variable SplashScreen location: class MainActivity

In the MainActivity.java file are included :

package com.v1;  
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.ReactContext;
import com.mehcode.reactnative.splashscreen.SplashScreenPackage;

From a prior closed issue someone else had this issue but solved it via the importing of -> android.content.bundle. Sadly that didnt work for me.

In the MainApplication.java file are included :

import com.mehcode.reactnative.splashscreen.SplashScreenPackage;

and is triggered in :

protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
      new MainReactPackage(),
        new SplashScreenPackage(),

In the MainActivity.java file the create call was added ( since its now located in the Application file as well ) and looks like this:

public class MainActivity extends ReactActivity {

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
  SplashScreen.show(this, getReactInstanceManager());
  super.onCreate(savedInstanceState);
}

Last, its also correctly listed under dependancies in graddle

compile project(':rn-splash-screen')

Any hints as to what I'm doing wrong would be greatly appreciated. Works perfect on the IOS side of things. I'm sure its something super small that I managed to mistake.

mehcode commented 7 years ago

You need to import the SplashScreen class in MainActivity. Read over the example file. Especially right here: https://github.com/mehcode/rn-splash-screen/blob/master/example/android/app/src/main/java/com/mehcode/reactnative/splashscreen/example/MainActivity.java#L9

name-industry commented 7 years ago

Oh wow., yes. I absolutely missed that. ( not sure how, mind you... ) Works perfectly now. Thanks for the really fast help and thanks for making the component.

:)

therovermind commented 7 years ago

@mehcode this is my index.android.js file....error says unexpected token at 17:20

import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View } from 'react-native'; import SplashScreen from 'rn-splash-screen'

export default class animaltune extends Component { componentDidMount:function() { //HERE IS THE ERROR SplashScreen.hide(); }, render() { return (

Welcome to React Native! To get started, edit index.android.js Double tap R on your keyboard to reload,{'\n'} Shake or press menu button for dev menu
);

} }

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('animaltune', () => animaltune);

i am new to RN, so just want to use splashscreen.

sakthit03 commented 4 years ago

@mehcode this is my index.android.js file....error says unexpected token at 17:20

import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View } from 'react-native'; import SplashScreen from 'rn-splash-screen'

export default class animaltune extends Component { componentDidMount:function() { //HERE IS THE ERROR SplashScreen.hide(); }, render() { return (

Welcome to React Native!

To get started, edit index.android.js

Double tap R on your keyboard to reload,{'\n'} Shake or press menu button for dev menu

); } }

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('animaltune', () => animaltune);

i am new to RN, so just want to use splashscreen.

oops! replace your componentDidMount:function with componentDidMount. you dont need to use function keyword.

emachalan-subramaniyan commented 4 years ago

In MainActivity.java try to replace import file (import org.devio.rn.splashscreen.SplashScreen;) instead of (import org.devio.rn.splashscreen.SplashScreenReactPackage;)

its working..

sturdynut commented 3 years ago

For those still having issues, open up Android Studio and run it from there. This makes it much easier to see the logs, specifically the error causing the crash.

For me, my splash screen image was too large and I needed to remove packages.add(new SplashScreenReactPackage()); from the MainApplication.java file because it said it had already loaded it. 🤷🏼‍♂️