In the nice Erels Orientation Tutorial one can find this sub:
This sub is envoked:
1. The IDE tells me: "nicht alle Codepfade geben einen Wert zurück" (Not each line returns a value), which refers to this sub
2. The warning vanishes, when I delete the "As SensorData" in the Line: Sub AddSensor...
3. If I do 2., the compiler throws an error:
Error occurred on line: 56 (Main)
java.lang.ClassCastException: java.lang.String cannot be cast to anywheresoftware.b4a.samples.sensors.main$_sensordata
at anywheresoftware.b4a.samples.sensors.main._addsensor(main.java:470)
at anywheresoftware.b4a.samples.sensors.main._activity_create(main.java:407)
...
where line 56 is the line with "End Sub". Why this error?
4. The sub does not contain a return <variable>. So what is returned?
5. And why is it necessary, that it has a return-value?
B4X:
Sub AddSensor(SensorType As Int, Name As String, ThreeValues As Boolean) As SensorData
Dim sd As SensorData
sd.Initialize
sd.Name = Name
sd.ThreeValues = ThreeValues
Dim ps As PhoneSensors
ps.Initialize(SensorType)
SensorsMap.Put(ps, sd)
Log(Name & " MaxValue = " & ps.MaxValue)
End Sub
This sub is envoked:
B4X:
Dim ps As PhoneSensors 'This object is only used to access the type constants.
AddSensor(ps.TYPE_ACCELEROMETER, "ACCELEROMETER", True)
AddSensor(ps.TYPE_GYROSCOPE, "GYROSCOPE", True)
AddSensor(ps.TYPE_LIGHT, "LIGHT", False)
AddSensor(ps.TYPE_MAGNETIC_FIELD, "MAGNETIC", True)
AddSensor(ps.TYPE_ORIENTATION, "ORIENTATION", True)
AddSensor(ps.TYPE_PRESSURE, "PRESSURE", False)
AddSensor(ps.TYPE_PROXIMITY, "PROXIMITY", False)
AddSensor(ps.TYPE_TEMPERATURE, "TEMPERATURE", False)
1. The IDE tells me: "nicht alle Codepfade geben einen Wert zurück" (Not each line returns a value), which refers to this sub
2. The warning vanishes, when I delete the "As SensorData" in the Line: Sub AddSensor...
3. If I do 2., the compiler throws an error:
Error occurred on line: 56 (Main)
java.lang.ClassCastException: java.lang.String cannot be cast to anywheresoftware.b4a.samples.sensors.main$_sensordata
at anywheresoftware.b4a.samples.sensors.main._addsensor(main.java:470)
at anywheresoftware.b4a.samples.sensors.main._activity_create(main.java:407)
...
where line 56 is the line with "End Sub". Why this error?
4. The sub does not contain a return <variable>. So what is returned?
5. And why is it necessary, that it has a return-value?