0
我想向我的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);
}
}
}
任何想法?
不起作用。我添加了'import android.content.Intent;'並且仍然是相同的錯誤。 – slowydown
只需清理並重建它,如果它工作。你在使用android studio setup還是其他設置,例如原子和命令行工具? –
我使用了PHPStrom,但我只是將我的項目移動到Android Studio。如何在Android Studio中重建React Native項目? – slowydown