This question already has answers here:
The declared package does not match the expected package ""
(25 answers)
Closed 3 years ago.
I am trying to create a puzzle solving algorithm with an A* search. everything should be right but I got a problem when I try to use one of the new "MoveUp MoveDown MoveLeft MoveRight" classes that I implemented i get an error that (the declared package "rushhour" does not match the expected package)
MoveDown
package rushhour;
import search.Action;
import search.State;
public class MoveDown implements Action{
int carNum;
int nPositions;
public MoveDown(int carNum, int nPositions){
this.carNum = carNum;
this.nPositions = nPositions;
}
public int getCost() {
return 1;
}
public String toString(){
return "move down";
}
}
then the class I use it in looks like this
package rushhour;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.lang.model.element.Element;
import search.Action;
import search.State;
public class GameState implements search.State {
boolean[][] occupiedPositions;
List<Car> cars; // target car is always the first one
int nrRows;
int nrCols;
...
...
...
public boolean isLegal(Action action) {
if(action instanceof MoveDown){
Car car = cars.get(((MoveDown) action).carNum);
int nextPos = car.getRow() + car.getLength() + ((MoveDown) action).nPositions;
Is is expected that your folder hierarchy matches your package hierarchy, (and vice-versa).
If you classpath is /src/main/java/ your files should look like this:
/src/main/java/rushour/GameState.java
/src/main/java/rushour/MoveDown.java
/src/main/java/search/Action.java
/src/main/java/search/State.java
Related
I am coding a Minecraft Plugin using of course Java for Minecraft 1.12
I have the latest version of Java and eclipse also the Bukkit Api.
This is the error I am getting:
String[] r *=* ("Spamming", "test1", "test2,", "test3", "Test34");
for (String reason : r)
The = is under red line with this error:
Syntax error on token "=", Name expected after this tokenReasonGUI.java /WarningSystem/src/listener line 28 Java Problem
full code:
package listeners;
import java.util.Arrays;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.SkullType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import me.OctoberTroy.WarningSystem.MainClass1;
public class ReasonGUI implements Listener{
MainClass1 main = MainClass1.getPlugin(MainClass1.class);
public Inventory rinv = Bukkit.createInventory(null, 9, "Select a reason to warn the player!");
public ReasonGUI(Player player){
if (player == null){
return;
}
String[] r = ("Spamming", "test1", "test2,", "test3", "Test34");
for (String reason : r);
Java uses braces to initialize an array.
String[] r = {"Spamming", "test1", "test2,", "test3", "Test34"};
Furthermore, although your program will compile, your for loop has no implementation. You cycle through each string in your newly declared array, but do nothing with it. Put the implementation for it as such:
for (String reason : r){
// IMPLEMENTATION GOES HERE
}
In Java you use curly braces {} for arrays, not parenthesis ().
I have been coding my libgdx application (for desktop only) for a while and after deciding to cleanup the code part by part iv'e gotten into a problem i cant seem to solve myself..
exception:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.UnsatisfiedLinkError: com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape()J
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:131)
Caused by: java.lang.UnsatisfiedLinkError: com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape()J
at com.badlogic.gdx.physics.box2d.PolygonShape.newPolygonShape(Native Method)
at com.badlogic.gdx.physics.box2d.PolygonShape.<init>(PolygonShape.java:29)
at com.mygdx.game.handler.BodyEditorLoader.<init>(BodyEditorLoader.java:41)
at com.mygdx.game.util.GameUtils.init(GameUtils.java:23)
at com.mygdx.game.DungeonLife.create(DungeonLife.java:168)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:147)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
after googling for a while i figured my error is as mentioned in this thread
as in
Another problem might be that you instantiate a SpriteBatch (or something else which internally uses a SpriteBatch) too early (looked a bit like this in the stacktrace).
but as the answer mentions
Instead, create such things in the create/show methods of your game.
I cant seem to understand when libgdx is initialized and ready for use, and where to place my GameUtils.init() method to assure libgdx is initialized
My code is as follows: (i have taken out e-relevant methods)
Application Class
package com.mygdx.game;
import box2dLight.RayHandler;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.maps.MapProperties;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.*;
import com.mygdx.game.entity.MobEntity;
import com.mygdx.game.entity.PhysicalEntity;
import com.mygdx.game.entity.Player;
import com.mygdx.game.entity.Weapon;
import com.mygdx.game.handler.*;
import com.mygdx.game.util.CollisionConstants;
import com.mygdx.game.util.GameUtils;
import com.mygdx.game.util.TileObjectUtil;
import com.mygdx.game.util.WorldConstants;
import com.mygdx.game.valtype.WeaponDefinition;
public class DungeonLife extends ApplicationAdapter implements WorldConstants {
OrthographicCamera camera;
float width , height;
Texture texture;
TextureRegion[] enttex;
//TEMP
MobEntity demo;
Player thePlayer;
PlayerInputProcessor playerInputProcessor;
ScreenUI ui;
int mapWidth , mapHeight;
//========================================
GameMap gameMap;
//========================================
#Override
public void create () {
texture = new Texture("maps/img/tileset_entity.png");
enttex = new TextureRegion[(int) ((texture.getWidth()*texture.getHeight()) / (BLOCK*BLOCK))];
enttex[0] = new TextureRegion(texture , 0 , 0 , (int)BLOCK , (int)BLOCK);
enttex[1] = new TextureRegion(texture , (int)BLOCK , 0 , (int)BLOCK , (int)BLOCK);
width = Gdx.graphics.getWidth()/5;
height = Gdx.graphics.getHeight()/5;
camera = new OrthographicCamera(width,height);
camera.position.set(width / 2, height / 2, 0);
camera.update();
GameUtils.init(); // <------this guy
//init();
} ...
GameUtils
package com.mygdx.game.util;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.World;
import com.mygdx.game.entity.PhysicalEntity;
import com.mygdx.game.handler.*;
import java.util.PriorityQueue;
public class GameUtils {
public static void init(){
weapon_bodyEditorLoader = new BodyEditorLoader(Gdx.files.internal("textures/weapons/dungeonlife_weapons.json"));
resourceManager = new ResourceManager();
resourceManager.addRes("friendlyhealth" , new Texture("textures/ui/friendlyhealth.png"));
resourceManager.addRes("enemyhealth" , new Texture("textures/ui/enemyhealth.png"));
tmxMapLoader = new TmxMapLoader();
gameContactListender = new GameContactListender();
}
//GLOBAL
public static BodyEditorLoader weapon_bodyEditorLoader;
public static GameContactListender gameContactListender;
public static ResourceManager resourceManager;
public static TmxMapLoader tmxMapLoader;
//CURRENTS ============================
public static GameMap CURRENT_GAMEMAP;
}
Desktop launcher (the usual)
package com.mygdx.game.desktop;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.mygdx.game.DungeonLife;
import com.mygdx.game.util.GameUtils;
public class DesktopLauncher {
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.useGL30 = false;
config.width=640;
config.height=360;
DungeonLife dungeonLife = new DungeonLife();
new LwjglApplication(dungeonLife, config);
}
}
Help is much appriciated! :D
As I've already wrote in the other linked answer, make sure that your project is correctly set up. Box2D is an extension and needs its own native libraries to be able to run.
It seems that it's a specific problem with the Box2D natives which are not loaded yet. They are not loaded automatically when LibGDX is initializing, but you have to trigger that yourself (see wiki).
The code you've posted looks correct, but before you can use anything Box2D related, you have to call Box2D.init(). Alternatively, creating a World object does the same, but isn't the nicest way to do it.
I am trying to call a docx4j method "setAlgn" in the interface CTTextParagraphProperties, which, per the docx4j jar I am using and the compiler takes an Enum type as a parameter. I am passing the actual argument STTextAlignType.CTR which I believe should resolve to the value 'ctr' (citation: http://grepcode.com/file/repo1.maven.org/maven2/org.docx4j/docx4j/3.0.1/org/docx4j/dml/STTextAlignType.java?av=f, I am running this same code).
Here is my code:
import java.lang.Enum;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFChildAnchor;
import org.apache.poi.xssf.usermodel.XSSFDataFormat;
import org.apache.poi.xssf.usermodel.XSSFDrawing;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
import org.apache.poi.xssf.usermodel.XSSFPrintSetup;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFSimpleShape;
import org.apache.poi.xssf.usermodel.XSSFShapeGroup;
import org.apache.poi.xssf.usermodel.XSSFTextBox;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.docx4j.dml.*;
public static XSSFTextBox createTextBox(XSSFSheet sh, String message, int row1, int col1, int row2, int col2, boolean is_bold, boolean is_italics, boolean is_underline, boolean centered, int fontSize){
//Various apache-poi stuff
XSSFWorkbook wb = sh.getWorkbook();
XSSFDrawing drawing = sh.createDrawingPatriarch();
XSSFClientAnchor clientanchor = new XSSFClientAnchor(0,0,0,0,(short)col1,row1,(short)col2,row2);
XSSFChildAnchor childanchor = new XSSFChildAnchor(0,0,0,0);
XSSFShapeGroup group = drawing.createGroup(clientanchor);
XSSFTextBox textbox = group.createTextbox(childanchor);
XSSFRichTextString richMessage = new XSSFRichTextString(message);
XSSFFont textFont = wb.createFont();
textFont.setFontHeightInPoints((short)fontSize);
textFont.setFontName("Verdana");
if(is_bold){
textFont.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
}
textFont.setItalic(is_italics);
if(is_underline){
textFont.setUnderline(XSSFFont.U_SINGLE);
}
if(centered){
//Here is the code in question.
textbox.getCTShape().getTxBody().getPArray(0).getPPr().setAlgn(STTextAlignType.CTR);
}
richMessage.applyFont(textFont);
textbox.setText(richMessage);
return textbox;
}
My compiler returns the following error message:
com\tem\POIStuff.java:1105: error: method setAlgn in interface CTTextParagraphProperties cannot be applied to given types;
textbox.getCTShape().getTxBody().getPArray(0).getPPr().setAlgn(STTextAlignType.CTR);
Ultimately, my question is how can I get the "setAlgn" method to accept 'STTextAlignType.CTR' as an Enum and not as object type 'STTextAlignType'? Thank you in advance very much for your help!
The problem is actually on the first line of your code snippet! Your issue is with
import java.lang.Enum;
CTTextParagraphProperties.setAlgn does take a class of type Enum, but it's not that kind of Enum. It has to be a org.openxmlformats.schemas.drawingml.x2006.main.STTextAlignType.Enum
I'd suggest you switch your imports to be:
import org.openxmlformats.schemas.drawingml.x2006.main.STTextAlignType;
import org.openxmlformats.schemas.drawingml.x2006.main.STTextAlignType.Enum;
You can then set the alignment with things like STTextAlignType.L and it'll work fine
import java.sql.SQLException;
import java.util.ArrayList;
public class UserSearchJB {
public UserSearchJB(){
System.out.println("UserSearchJB");
}
public ArrayList searchRecords(UserDTO udto) throws SQLException{
UserSearchDAO usdao = new UserSearchDAO();
ArrayList list = usdao.searchRecords(udto);
return list;
}
}
//This is the code for javabean using struts flow.
This is for model to transfer the data one component to another component
What is the problem in this program i think it is a basic program in which import two spacial package import java.sql.SQLException; and
import java.util.ArrayList;
I am making a Craftbukkit plugin that has a message in the player count list, Like HIVE-MC or Omega Realm. I am coding in Ecplise and using ProtocolLib v3.2.0 and Craftbukkit 1.7.2 R0.3. I am new to java and don't understand it much. I do know that everything is imported.
So far, here are the imported methods, code, and the error
Methods:
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerOptions;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
Code:
private List<WrappedGameProfile> message = new ArrayList<WrappedGameProfile>();
public void onEnable() {
if(!new File(getDataFolder(),"RESET.FILE").exists()){
try {
getConfig().set("PCMessage",
Arrays.asList(new String[]{"First Line", "Second Line"}));
new File(getDataFolder(),"RESET.FILE").createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
saveConfig();
for (String str : getConfig().getStringList("PCMessage"))
message.add(new WrappedGameProfile("1", str));
ProtocolLibrary
.getProtocolManager()
.addPacketListener(
new PacketAdapter(
this,ListenerPriority.NORMAL,
Arrays.asList(new PacketType[] {PacketType.Status.Server.OUT_SERVER_INFO}),
new ListenerOptions[] { ListenerOptions.ASYNC })); {
}
}
Error:
Cannot instantiate the type PacketAdapter
As you will see in the Javadocs for PacketAdapeter, it is declared as:
public abstract class PacketAdapter implements PacketListener
abstract means the class is not a full class, and must be implemented as a full class or anonymous class, it cannot be instantiated. You need to find a subclass of PacketAdapter, or make one yourself.
For more information, see the Java Tutorial for Abstract Methods and Classes.