IOException cannot be resolved to a type

Hi,

I use a snippet from other posts. The function works well, but my Visual Studio Code editor shows me some problems:
grafik

The files are saved and can be used to send it via Pushover.

The full rule file:

// Importe, um Kamerabilder abzuspeichern
import javax.xml.bind.DatatypeConverter
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStream
//import java.io.*

// Name des Regelwerks für Logging
val String Regelwerk = "Kameras.rules"
var PushoverServiceUser = "xxxxxxxxxxxxxxxxxxxxx"
var PushoverServiceGroup = "xxxxxxxxxxxxxxxxxxxxx"
var KameraSnapshotPath = "/var/lib/openhab2/tmp/KameraSnapshots"

rule "SavePicture"
when
  Item FlurKameraSnapshot changed
  or Item WohnzimmerKameraSnapshot changed
then
  logDebug(Regelwerk, "Rule: <SavePicture>, triggeringItem: {}",triggeringItem)
  //Convert image item to base64 encoded string
  var String CameraImage = triggeringItem.state.toFullString
  //Slice the string up to the delimiter ","
  val String Image64 = CameraImage.split(",").get(1) 
  var byte[] data = DatatypeConverter.parseBase64Binary(Image64)

  try {
    var OutputStream os;
    //val time = new DateTime().millisOfDay().getMillis()
    var File f = new File(KameraSnapshotPath + "/" + triggeringItem.name + ".jpg")
    os = new FileOutputStream(f);
    os.write(data);
    os.close();
  } catch (IOException e) {
    e.printStackTrace();
  }
end



rule "Kamera Bewegung erkannt"
when 
    Item FlurKameraEventMotion changed from OFF to ON
    or Item WohnzimmerKameraEventMotion changed from OFF to ON
then
    if (surveillancestationHomemode.state == OFF) {
        var String Kameraname = ""
        switch triggeringItem.name
        {
            case "FlurKameraEventMotion": Kameraname = "FlurKamera"
            case "WohnzimmerKameraEventMotion": Kameraname = "WohnzimmerKamera"
            case "Undefined",
            case "Uninitialized": { }

            default:
            {
                logWarn (Regelwerk, "TriggeringItem nicht bekannt: " + triggeringItem.name + " (" + triggeringItem.label + ")")
            }
        }
        logInfo(Regelwerk, "Rule: <Kamera Bewegung erkannt>, triggeringItem: {}", triggeringItem)
        //sendPushoverMessage(pushoverBuilder(triggeringItem.label).withApiKey(PushoverServiceUser).withUser(PushoverServiceGroup).withTitle(Kameraname).withPriority(-2).withAttachment(KameraSnapshotPath+"/" + Kameraname + "Snapshot.jpg"))
        sendPushoverMessage(pushoverBuilder(triggeringItem.label).withTitle(Kameraname).withPriority(1).withAttachment(KameraSnapshotPath+"/" + Kameraname + "Snapshot.jpg"))
    }
end

What is wrong with the IOException Code?

Thanks
Ulf

  • Platform information:
    • Hardware: amd64/4GB/16GB KVM
    • OS: Debian 10 Buster
    • Java Runtime Environment: OpenJDK Runtime Environment (Zulu 8.46.0.19-CA-linux64) (build 1.8.0_252-b14)
    • openHAB version: 2.5.4 (Build)

Too bad nobody could help me. In the end it was very easy, because only one class had to be loaded, namely java.io.IOException.

The original author had imported everything from io that I had commented out.

After I corrected the block at the beginning, there was no error message anymore.

// Importe, um Kamerabilder abzuspeichern
import javax.xml.bind.DatatypeConverter
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStream
import java.io.IOException // this line was missing
//import java.io.*