Programming problem "Syntax error on token ";", , expectedJava(1610612940)"

package frc.robot.commands.subsystemState;

import edu.wpi.first.wpilibj.AnalogInput;
import edu.wpi.first.wpilibj2.command.CommandBase;
import frc.robot.subsystens.Conveyor;



public class Infra extends CommandBase {
    
    Conveyor m_conveyor;
    
    public AnalogInput sharp;
    
    //Constuct a new instance
    sharp = new AnalogInput(port);
    
    //Create an accessor method
    public double getDistance()
    {
        double irValue = sharp.getValue();
        
        return (Math.pow(sharp.getAverageVoltage(), -1.2045)) * 27.726;
    }
    
boolean isObjectInIntake = (sharp < 4); 

public void startConveyor (boolean a) {
    this.isObjectInIntake = a;

  if (a == true){
    new startConveyor(m_conveyor);
        } else {
            new stopConveyor(m_conveyor);
        }
    }
}

I was trying to program the distance sensor Infrared Proximity Sensor - Sharp GP2Y0A21YK. On line 13
But my code is giving me this error, can anyone help?
Thanks in advance

You can’t do this here. You could combine the instantiation with the declaration a couple lines above if thats what you want to do, or you can move this line into the constructor.

Not certain that’s your issue, but it seems to be the most likely to me.

1 Like

It worked thanks man

I’m surprised that this compiles, since sharp is an object. You probably want the getDistance method instead of sharp object.
Also, that will only execute once when the program starts, so the conveyor would only ever start if something was in the intake when the program started.

I didn’t realize I could do that. I was creating another int variable and assigning sharp to it, but the way you said is really much more practical. I’m still a beginner programmer and don’t know much. Thanks for the tips, I’ll sort it out

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