org.apache.struts.ServletException :JavaBean is not found - java

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;

Related

Have a problem with packages not getting recognized [duplicate]

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

IllegalArgumentException when using GSON's fromJson()

I have this exception when trying to parse a JSON file with GSON:
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: class com.sun.javafx.jmx.HighlightRegion declares multiple JSON fields named hash
I have tested a little to what causes this, and I found that it only occurs when I create a Object that has an Event object as a member. In this case, I am trying to create a List of Quest objects that eventually have Event objects.
package Quests;
import Events.EventSequence;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Quest {
public static void parseQuest() {
Gson gson = new Gson();
FileReader questGSON;
try {
questGSON = new FileReader(QUEST_FILE);
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}
JsonObject questJSON = gson.fromJson(questGSON, JsonObject.class);
questList = new ArrayList<>();
for(Map.Entry<String, JsonElement> element : questJSON.entrySet()) {
questList.add(gson.fromJson(element.getValue(), Quest.class));
}
}
}
I am using javafx in that class in the following way:
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
public abstract class Event implements EventHandler<ActionEvent> {
// members of this class
private String title, text;
private Button[] buttonSet;
protected Entity other;
protected Event nextEvent;
public abstract Event chooseNewEvent(String command);
#Override
public void handle(ActionEvent event) {
// Get the name of the button
String command = ((Button) event.getSource()).getText();
displayNewEvent(chooseNewEvent(command));
}
}
The only information I could find regarding this was:
https://github.com/wpilibsuite/shuffleboard/issues/358
Could someone point me in some direction to fix my bug?
I found out that it was a Button array from javafx.scene.control.Button in my Event class that was causing the problem. I fixed it by making it transient so it would get ignored by GSON and not cause any problems.
Nevertheless, I have no idea why the Button array would cause this exception. Any thoughts?

Passing an Enum to a method as a parameter in Java?

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

Error when using ProtocolLibrary PacketAdapter()

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.

Issue with missing class DataEntry

probably a very simple issue related to importing the correct libraries but I cannot seem to find anything to help me.
Basically getting this error when trying to run my code:
"Cannot find a class or type named "DataEntry"
This is my Code here:
//Variables
UnfoldingMap map;
List<Marker>countryMarkers;
HashMap<String, DataEntry> dataEntriesMap;
//Core methods...
void setup() {
size(800, 600);
smooth();
map = new UnfoldingMap(this);
MapUtils.createDefaultEventDispatcher(this, map);
//Read in GeoJSON File - Countries
List<Feature> countries = GeoJSONReader.loadData(this, "countries.geo.json");
countryMarkers = MapUtils.createSimpleMarkers(countries);
map.addMarkers(countryMarkers);//Add the countries to the map
//External Data source - CSV file
}
void draw() {
map.draw();
}
//Other methods required...
This is a list of all my Imports
import de.fhpotsdam.unfolding.mapdisplay.*;
import de.fhpotsdam.unfolding.utils.*;
import de.fhpotsdam.unfolding.marker.*;
import de.fhpotsdam.unfolding.tiles.*;
import de.fhpotsdam.unfolding.interactions.*;
import de.fhpotsdam.unfolding.ui.*;
import de.fhpotsdam.unfolding.*;
import de.fhpotsdam.unfolding.core.*;
import de.fhpotsdam.unfolding.data.*;
import de.fhpotsdam.unfolding.geo.*;
import de.fhpotsdam.unfolding.texture.*;
import de.fhpotsdam.unfolding.events.*;
import de.fhpotsdam.utils.*;
import de.fhpotsdam.unfolding.providers.*;
import processing.opengl.*;
import java.util.List;
import java.util.HashMap;
I am experimenting with GeoSpatial data using Processing and the Unfolding Map Library.
I'd appreciate any help guys.
I am not entirely familiar with the packages you are using but based on examples I've seen, it seems as though you are missing an inner class.
Try updating the code as indicated below noting the DateEntry inner class at the very bottom:
//Variables
UnfoldingMap map;
List<Marker>countryMarkers;
HashMap<String, DataEntry> dataEntriesMap;
//Core methods...
void setup() {
size(800, 600);
smooth();
map = new UnfoldingMap(this);
MapUtils.createDefaultEventDispatcher(this, map);
//Read in GeoJSON File - Countries
List<Feature> countries = GeoJSONReader.loadData(this, "countries.geo.json");
countryMarkers = MapUtils.createSimpleMarkers(countries);
map.addMarkers(countryMarkers);//Add the countries to the map
//External Data source - CSV file
}
void draw() {
map.draw();
}
public class DataEntry {
String countryName;
String id;
Integer year;
Float value;
}

Categories