java

Java NullPointerException When I call a method on a custom class

I get a null pointer exception when a call a method on a custom class. I do not see why my object p of class Player is null. (Player is a class of Players of my game) play is the method. This class should create n number of p objects of the Player class and run the play method on them. import java.util.*; public class PsychicGameMore ...

java.util.ConcurrentModificationException in Non Multithreaded Program,

Hey SO Guru's im having one heck of a job with this code public void kill(double GrowthRate, int Death) { int before = population.size(); for (PopulationMember p : population) { int[] probs = ProbablityArrayDeath(GrowthRate,Death,(int)p.fitness()); if (probs[RandomNumberGen.nextRandomInt(0, 99)]==0) ...

Multilingual virtual keyboard in java

Hi all, I am planning to create a multi lingual keyboard using Java. can u give some ideas or suggestions for doing that? Is there any open source code or interface which i can use in my code? ...

Java: Code Review: Binary Search

I wrote this for self education. How does it look? (It passes all my junit tests.) /** * find needle in haystack * @param haystack a sorted list * @param needle * @return i such that <code>haystack[i] == needle</code>, or -1 if it is not found */ public static int find(char[] haystack, char needle) { int minWindow = 0; // lower ...

Overwriting existing data in external file, how do i stop this?

When new data is entered in the GUI and exported to the following file it replaces the existing data, how would i prevent this and make it add to the existing data? thanks public void exportContacts() { FileOutputStream file; PrintStream out; try { file = new FileOutputStream("../files/example.buab"); out...

Using spring beans from other modules?

I imagine this is simple - but I can't find the right combination of search terms to get an answer. If I have a multi-module application, how do I get the beans in module A available to the beans in module B. The project setup looks a little like this: project.ear/module-a.jar/resources/beans.xml project.ear/module-a.jar/java/foo/bar.c...

ksoap2 complex parameter

I need to call a web service using ksoap2, I have been doign this successfully up till the point where I need to pass a more complex type to the web service. Does anybody have an example of passing a complex type to a webservice, preferably, only using SoapObject (the object in question is only Strings and dateTimes. Thanks in advance ...

Importing a file using the Java FileChooser

Hi I'm having trouble using the Java JFileChooser and was wondering if anyone could help me out. It's probably something really simple but I just cant spot whats wrong. The JFileChooser window opens fine when I click my import button and I can navigate to any field but I just cant read them into my JTextFields. Heres my JFileChooser m...

Getting hold of the outer class object from the inner class object

I have the following code. I want to get hold of the outer class object using which I created the inner class object inner. How can I do it? public class OuterClass { public class InnerClass { private String name = "Peakit"; } public static void main(String[] args) { OuterClass outer = new OuterClass(); Inne...

In a spring messages.properties, how to ensure line break of error message when using an error code as key ?

In messages.properties: error.code=This is error message.\nThis is next line of error message. Now, when I set "errors.rejectValue" with this "error.code" for a form field, I cannot get the line break of '\n' to display on the jsp page when displaying the error message using the form:errors element. Instead of '\n', using <br/> also ...

Lisp code called from Java

Hello, Long story: I am doing a project for my functional programing class, and I thought of writing an AI controller in Lisp, for the Mario AI competition. I was looking over frameworks/libraries/ways of calling Lisp code from Java, or even better Lisp-Java intercommunication. I have looked at Jacol, but it is old, and it does not ...

Make Java runtime ignore serialVersionUIDs?

I have to work with a large number of compiled Java classes which didn't specify explicitly specify a serialVersionUID. Because their UIDs were arbitrarily generated by the compiler, many of the classes which need to be serialized and deserialized end up causing exceptions, even though the actual class definitions match up. (This is all ...

Why am I getting SQLSyntaxErrorException - encountered "" ?

This method keeps throwing the exception in the title, and I cannot find a reason, I have created other tables through the connection and all the referenced tables have been created. I'm using embedded JavaDB. private void createEvidenceTable() throws SQLException { Statement evidenceTable = CONNECTION.createStatement(); evidenc...

What does Tool/Bundle-Name/Export-Package etc. mean in a jar manifest

I'm looking at the manifest.mf for some apache libraries. While I can guess what Export-Package means, I can't find any documentation for these attributes ? Could anyone point me in the right direction. Here.s an example: Manifest-Version: 1.0 Created-By: 1.6.0_07 (Sun Microsystems Inc.) Built-By: pemben Implementation-Title: Commons Be...

How do I check if a file exists? (Java on Windows)

How can I check whether a file exists, before openinging it for reading in Java? (equivalent of Perl's -e $filename). The only similar question on SO dealt with writing the file and was thus answered using FileWriter which is obviously not applicable here. If possible I'd prefer a real API call returning true/false as opposed to some...

Using Resteasy with javassist?

I'm trying to use resteasy to serve out some entities fetched by spring-hibernate. I've configured one method which returns a POJO and works as expected: @GET @Path("/test") @Produces(MediaType.APPLICATION_XML) public Episode getTestEpisode() { Episode e = new Episode(); e.setEpisodename("test"); return e; } Produces: <episod...

Is there a way to force a classloader to load a package even if none of its classes have been loaded?

Let's say a java codebase has a package called "com.example". At runtime, we can get this Package by calling Package p = Package.getPackage( "com.example" ); //(returns null) or even get a list of all packages by calling Packages[] ps = Package.getPackages(); The problem is - if the ClassLoader has not yet loaded any class from th...

Java short circuit evaluation

I thought Java had short circuit evaluation, yet this line is still throwing a null pointer exception: if( (perfectAgent != null) && (perfectAgent.getAddress().equals(entry.getKey())) ) { In this case perfectAgent is null, so I just want the whole expression to return false, but my app is still crashing on this line with a NullPointer...

How to reuse fieldlength in form, validation and ddl ?

I'm working on an Spring application with lots of input forms. I'd like to reuse the field length in the UI-form, validation and JPA annotations. Is there an elegant way to solve this. My solution at the moment is, to use constants to declare the length: public class Person { public static final int FIRSTNAME_LENGTH = 25; @Column...

Java Stanford NLP: Find word frequency?

I'm using the Stanford NLP Parsing toolkit. Given a word in the lexicon, how can I find its frequency*? Or, given a frequency rank, how can I determine the corresponding word? *in the entire language, not just the text sample. This is a demo of the toolkit I'm using: class ParserDemo { public static void main(String[] args) { Le...