Java syntax error on token ";" expected [closed] - java

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have a small problem in my java code. Error is
Syntax error on token ";", , expected
Here is my code:
package natchly.chest;
import natchly.chest.blocks.BlockStoneChest;
import net.minecraft.block.Block;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.common.event.FMLInitializationEvent;
#Mod(modid="chestsplus", name="Chests+", version="1.4.6_01")
#NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class ModChests {
public int idBlockStoneChest = 250;
public static Block blockStoneChest; // <-------- Error here
blockStoneChest = new BlockStoneChest(idBlockStoneChest).setBlockName("blockNAZWABLOKU").setHardness(1.5F).setResistance(5.0F);
#Init
public void init(FMLInitializationEvent e) {
GameRegistry.registerBlock(blockStoneChest);
LanguageRegistry.addName(blockStoneChest, "Stone Chest");
}
}

Either do this:
public static Block blockStoneChest = new BlockStoneChest(idBlockStoneChest).setBlockName("blockNAZWABLOKU").setHardness(1.5F).setResistance(5.0F);
Or this:
public static Block blockStoneChest; <-------- Error here
static {
blockStoneChest = new BlockStoneChest(idBlockStoneChest).setBlockName("blockNAZWABLOKU").setHardness(1.5F).setResistance(5.0F);
}

Combine these two lines into one declaration and instantiation step. The way you're doing it isn't permitted in Java unless that's inside of a method.
public static BlockStoneChest blockStoneChest = new BlockStoneChest(idBlockStoneChest).setBlockName("blockNAZWABLOKU").setHardness(1.5F).setResistance(5.0F);

Related

