java

@Async not working for me

I am using @Scheduled and it have been working fine, but can't get the @Async working. I tested it many times, and seems that it is making my method asynchronous. Is there any other thing, configuration, or parameter I am missing? I have one class that has two methods one, the method marked with @Scheduled, executes and calls the second ...

why I got "org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted exception?

I wrote this code but the mentioned exception thrown. what's wrong, please help? this is the code : //-*-*- FileInputStream input = new FileInputStream("cv.xml"); XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(input); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); ...

How to find all implementations of a certain interface?

I want to make my program initialization a bit "smarter". I have several classes which represent commands. All these classes are immutable (i.e. creating only one instance of each should be enough for the whole application). All these classes implement Command interface. I think that the fact that some classes are placed in the same ...

Sizeof unknown type object

I have to get size of object which type I does not know. It's a template where I want to achieve sth like this: void sth(T data) { System.out.println("Data size = ", sizeof(data)); } How I can do this in Java? sizeof - like a C sizeof ;) ...

Overriding default accessor method across different classloaders breaks polymorphism

Hello. I come across to a strange behavior while trying to override a method with default accessor (ex: void run()). According to Java spec, a class can use or override default members of base class if classes belongs to the same package. Everything works correctly while all classes loaded from the same classloader. But if I try to load...

Trying to use jdbc driver for postgresql but it's not working

I have added the jdbc driver to my classpath as far as I know i.e. I added the following to my .profile export CLASSPATH=$CLASSPATH:location/to/the/jarfile.jar When I compile my java program I always get this error javac v9.java v9.java:8: <identifier> expected Class.forName("org.postgresql.Driver");//load the driver ^ v9.j...

Basic Android alarm app, Broadcast Receiver's onReceive() method not being called.

Hi, I am working on an alarm app. I followed the Android AlarmController tutorial word for word with only some minor changes. For some reason my Broadcast Receiver's onReceive() method is not being called when the alarm goes off. Here's the code: // the callback received when the user "sets" the time in the dialog private TimePickerD...

setMaximumSize not working in java

I hava a java program with a JFrame I am using absolute positioning here is my main function public static void main(String[] args) { ape Ape = new ape(); Ape.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Ape.setSize(1000,1000); Ape.setMinimumSize(new Dimension(1000,1000)); Ape.setMaximumSize(new Dimension(1000,1...

How to concisely create a String that begins with a primitive value without using an empty double-quote?

To get a newString value of "99 bottles": int x = 99; String fruit = " bottles"; To form a new String I do this: String newString = "" + x + fruit; since this is not allowed: String newString = x + fruit; But there's something about using the double quotes here that doesn't seem right. Is there a better way to do this (without ...

Whats better in the job market, and what has a better future: Java or C#?

I've learned a lot of programming language, and I think that Java or C# are most likely the best for getting a job, but I was wondering if I am correct in thinking this, or are there other popular languages I should know about? ...

Java null pointer exceptions - don't understand why...

Run time error on main method in MovieList.java. I'm not sure my program design is fundamentally very good, but I'd like to know why it crashes. Thanks in advance. package javaPractical.week3; import javax.swing.*; public class Movie { //private attributes private String title; private String movieURL; private String ...

Need Compilers on Server

Hello, I'm looking to build a web service that can compile some entered code (probably C/Java) and can run some tests on it. What kind of design should I follow? What compiler can I place on my server to do the job? Recommendations? Pros? Cons? ...

.Net (C#) Enum rewritten to java

I have an Enum in .Net. How can I rewrite this Enum in java? Here is the Enum: public enum AdCategoryType : short { ForSale = 1, ForBuy = 2, ForRent = 8, WantingForRent = 16, WorkIsWanted = 32, WorkIsGiven = 64 } ...

Using openSession() over getCurrentSession() - when and why?

This question is in relation to another question I have asked, but what are the reasons as to why you would use openSession() over getCurrentSession()? I know you would use openSession() so that you could self-manage the closing and flushing of the session, however, why would you want to do this manually? I have used openSession() when...

Java : Clearing StringBuffer contents

All, I was wondering if clearing a StringBuffer contents using the setLength(0) would make sense. i.e. Is it better to do : while (<some condition>) { stringBufferVariable = new StringBuffer(128); stringBufferVariable.append(<something>) .append(<more>) ... ; Append stringBuff...

java adding data to a JTable with a for-loop

i need some help writing a for-loop please but i can't get it. i need to add the numbers 0 to 63 in a table like this: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 etc. for (int j = 0; j < 8; j++) { for (int i = 0; i < 8; i++) { table.setValueAt(""+(i+(j)), i, j); } } but the inputted values are not correct can you please help ...

How to get a specific attribute from a object list ?

I've an array keeping a list of "Group" objects. I want to set this list to the dropdownchoice component. However I want to show the end user only the name attribute of Group objects, and then get the selected values' id attribute to add database. What to do? Thanks private List<Group> groupTypes; DatabaseApp db = new DatabaseApp(); gro...

Update JscrollBar without resetting position

I have a class which extends JScrollPane, its viewport is another class which extends JComponent and implements Scrollable. When the size of the component changes the JscrollBars do not update unless I call revalidate() however this resets the position of the scroll bars to the top left. Is there a way of updating the size of the scroll ...

Maven war plugin not able to exlude libs in exploded war format..

Hi, I am using maven war plugin to exclude some common jar and put them in the classpath. I am able to generate war file properly which excludes specified libs and add them in the classpath but exploded war directory still contains excluded libararies. How can I generate exploded war file which use configuration of maven war plugin. ...

captcha image coming back a binary data? How to display this?

I am retrieving a captcha image from the Java based package "SimpleCaptcha" On the front end I just put the following in my page and I get a captcha image: <img src="stickyImg" /> I want to reload this captcha image onclick using javascript. I tried: $("#theclickhandler").click(function(){ $("#stickyImg").load('stickyImg', fu...