Sintax problem in command

package frc.robot.subsystems;

import java.io.IOException;
import java.nio.file.Path;

import edu.wpi.first.math.trajectory.Trajectory;
import edu.wpi.first.math.trajectory.TrajectoryUtil;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Filesystem;

public class pegatrajeto {
    
    String trajectoryJSON = "paths/Unnamed_.wpilib.json";
    Trajectory trajectory = new Trajectory();

    try {
            Path trajectoryPath = Filesystem.getDeployDirectory().toPath().resolve(trajectoryJSON);
            trajectory = TrajectoryUtil.fromPathweaverJson(trajectoryPath);
        }catch (IOException ex) {
            DriverStation.reportError("não foi possivel abrir a trajetoria:" + trajectoryJSON, ex.getStackTrace());
        }
}

i am triing to initialize a pathweaver trajectory in a separate archive, to reference it in the autonomous mode in robot container. i copied the example code from FIRST site ant it has something that is not right

[{
	"resource": "/e:/coisas/programations/swerve-2/src/main/java/frc/robot/subsystems/pegatrajeto.java",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": "1610612967",
	"severity": 8,
	"message": "Syntax error on token \";\", { expected after this token",
	"source": "Java",
	"startLineNumber": 14,
	"startColumn": 45,
	"endLineNumber": 14,
	"endColumn": 46
}]

and

[{
	"resource": "/e:/coisas/programations/swerve-2/src/main/java/frc/robot/subsystems/pegatrajeto.java",
	"owner": "_generated_diagnostic_collection_name_#1",
	"code": "1610612976",
	"severity": 8,
	"message": "Syntax error, insert \"}\" to complete ClassBody",
	"source": "Java",
	"startLineNumber": 22,
	"startColumn": 1,
	"endLineNumber": 22,
	"endColumn": 2
}]

it is probably a very dumb solution, but i’m not too familiar with java and how to reference it properly

Is that your actual code? Or just a simplified version of it? The issue with the code snippet you provided is that your try/catch block is at the class level which is not allowed. That code needs to exist within a function/method scope.

There’s also a syntax error in your title :rofl:

To help you, though, can you please paste the whole class? It seems this is only a snippet, which makes it difficult to debug.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.