Is there something wrong with this code?
Any help is appreciated.
This is the error:
Compiling generated Java code. Error
javac 1.8.0_101
src\prusb\nfctoggle\main.java:478: error: ';' expected
If (nfcAdapter != Null) {
^
1 error
B4X:
#Region Project Attributes
#ApplicationLabel: testNFC
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#AdditionalJar: android-support-v4
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim jo As JavaObject
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private btnToggle As Button
Private lblTitle As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Main")
If FirstTime Then
jo.InitializeContext
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnToggle_Click
Dim isOn As Boolean
Dim success As Boolean
isOn = jo.RunMethod("checkNfcPowerStatus", Array As Object(Me))
success = jo.RunMethod("powerNfc", Array As Object(isOn, Me))
If success Then
ToastMessageShow("Success", False)
Else
ToastMessageShow("Failed", False)
End If
End Sub
#If JAVA
public static boolean powerNfc(boolean isOn, Context context) {
boolean success = false;
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
if (nfcAdapter != null) {
Class<?> NfcManagerClass;
Method setNfcEnabled;
try {
NfcManagerClass = Class.forName(nfcAdapter.getClass().getName());
setNfcEnabled = NfcManagerClass.getDeclaredMethod(isOn
? "enable" : "disable");
setNfcEnabled.setAccessible(true);
success = (Boolean) setNfcEnabled.invoke(nfcAdapter);
} catch (ClassNotFoundException e) {
Log.e(TAG, Log.getStackTraceString(e));
} catch (NoSuchMethodException e) {
Log.e(TAG, Log.getStackTraceString(e));
} catch (IllegalArgumentException e) {
Log.e(TAG, Log.getStackTraceString(e));
} catch (IllegalAccessException e) {
Log.e(TAG, Log.getStackTraceString(e));
} catch (InvocationTargetException e) {
Log.e(TAG, Log.getStackTraceString(e));
}
}
return success;
}
public static boolean checkNfcPowerStatus(Context context) {
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
boolean enabled = false;
If (nfcAdapter != Null) {
enabled = nfcAdapter.isEnabled();
}
Return enabled;
}
#End If
Any help is appreciated.
This is the error:
Compiling generated Java code. Error
javac 1.8.0_101
src\prusb\nfctoggle\main.java:478: error: ';' expected
If (nfcAdapter != Null) {
^
1 error