Is there any kind of way to generate HTTP request within a servlet, dispatch it to the server and get back the answer delivered to the servlet? Or are the servlets meant only to respond to passed requests, not generate them?
(I asked a similar question here: [Code] ..... but no luck)
I want to write a little java program that when ran it will add information to my host file. A screen will pop up with a button on it. When you click the button it will add a few ip to domain connections. In order to edit the host file with notepad you must first give notepad admin privileges. I can't find a way to do this and I'm extremely fresh to programming. Is there a way I can write directly to the file or is there a way to run notepad with elevated privileges?
I have gf 4.0.1 and swing client. I want to get EJB over SSL. I've set all certificates. However, I can get it work only when client and server are at the same host. What I see in tcpdump when they are at the same host:
I want to encrypt a file and decrypt it on another host. For decryption on another host I guess I need to transfer the cipher... how can this be done? How can you write a Cipher to disk?Or am I completely on a wron track?
The following code is doing it already on one host:
I have a Linux Server Debian 7 x86_64 Minimal With java version "1.7.0_65" installed..Its an online Game Server wich Players can join just like other Services.Every 10 - 15 minutes all the players get kicked from the server and get this messege: "internal exception: java.io.ioexception: an existing connection was forcibly closed by remote host"
The players can't join the server for 10 seconds and the server console doesn't show anything for 10 seconds.it doesnt show that the players even left! and when the players try to join they get htis messege: "same nick is already playing"
After 10 seconds everything will work and players can join again and server console say that everyone left and joined..But that happens again after 10 minutes and im losing lots of players because of this error.
I am just learning how to throw exceptions, and I'm stuck on the last part,
Here is where I created the exception that receives a string consisting of ID and wage.
public class EmployeeException extends Exception { public EmployeeException(String Employee) { super(Employee); } }
Here is where I created the Employee class with the two fields. I also believe I am throwing the exception if the hourly wage is < $6 or > $50.
public class Employee { int idNum; double hourlyWage; public void Employee(int empID, double empWage) throws EmployeeException { idNum = empID; hourlyWage = empWage;
[Code]...
Now, I need to write an application with three employees and display a message when an employee is successfully created or not. This is what I have so far... I'm trying to get it to work with one employee, and then I can easily go back and add two more.
import javax.swing.*; public class ThrowEmployee { public static void main (String[] args) { try { Employee one = new Employee(542, 15.20); }
[Code
The current compile error that I'm receiving is: ThrowEmployee.java:12: error: constructor Employee in class Employee cannot be applied to given types;
Employee one = new Employee(542, 15.20); ^ required: no arguments found: int,double reason: actual and formal argument lists differ in length 1 error
I have public void Employee(int empID, double empWage) in my Employee class, so why is it saying that no arguments are required? Not sure if I'm missing a step with throwing exceptions, because this error has always been a simple fix when I've come across it in the past?!?
In my EJB modules, to prevent that any JPA exception is ever thrown, I check the condition that would cause the exception beforehand. For example, the exception javax.persistence.EntityExistsException is never thrown because, before persisting the entity, I check if such primary key already exists in the DB. Is it the right way to do this?
Another approach is too allow the JPA exceptions to be thrown and catch them in a try-catch block, and then throw my custom exception from the "catch" block. However it requires to call EntityManager.flush () at the end of the "try" block. Otherwise the exception throw could be deferred and never be caught by my block.
There are times that my methods need to report the caller about many kinds of errors, represented as checked exceptions. This makes my methods look like very convoluted. It happens mostly when I work with stateless EJBs and databases. Sometimes I end throwing even 8 different exceptions! Are they too many?
Many of them inherit from common exceptions, so I've been tempted to throw the parent classes. But I've quickly discarded that option because I've read that it's a bad practice, since a method may throw only a subset of the children of that parent class, not all.
Finally, I've studied these possibilities:
1. Throwing the parent class (mentioned above). 2. Throwing a common exception with an error ID or code as message. 3. Throwing a common exception with an enum as member, as if it were an ID or code (safer than the #2).
All them show the same defect that the #1. However it's more a conceptual problem than a technical one, because my callers always use the same mechanism to treat every "specialization" of the same exception, without worrying about if the method really can return it or not.
I'm writing a program that accepts three doubles from the user, and performs calculations on them. I want to be able to handle input mismatch exceptions on each individually (i.e., if the user enters a double for the first, then a letter for the second, I'd like to be able to keep the value entered for the first, and only require that the user try again with the second, then the third, etc.)... I tried putting each input instance into its own try/catch blocks, but it always goes back to #1 when an invalid input is entered. Right now, I have all three in one try/catch:
I'm wondering about the use of exceptions to handle errors that might occur during file I/O when the I/O is done by a method implementing an interface's method. The idea is for the interface to provide a uniform way for application code to read (and write, though I'm not addressing that in this post) a document from a file, given a File object that specifies the on-disk location of the document. The "document" can be an instance of any class the application programmer wants it to be, provided that it can be created from a file stored on disk. Here's the interface definition:
public interface DocumentRamrod<T> { public T openDocumentFile(File file) throws FileNotFoundException; }
A simple implementation, when T is a class that just holds a String, might look like this (Please overlook the fact that there is no call to the BufferedReader's close method, as it's not needed for this example.):
public class MyRamrod implements DocumentRamrod<OneLineOfText> { public OneLineOfText openDocumentFile(File file) throws FileNotFoundException { return new OneLineOfText(new BufferedReader(new FileReader(file)).readLine()); } }
But, that one line where the file is read (Line 5) might generate an IOException.To cope with it, I could add a try-catch to the implementation like this:
public class MyRamrod implements DocumentRamrod<OneLineOfText> { public OneLineOfText openDocumentFile(File file) throws FileNotFoundException { try { return new OneLineOfText(new BufferedReader(new FileReader(file)).readLine()); } catch (IOException ex) { Logger.getLogger(MyRamrod.class.getName()).log(Level.SEVERE, null, ex); } } }
Or, I could add that to the list of exceptions defined for the method in the interface, like this:
public interface DocumentRamrod<T> { public T openDocumentFile(File file) throws FileNotFoundException, IOException }
But that's where I'm getting nervous, as it makes me realize that, with an infinite number of possible implementations of openDocumentFile, I can't predict what all the exceptions thrown might be.should I have openDocumentFile simply throw Exception, and let the application programmer sort out which one(s) might actually be thrown, should I keep listing them as it become clear which ones are likely to be thrown, or should I not have openDocumentFile throw any exceptions and let the application programmer deal with it in the implementation of openDocumentFile (with try-catch blocks, etc.)? In Good Old C, I'd have passed back a null to indicate some general failure, with the various callers up the call-stack having to either deal with it or pass that back themselves (until some routine up the stack finally did deal with it), but that seems like an approach the whole exception mechanism was designed to avoid.
I'm thinking the right choice is to have openDocumentFile throw Exception, and let the application programmers decide which subclasses of Exception they really want to deal with. But I have learned to be humble about the things I think, where Java is concerned,
I am having some difficulties grasping the concept of throwing your own exceptions. How do I get this to repeatedly ask the user to enter a valid value for hours. Also i am having difficulties in the method with using the throw new InvalidHrExcep("That value is invalid"); i cannot get this to work.
public class exceptionProgram { static Scanner console = new Scanner(System.in); public static void main(String[] args) throws InvalidHrExcep { int day=0; int month = 0; int year=0; int hours=0; int minutes=0; int seconds=0;
class A { final Object b; public A(C c) { try { b = c.someMethodThatMayThrowSomeException(); } catch (SomeException e) { b = null; // This line results in compiler error: "variable b might already have been assigned" } } // take away b=null line and you get "variable b might not have been initialized" on this line }
Why? How could 'b' be assigned if the exception was thrown?
currently we can able to monitor all calls given to this class but whenever any exception thrown in this class hierarchy we are not able to track it on exceptions.jsp of JAMON
I am designing/coding a blackjack GUI program and I'm trying to add function to my JButtons. Problem is, I now have 2 NullPointerExceptions.
public class GameConsole { Player user; Player dealer; Deck playingDeck; ValidateInput validate = new ValidateInput();
[Code] .....
I am trying to do. I am getting the following exception/stack trace at line 14 in userTurn()
Exception in thread "main" java.lang.NullPointerException at blackjackControls.GameConsole.userTurn(GameConsole.java:163) at blackjackControls.GameConsole.gamePlay(GameConsole.java:87) at blackjackControls.Main.main(Main.java:7)
and then the program continues and after I click the button I get :
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at blackjackControls.GameConsole.userTurn(GameConsole.java:163) at blackjackControls.ResultPanel$1.actionPerformed(ResultPanel.java:34) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028) //and then about 30 more "at" lines
Why am I getting these exceptions and how do I fix it?
I am having some serious difficulty getting my project off the ground. I have the following code:
FileInputStream file = new FileInputStream(new File("src/retestchecker/test_sheet.xlsx")); //Get the workbook instance for XLS file XSSFWorkbook workbook = new XSSFWorkbook(file); //Get first sheet from the workbook XSSFSheet sheet = workbook.getSheetAt(0); Row row = sheet.getRow(0); Cell x = row.getCell(3); System.out.println(x);
Everything is properly imported, etc etc.. But I am getting this error and I am not sure what it means:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException at retestchecker.RetestChecker.main(RetestChecker.java:23) Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
[Code] .....
Java Result: 1
I am using Netbeans and the latest version of Apache POI that was released May 11, 2015.
The line 23 that the error refers to is this line:
I'm trying to stress test JavaFX and I'm on Window 8.1 using 1.8.0_20-b26. I have an application that has many objects on the scene with animation timers and overall it purposefully runs very slow. I have listeners on the root AnchorPane for touch input and if I generate many touch point events after a few minutes I get "Too many touch points reported" exceptions (posted below) and the app of course no longer responds to touch input. Is it possible to catch the exception and then reset the scene touch input so it goes back to normal without restarting the application? If it lost any current touch input that's fine.
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: Too many touch points reported at javafx.scene.Scene$ScenePeerListener.touchEventNext(Scene.java:2686) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleNextTouchEvent$346(GlassViewEventHandler.java:1090)
There is a method taken from a class with several try and catch blocks. If you think it is possible, add one more catch block to the code to catch all possible exceptions, otherwise say 'Not possible' with your reason.