将模块添加到React Native - 错误:找不到符号
问题描述:
我想向我的React Native应用程序添加一个简单的模块。但是我有一个错误:将模块添加到React Native - 错误:找不到符号
:app:compileDebugJavaWithJavacE:\project\android\app\src\main\java\com\androiddepends\HelloWorld.java:23: error: cannot find symbol
Intent intent = new Intent(Intent.ACTION_WIFI_SETTINGS);
^
symbol: class Intent
location: class HelloWorld
E:\project\android\app\src\main\java\com\androiddepends\HelloWorld.java:23: error: cannot find symbol
Intent intent = new Intent(Intent.ACTION_WIFI_SETTINGS);
^
symbol: class Intent
location: class HelloWorld
E:\project\android\app\src\main\java\com\androiddepends\HelloWorld.java:23: error: cannot find symbol
Intent intent = new Intent(Intent.ACTION_WIFI_SETTINGS);
^
symbol: variable Intent
location: class HelloWorld
E:\project\android\app\src\main\java\com\androiddepends\HelloWorld.java:24: error: cannot find symbol
if (intent.resolveActivity(getPackageManager()) != null) {
^
symbol: method getPackageManager()
location: class HelloWorld
4 errors
FAILED
下面是代码:
package com.androiddepends;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import android.util.Log;
public class HelloWorld extends ReactContextBaseJavaModule {
public HelloWorld(ReactApplicationContext reactContext) {
super(reactContext);
}
@Override
public String getName() {
return "HelloWorld";
}
@ReactMethod
public void openWifiSettings() {
Intent intent = new Intent(Intent.ACTION_WIFI_SETTINGS);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
}
任何想法?
答
您应该导入android SDK的intent包,该包在进口部分找不到。
android.content.Intent
问题是SDK的Intent类未找到。
不起作用。我添加了'import android.content.Intent;'并且仍然是相同的错误。 – slowydown
只需清理并重建它,如果它工作。你在使用android studio setup还是其他设置,例如原子和命令行工具? –
我使用了PHPStrom,但我只是将我的项目移动到Android Studio。如何在Android Studio中重建React Native项目? – slowydown