MainApplication.java:84: error: class, interface, or enum expected }

Maliethy·2021년 4월 1일
0

React-Native Error

목록 보기
11/15
post-custom-banner

1. issue

rn프로젝트에서 npm run android를 하는 도중 Task :app:compileDebugJavaWithJavac FAILED가 발생했다.

> Task :app:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
Note: /Users/momo/wellgrower/node_modules/@react-native-async-storage/async-storage/android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStorageModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/momo/wellgrower/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java uses unchecked or unsafe operations.

react-native-webview에서 문제가 발생한 것 같아 react-native-webview를 삭제해보니 이번에는 다음의 에러가 발생했다.

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:46: error: class, interface, or enum expected
  public ReactNativeHost getReactNativeHost() {
         ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:48: error: class, interface, or enum expected
  }
  ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:51: error: class, interface, or enum expected
  public void onCreate() {
         ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:53: error: class, interface, or enum expected
    SoLoader.init(this, /* native exopackage */ false);
    ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:54: error: class, interface, or enum expected
    initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
    ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:55: error: class, interface, or enum expected
  }
  ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:73: error: class, interface, or enum expected
        aClass
        ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:74: error: <identifier> expected
            .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
                                                         ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:74: error: <identifier> expected
            .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
                                                                                ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:74: error: ';' expected
            .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
                                                                                     ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:75: error: illegal start of type
            .invoke(null, context, reactInstanceManager);
            ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:75: error: illegal start of type
            .invoke(null, context, reactInstanceManager);
                    ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:75: error: <identifier> expected
            .invoke(null, context, reactInstanceManager);
                                 ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:75: error: <identifier> expected
            .invoke(null, context, reactInstanceManager);
                                                       ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:76: error: class, interface, or enum expected
      } catch (ClassNotFoundException e) {
        ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:78: error: class, interface, or enum expected
      } catch (NoSuchMethodException e) {
      ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:80: error: class, interface, or enum expected
      } catch (IllegalAccessException e) {
      ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:82: error: class, interface, or enum expected
      } catch (InvocationTargetException e) {
      ^
/Users/momo/wellgrower/android/app/src/main/java/com/wellgrower/MainApplication.java:84: error: class, interface, or enum expected
      }
      ^
19 errors

FAILURE: Build failed with an exception.

2. solution

class, interface or enum expected를 키워드로 검색해보니 MainApplication.java에 괄호가 잘못닫혀있었다...

class, interface or enum expected
이 메시지의 의미는 '키워드 class 나 interface 또는 enum가 없다.' 이지만, 보통 괄호 '{' 또는 '}'의 개수가 일치하지 않는 경우에 발생한다. 열린 괄호 '{'와 닫힌 괄호 '}'의 개수가 같은지 확인하자.

출처:허니몬(Honeymon)의 자바guru

역시 에러를 잡을 땐 검색 키워드가 중요하다!

profile
바꿀 수 있는 것에 주목하자
post-custom-banner

0개의 댓글