"kBrushless cannot be resolved or is not a field" error in FRC Java [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last year.
Improve this question
Importer "kBrushless" states that is is not resolved of not a field. Any help?
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package frc.robot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.RobotDriveBase.MotorType;
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
// import edu.wpi.first.hal.FRCNetComm.tResourceType;
// import edu.wpi.first.hal.HAL;
import frc.robot.autos.*;
import frc.robot.commands.*;
import frc.robot.subsystems.*;
public class Robot2 extends TimedRobot {
private static final int leadDeviceID = 1;
private static final int followDeviceID = 2;
private static final int kJoystickPort = 0;
private CANSparkMax m_leadMotor;
private CANSparkMax m_followMotor;
private Joystick m_joystick;
#Override
public void robotInit() {
m_leadMotor = new CANSparkMax(leadDeviceID, MotorType.kBrushless);
m_followMotor = new CANSparkMax(followDeviceID, MotorType.kBrushless);
m_leadMotor.restoreFactoryDefaults();
m_followMotor.restoreFactoryDefaults();
}
}
This is also using the WPI libraries and FRC. This is also using all of the imported libraries, as it is shown below.
You are importing the wrong MotorType enum:
the edu.wpi.first.wpilibj.drive.RobotDriveBase.MotorType doesn't contain a kBrushless constant.
it seems that you are using CANSparkMax (because you write m_leadMotor = new CANSparkMax(leadDeviceID, MotorType.kBrushless);)
the [CANSparkMax constructor](https://codedocs.revrobotics.com/java/com/revrobotics/cansparkmax#%3Cinit%3E(int,com.revrobotics.CANSparkMaxLowLevel.MotorType) takes as second parameter an instance of CANSparkMaxLowLevel.MotorType, which has a constant kBrushless
Therefore it seems that you should replace
import edu.wpi.first.wpilibj.drive.RobotDriveBase.MotorType;
with
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
and probably also add
import com.revrobotics.CANSparkMax;

Google Firebase real time database updateChildren() method is not working? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
In my application, I am using google firebase real-time database with admin-sdk for Java. When I run a sample program from my machine it works perfectly and updates the given data into firebase db. But, when I try to run the same program from another public server, it's not working. It doesn't throw any exceptions at all. updateChildren() was executed, and then nothing. I tried with onCompletionListener too.There is nothing in there. What might be the problem?
FBManager.java
import com.nexge.firebase.Firebase;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import java.util.HashMap;
class FBManager {
//FIREBASE
public static Firebase fireBase;
public static DatabaseReference dbRef = null;
public static String filePath="key/siva-6d0aa-firebase-adminsdk-1bo0t-e98c5af5d5.json";
public static String databaseUrl="https://siva-6d0aa.firebaseio.com";
public static String projectName="ABES";
public static String databaseChildPath;
public static void main(String[] args) {
try {
databaseChildPath="calls/";
System.out.println("Inside iniDB !");
fireBase = new Firebase(filePath, databaseUrl, projectName, databaseChildPath);
System.out.println("FireBase db created!");
dbRef = fireBase.getDatabaseReference();
System.out.println("Got reference!");
T t = new T();
new Thread(t).start();
}
catch(Exception e) {
e.printStackTrace();
}
}
}
T.java
class T implements Runnable {
public void run() {
try {
String path = "191963944/5e0e44e2-3442-4acd-977a-fea7232c0f0a";
HashMap hm1 = new HashMap();
hm1.put("caller_Recv_Media_IpPort","xxx.xxx.xx.xxx:9811");
HashMap hm2 = new HashMap();
hm2.put("yServer_src_Media_IpPort","xxx.xx.xx.xx:10000");
FBManager.dbRef.child(path).updateChildren(hm1);
FBManager.dbRef.child(path).updateChildren(hm2);
Thread.sleep(10000);
}
catch(Exception e) {
e.printStackTrace();
}
}
}
It seems this is to do with server network issue. Working fine in another server. Closing this question. thanks

Method-call compile error [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
This is my code:
public class LoginSql {
Conexion con = new Conexion();
con.conexionDB(); // error here <
}
package con does not exist
but exist
public class Conexion {
public Connection conexionDB(){
Connection link = null;
return link
}
}
I using package example
com.hi.pro
com.hi.pro.class
com.hi.pro.sql
I have code in com.hi.pro.sql but not work
only work in the com.hi.pro in class app.java
The problem is that this statement:
con.conexionDB();
... is just a method call statement. That can't sit directly inside a class - it needs to be in a method, constructor, or initializer block. You probably want to put it in a constructor:
public class LoginSql {
private Conexion con = new Conexion();
public LoginSql() {
con.conexionDB();
}
}
The declaration of con is fine, because that's an instance variable declaration, which is allowed directly inside a class declaration.
Note that this has nothing to do with packages. It's purely a matter of trying to put a statement in the wrong place.
call that method inside some method or constructor.
like
public void createConnection(){
con.conexionDB();
}
OR
public LoginSql(){
con.conexionDB();
}
Hope that helps

type cannot be resolved [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
heres my code:
import javax.swing.*;
import java.awt.*;
public class FirstGui extends JFrame {
private JLabel label;
private JButton button;
public FirstGui() {
setLayout(new FlowLayout());
button = new JButton("Click for sex");
add(button);
label = new JLabel("");
add(label);
event e = new event();
button.addActionListener(e);
}
public class event implements ActionListener {
public void actionPerformed(ActionEvent e) {
label.setText("how you can see wors here");
}
}
public static void main(String [] args) {
FirstGui gui = new FirstGui();
gui.setDefaultCloseOperation(EXIT_ON_CLOSE);
gui.setSize(200, 200);
gui.setTitle("Title");
gui.setVisible(true);
}
}
And it generates a errors:
ActionEvent cannot be resolved to a type FirstGui.java /Test/src line 26 Java Problem
ActionListener cannot be resolved to a type FirstGui.java /Test/src line 24 Java Problem
The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (FirstGui.event) FirstGui.java /Test/src line 21 Java Problem
what is wrong with it??? im new to java.
Import the following:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
ActionEvent and ActionListener are located into the java.awt.event package.
Importing java.awt.* is not enough.
Both of these classes require you to import them. You can do so by importing everything in java.awt.event:
import java.awt.event.*;
or you may just want to import specifically what you're using:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Remember that it's considered good practice to import individual classes (the latter option) instead of importing whole packages.
If you ever get stuck like this again, looking at The Docs for any Java Class will tell you exactly what you need to import with a little diagram that looks like this:
java.lang.Object
java.util.EventObject
java.awt.AWTEvent
java.awt.event.ActionEvent

What is this syntax - public static 9000? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Reading the article on http://www.jamesward.com/2011/08/23/war-less-java-web-apps on how to embed an app server with your application, i noticed this bit of code.
package foo;
import java.io.File;
import java.net.URL;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.*;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.webapp.WebAppContext;
public class Main
{
public static 9900;">);
out.close();
}
}
What is the Main class doing as i dont understand that syntax.
I see this, so it has to be a problem with your browser.
package foo;
import java.io.File;
import java.net.URL;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.*;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.webapp.WebAppContext;
public class Main
{
public static void main(String[] args) throws Exception
{
String webappDirLocation = "src/main/webapp/";
Server server = new Server(8080);
WebAppContext root = new WebAppContext();
root.setContextPath("/");
root.setDescriptor(webappDirLocation + "/WEB-INF/web.xml");
root.setResourceBase(webappDirLocation);
root.setParentLoaderPriority(true);
server.setHandler(root);
server.start();
server.join();
}
}
This is not compilable source code
Also there is no such source code available from the link you provided
public static 9900;">);
The above is no legal code, it may be some issue with your browse.
Which browser are you using anyways....

Categories