方法不会覆盖或实现超类型的方法(:app:compileDebugJavaWithJavac)

时间:2016-08-09 06:16:55

标签: android android-studio react-native

运行命令react-native run-android时出现以下错误。可能是什么问题?

  

:应用程序:compileDebugJavaWithJavacC:\用户\ Deeksha   古普塔\ git的\ PE-金原生\机器人\程序\ SRC \主\ java中的\ com \ pegoldnative \ MainActivity.java:39:   error:方法不会覆盖或实现超类型的方法   @Override ^ 1错误失败        FAILURE:构建因异常而失败。任务':app:compileDebugJavaWithJavac'

的执行失败

MainActivity.java

  package com.pegoldnative;

  import com.facebook.react.ReactActivity;
  import com.horcrux.svg.RNSvgPackage;
  import io.realm.react.RealmReactPackage;
  import com.brentvatne.react.ReactVideoPackage;
  import com.facebook.react.ReactPackage;
  import com.facebook.react.shell.MainReactPackage;

  import java.util.Arrays;
  import java.util.List;
  import com.oblador.vectoricons.VectorIconsPackage;
  import com.mihir.react.tts.*;
  import com.rnfs.RNFSPackage;
  public class MainActivity extends ReactActivity {

/**
 * Returns the name of the main component registered from JavaScript.
 * This is used to schedule rendering of the component.
 */
     @Override
     protected String getMainComponentName() {
        return "pegoldnative";
     }

/**
 * Returns whether dev mode should be enabled.
 * This enables e.g. the dev menu.
 */
    @Override
    protected boolean getUseDeveloperSupport() {
         return BuildConfig.DEBUG;
    }

/**
 * A list of packages used by the app. If the app uses additional views
 * or modules besides the default ones, add more packages here.
 */
    @Override
    protected List<ReactPackage> getPackages() {
         return Arrays.<ReactPackage>asList(
             new MainReactPackage(),
             new RNSvgPackage(),
             new RealmReactPackage(),
             new ReactVideoPackage()
             , new VectorIconsPackage()
            , new RCTTextToSpeechModule()
            , new RNFSPackage()
    );
  }
}

1 个答案:

答案 0 :(得分:3)

截至发布此问题的日期,我相信您使用的是react native 0.29或更高版本。

如果是这样,在react native 0.29引导程序包的方式发生了变化:

https://github.com/facebook/react-native/releases/tag/v0.29.0

现在你有一个MainApplication.java类,扩展Application并实现ReactApplication

您可以覆盖getUseDeveloperSupport()方法。

MainApplication.java

package com.yourapp;

import android.app.Application;
import android.util.Log;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    protected boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(          
          new MainReactPackage()
      );
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
      return mReactNativeHost;
  }
}