w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to add (read) java.io.FilePermission to my /usr/share/java/mysql-connector-java.jar for a java applet using MySQL on Ubuntu?
java.security.AccessControlException: access denied (java.io.FilePermission /usr/share/java/mysql-connector-java.jar read That means that you need to either: Add an AllPermission covering that file or directory to the .policy file that is active when the applet executes. Add an explicit java.io.FilePermission read ditto. And it doesn't mean anything else. Most of your post is therefore irrelevant: specifically, your points 1, 2, 5, 6, and 7. Sign the JAR file. This is by far the best solution. It solves that problem and many others. The fact that your 'applet is not a runnable jar file' has nothing to do with whether you should sign it.

Categories : Java

Java: Unable to fix unchecked conversion required java.util.Collection
If oldV is declared as a Vector<String> just use the parameterized version of 'LinkedHashSet': Vector<String> newV = new Vector<String>( new LinkedHashSet<String>(oldV) ) you can also use the annotation @SuppressWarnings if you just want to get rid of the warnings: @SuppressWarnings("unchecked") Vector<String> newV = new Vector<String>( new LinkedHashSet(oldV) );

Categories : Java

Java "ajp-9009-AsyncTimeout" java.lang.OutOfMemoryError: Java heap space Errors
Without specifics, it's difficult to identify your issues. I would look at tools like YourKit to profile your app (you can get a free 30 day trial, ISTR) and VisualVM to dig down into your JVM. But, if your webservice takes your 100,000 records, renders them into XML/JSON and sends them out in one request/response, then that's a lot of data to pull from the db, marshall and transmit. I would investigate that design and see if that's the fundamental issue.

Categories : Java

How to use Maven to build a Java EE project with Java class references to several dependent Java projects?
You are getting this error because you are trying to join everything with maven pom file where packaging node is set to war: war/ +--- project 1 - jar/ | +--- project 2 - jar/ instead you have to reorganize your project and join everything in project with packaging type set to "pom" pom/ +--- war/ | +--- project 1 - jar/ | +--- project 2 - jar/ Maven requires parent pom to be of type "pom".

Categories : Java

Getting error A message body writer for Java class java.util.ArrayList/List was not found
You should add at least a getter in your StringWrapper. Without public attributes, there is nothing to serialize. So the output is correct. If you do not want a tag around the list of your strings, you can mark a single getter with @XmlValue. @XmlRootElement public class StringWrapper { public StringWrapper (){} List<String> list=new ArrayList<String>(); public void add(String s) { list.add(s); } @XmlValue public List<String> getData() { return list; } }

Categories : Java

java mysql java.lang.OutOfMemoryError: Java heap space
The code never closes the connection to the database. Try creating/closing the connection in the insertCat method. Connections should be obtained and released as quickly as possible. The connection should only be open for the necessary amount of time to perform the persistence operation. public class model { public synchronized void insertCat(String parola, String categoria){ Connection connect = null; try{ Class.forName("com.mysql.jdbc.Driver"); connect = DriverManager.getConnection("jdbc:mysql://localhost/system?user=keyword_tool&password=l0gripp0"); PreparedStatement statement = connect.prepareStatement("insert into sostantivi (nome, categoria) values (?, ?)"); statement.setString(1, parola); statem

Categories : Java

java.lang.UnsatisfiedLinkError: no lwjgl in java.libary.path at java run
Okay my current command is: java -cp bin;.;lib/lwjgl.jar;lib/slick-util.jar; -Djava.library.path="D:devLWJGLlwjgl-2.9.0 ativewindowslwjgl.dll" Change that to: java -cp bin;.;lib/lwjgl.jar;lib/slick-util.jar; -Djava.library.path="D:devLWJGLlwjgl-2.9.0 ativewindows" The -Djava.library.path is a search path; i.e. a list of places to look for the lwjgl.dll file.

Categories : Java

A message body reader for Java class java.util.List, and Java type java.util.List<>, and MIME media type text/html was not found
I deleted all generated classes and all restful classes and the GroupUClient then the program works without problems. change from public ChatuserClient() { com.sun.jersey.api.client.config.ClientConfig config = new com.sun.jersey.api.client.config.DefaultClientConfig(); client = Client.create(config); webResource = client.resource(BASE_URI).path("entities.chatuser"); } to public ChatuserClient() { com.sun.jersey.api.client.config.ClientConfig config = new com.sun.jersey.api.client.config.DefaultClientConfig(); client = Client.create(config); webResource = client.resource(BASE_URI).path("entities.service.chatuser"); }

Categories : Java

Java convert hex string to java: char[] (C) to byte[] (JAVA)
What you have in C would be this in Java: byte[] tab = { 0x02, 0x04, (byte) 0xF3, (byte) 0xFC, (byte) 0xFF, 0x06, 0x00, (byte) 0xF7, 0x00, 0x00, 0x09, (byte) 0xFD, (byte) 0xFD, 0x00, 0x03, 0x0A, (byte) 0xFD, 0x02, (byte) 0xFD, 0x08, 0x08, 0x00, 0x01, (byte) 0xFD }; Note that instead of char you use byte, and that values that are outside of the allowed range for byte such as 0xFD need an explicit cast. And you don't include the array length in the declaration. Update: To not add casts manually you can declare the data of a wider type (like int or short) and then loop over it: int[] temp = { ... }; byte[] tab = new byte[temp.length]; for (int i = 0; i<temp.length; i++) tab[i]=(byte)temp[i]; A better solution would be loading the dat

Categories : Java

xception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1703, Size: 1699 at java.util.ArrayList.rangeCheck(ArrayList.java:604)
For int, contains looks up the value, while remove remove the element at the index. So after a number of deletions, the number near the end might have a smaller index, e.g., 0, 1, 2 -> 0, 2 So here contains(2) will be true, but remove(2) gives you an exception. Also, remove does have a variant that removes the first occurrence of the object.

Categories : Java

Lambda Expressions java 8 exception : java.lang.NoSuchMethodError: java.lang.invoke.LambdaMetafactory.metaFactory
I found that your example compiles fine for the latest beta. Not sure what you are trying to evaluate but I did a similar test as follows: public class LambdaTesting { public static String[] strs = { "a", "aa", "aaa"}; public static void main(String args[]) throws Exception { ExecutorService pool = Executors.newFixedThreadPool(3); Set<Future<Integer>> set = new HashSet<Future<Integer>>(); for (String word : strs) { Callable<Integer> c = (() -> word.length()); Future<Integer> future = pool.submit(c); set.add(future); } int sum = 0; for (Future<Integer> future : set) { sum += future.get(); } System.out.printf("The sum of leng

Categories : Java

java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer in java 1.6
Use: ((Long) userService.getAttendanceList(currentUser)).intValue(); instead. The .intValue() method is defined in class Number, which Long extends.

Categories : Java

Error occurred during initialization of VM java.lang.UnsatisfiedLinkError: java.lang.Float.floatToIntBits(F)I in java
You should use the jdk6 variant of JBoss built (http://sourceforge.net/projects/jboss/files/JBoss/JBoss-4.2.3.GA/jboss-4.2.3.GA-jdk6.zip/download)

Categories : Java

Can a Java Factory class be structured to instantiate either Java 6 or Java 7 specific class based on JVM version?
You can do this without having to worry about the versions. You can even build the "Java 7" to run on Java 6, but won't work because it needs classes which are not there. i.e. you can have one JAR which runs in Java 6 for them all. Also you don't need to use reflection.

Categories : Java

java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long
Use BigInteger#longValue() method, instead of casting it to Long: return firstResult.get(0).longValue(); Seems like firstResult.get(0) returns an Object. One option is to typecast to BigInteger: return ((BigInteger)firstResult.get(0)).longValue(); But don't do this. Instead use the way provided by Nambari in comments. I'm no user of Hibernate, so I can't provide Hibernate specific solution.

Categories : Java

pig join with java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
First I'd define a simple schema for the inputs. Based on your example I assume that your inputs are text files. Now you get the ClassCastException because just applying the schema (f1:int, f2:int) unfortunately won't do any conversion. You need to explicitly cast the output schema of STRSPLIT to (tuple(int,int)) so that flatten can generate f1:int and f2:int from it. I.e: d1 = LOAD 'data1' as (line:chararray); d2 = foreach d1 generate flatten((tuple(int,int))(STRSPLIT($0, ' +'))) as (f1:int,f2:int); d3 = LOAD 'data2' as (line:chararray); d4 = foreach d3 generate flatten((tuple(int,int))(STRSPLIT($0, ' +'))) as (f1:int,f2:int); data = join d2 by f1, d4 by f2;

Categories : Apache

java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Scanner.java:1585)
Allocate the Scanner at the start of your code, not each time through the loop: int level = 1; Scanner reader = new Scanner(System.in); String selection = null; while (true) { if (data.done) { level--; } data.done = false; System.out.println(getSubmenu(level, data)); if (level <6) { selection = reader.nextLine(); } else { level = 4; } if (validSelection(selection)) { level = getLevel(level, selection); data = getData(level, data, selection); } else { System.out.println("Invalid entry"); } if (data == null) { System.out.println("Level "+ level + "selection " + selection); break; // exit command was typed } } reader.close(); The way you were doing it, each Scanner that

Categories : Java

java.lang.ClassCastException: java.lang.StackOverflowError cannot be cast to java.lang.Exception
Well the cause of the stack overflow is simple: class Test_A { Test_B b = new Test_B(); } class Test_B { Test_A a = new Test_A(); } Constructing an instance of Test_A involves constructing an instance of Test_B, which involves constructing an instance of Test_A etc. You should redesign your classes to remove this cyclic dependency. (There are alternatives which keep the dependency, but add parameterized constructors - while those could work, breaking the dependency would be a much better bet.) The ClassCastException is presumably some broken bit of code casting Throwable to Exception - unfortunately we can't tell where that broken bit of code is without the stack trace. It may not even be your code.

Categories : Java

Java on Windows: Test if a Java application is run as an elevated process (with Administrator privileges)
This is what the Eclipse LocationManager does to determine if it can write to the install directory: public static boolean canWrite(File installDir) { if (installDir.canWrite() == false) return false; if (!installDir.isDirectory()) return false; File fileTest = null; try { // we use the .dll suffix to properly test on Vista virtual directories // on Vista you are not allowed to write executable files on virtual directories like "Program Files" fileTest = File.createTempFile("writtableArea", ".dll", installDir); } catch (IOException e) { //If an exception occured while trying to create the file, it means that it is not writable return false; } finally { if (fileTest != null) fileTest.delet

Categories : Java

Distributing a java plugin's functionality elegantly - general Java / OOP noob issue
If I understood you right you want a Bukkit Plugin to change Weather, Time, list online players and so on. But you shouldn't spilt that all up. It is easier for you if you do that in one Project. If you want a organised plugin you only should use packages and classes. The bukkit wiki shows you how to do it. Bukkit Plugin Tutorial I use it myself for my plugins.

Categories : Java

Compiling a Java project on Unix using external library mysql-connector-java-5.1.24-bin.jar
try putting individual jars like -classpath ".:/home/myname/SQLtest/lib/mysql-connector-java-5.1.24-bin.jar" and moreover it is a good idea to add the jars into permanent classpath environment vairable and export that.

Categories : Java

Java-6 to Java-7 Kerberos - breaking behaviour change sessionKey now AP-REQ.Authenticator.subkey
I don't see anything in the ExtendedGSSContext.inquireSecContext() doc to indicate that it returns the subkey if present for KRB5_GET_SESSION_KEY; do you know from some other source that it does? In any case, using the subkey is what you need to do. I would look at it this way: your original implementation was not correct, because the WSS Kerberos doc clearly states that the subkey is to be used if present. It just happened to work because the Java 6 Kerberos library did not generate a subkey. Now that one has appeared your bug is revealed, and you have to fix it. I'm not familiar with WSS, but the doc seems to indicate that you can choose various encodings for the token, and one is to use GSSAPI instead of a Kerberos AP-REQ directly. Perhaps if you had used GSSAPI to begin with, it woul

Categories : Java

java: Preventing malicious change or modification on some public functions in java packages
You can sign your code to prevent someone from changing it and giving it to someone else pretending it is the "official" version. You cannot prevent anyone from making changes to code they are running themselves. If they break the program that way, that is their fault. If they can break your system that way (such as gain unauthorized access to other people's files), then this is a design flaw in your system. You cannot depend on client software not being modified. Code that must not be tampered with needs to run on your machines and be accessible as a service. Practical example: Instead of checking a password and then granting access to a local file or not (which can be circumvented by changing that code), encrypt the file with the password (so that there is no way to access it if you d

Categories : Java

Can Oracle DBMS return a Java object from a Java stored procedure call?
What you need to do is, serialize and de-serialize java objects to and from Oracle database table. You can store the serialized object bytes in Oracle table using BLOB column type. Here is a link describing how you can store and retrieve java objects from a table. http://asktom.oracle.com/pls/apex/f?p=100:11:0::::p11_question_id:1285601748584

Categories : Java

Java tutorial sample code throws: java.net.SocketException: Connection reset - what does cause it?
Your code is working fine for JVM's that can connect to the internet. Based on the original question and discussion: http://chat.stackoverflow.com/rooms/31264/discussion-between-achingfingers-and-meewok it seems that either: An intermediate firewall is blocking the JVM from making the connection (or another similar network issue). An operating system firewall, or antivirus that is causing the problems as well. My suggestion is to try: Same app on different computer within same network (to see if it is PC specific). Same app on different network.

Categories : Java

java.lang.OutOfMemoryError: bitmap size exceeds VM budget & java.io.FileNotFoundException
Be remember that, each and everytime when your Bitmap did its work then make it null and recycle like mBitmap=null and mBitmap.recycle(). It will clear your Bitmap and application will release that much memory, so your app will not throw an Exception.

Categories : Java

Exception in thread "main" java.lang.NullPointerException on developing games in java
Exception in thread "main" java.lang.NullPointerException at image.ImageFont.load(ImageFont.java:78) You have a NPE (Null Pointer Exception): this means that you have used a variable or an object which has not been initialized yet. Example: Button b; b.setText("Text in my button"); // NULL POINTER EXCEPTION: b is a button but which button?!? Solution Button b = new Button(); b.setText("Text in my button"); // b now is a brand new button and it can be used. You sir have this kind of problem :)

Categories : Java

how caching hashcode works in Java as suggested by Joshua Bloch in effective java?
The hashCode variable in an instance variable, and it's not initialized explicitly, so Java intializes it to 0 (JLS Section 4.12.5). The comparison result == 0 is in effect a check to see if result has been assigned a presumably non-zero hash code. If it hasn't been assigned yet, then it performs the calculation, else it just returns the previously computed hash code.

Categories : Java

Finding root cause of java.lang.OutOfMemoryError: Java heap space using Eclipse MAT
Your stacktrace shows the method UnixFileSystem.list(File) which is a native method and it’s creating a string array for storing the file names. The remaining question is why it is creating an array of size 16 million. The method starts with an array of size 16 and will double it once the directory scan has more iterations than the array size. So the number of iterations now are between 8 million and 16 million. You either have that unbelievable number of files in that directory or there is a problem in the loop termination condition in that native code.

Categories : Java

Unable to rectify the cause during installation of java and setting java path in batch file
Delayed variable expansion: all your variables into parenthesis are evaluated before execution. Here you can't use SETLOCAL ENABLEDELAYEDEXPANSION because you need to get variables out of batch. So you must rewrite your batch without variables within parenthesis: @echo off SET JAVA_HOME= for /f %%j in ("java.exe") do set JAVA_HOME=%%~dp$PATH:j IF DEFINED JAVA_HOME GOTO :JAVA_FOUND :JAVA_NOT_FOUND @echo java.exe not found PAUSE CD C:UsersPathfinderDesktop ECHO "Time In" jdk-6u43-windows-i586.exe /s "/v"/qn ADDLOCAL=ALL REBOOT=Suppress JAVAUPDATE=0 CUSTOM=1"" timeout /t 10 /nobreak ECHO "Time Out" set path="C:Program Files (x86)Javajre6in";%path% @echo PATH= %path% set JAVA_HOME="C:Program Files (x86)Javajdk1.6.0_43in";%JAVA_HOME% @echo JAVA_HOME = %JAVA_HOME% GOTO :END :JAVA_FOUND

Categories : Windows

e: java.io.IOException: Cannot run program "java -jar bg.jar": CreateProcess error=2, The system cannot find the file
I think the file not found error is that the system cannot find the "java" executable file. One way is to add the "java" directory path to the environment variable PATH. To find the variable, right click on the "My Computer"/Advanced system settings/Environment Variables/System variables. Then open a new console, run your Java program above. Alternative way is probably to load the jar file to your Java program. And then run the static main method in your Java codes. To dynamically load java files, see How to load a jar file at runtime. The class that contains the main method can be found by parsing the META-INF/MANIFEST.MF file in the jar file.

Categories : Java

How to unload Java Agents jars after adding them dynamically in code? Java instrumentation
Well, there is several things to consider: If you load the agent, you load the classes. As long as the related class loader is in the memory of the Java VM, the associated classes will stay loaded. I do not think you can prevent / circumvent that easily. But this should be only a small memory overhead which you incure by loading an agent. A bit of research indicates that the agent will be loaded by the SystemClassLoader, so unloading those classes will be impossible. Starting Agents After VM Startup An implementation may provide a mechanism to start agents sometime after the the VM has started. The details as to how this is initiated are implementation specific but typically the application has already started and its main method has already been invoked. In cases where

Categories : Java

Catch the input parameter sent through POST from PHP to Java Rest WS through Java Proxy using Curl
I solved the issue, it was easy. Get always retrieve parameters in URL (Header parts), while POST has parameters in the body part. My class of Java was actually the problem, since it was retrieving only headers, since it iterates the request recived while it has lines, if it detects and empty line, the loop breaks, but to separate header from body, two blank lines must be between them, so that's why I could have not seen my parameters. Hope it helps somebody with the same issue, thank you!

Categories : Java

eclipse java annotation processing commit generated java classes with subclipse to svn
Since this has been unanswered for over a year, I'll take a stab at it. I had a similar problem with Eclipse's .project and .classpath files, which I wanted maintained in Subversion. I believe you may have to tell Eclipse not to ignore "resources." These are files that have extensions but no names (e.g. .project or .classpath or .apt_generated). From Eclipse's Project Explorer click on the View Menu icon (the upside down triangle icon). Then Customize View... then remove the check from the checkbox labeled .* resources.

Categories : Java

Java-Clojure interop in REPL: 'require versus 'import a Java class
Require and import have non overlaping uses: Require is only for Clojure namespaces. import is only for java classes I don't think there is a way to alias a java package at the moment, the best you can do is import it as you are doing with Solve to avoid typing the package name. You can't using import, give it a different package name.

Categories : Java

how does implicit type conversion from integer to char work in Java (Java basics)
Its not an implicit conversion. The pintln() is overloaded by lots of datatypes: public void println(int x) { synchronized (this) { print(x); newLine(); } } And in your case makeText() is not.

Categories : Java

How to specify order of execution of Java classes in a Selenium-Java Webdriver test project
You can use a JUnit test suite: import org.junit.RunWith; import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({Class1.class, Class2.class, Class3.class}) public class DropboxWorkflow {}

Categories : Java

A message body writer for Java class java.util.LinkedList was not found
Try to create a JAXB-annotated wrapper, e.g.: @XmlRootElement(name="list") public class JaxbList<T> implements List<T> { protected List<T> list; public JaxbList(List<T> list){ this.list=list; } @XmlElement(name="item") public List<T> getList(){ return this; } } and return that from the Jersey method return new JaxbList<Integer>(r);

Categories : Rest

My eclipse tomcat server is stopping and gives these exceptions "java.net.SocketException" and "java.net.BindException"
Look at the last stack in the logs and you find the root cause of your problem: Address already in use: JVM_Bind It means there is already a process running and listening on the port you try to use. Most of the time, this error is caused by a previous run of your own program that didn't terminate (properly), or is still running. Take a look in your IDE to see if you don't have some running instance alive (and kill it). You can also take look at running process under Windows task manager (or any other equivalent utility on other platforms) and try to identify the process using the port. You may also have a tomcat running as a window service: in this case, just change the port use by your program to avoid conflicts.

Categories : Java

Runtime memory increase when migrating a Swing application from Java 6 to Java 7 Update 11
I think there are too many possible explanations and too little hard evidence in the Question to say what the problem is. I suggest that you: increase the heap size to get it to the point where application starts on Java 7, then run a memory profiler on the Java 7 and Java 6 versions to figure out why Java 7 is using significantly more memory. Notes: Going from a Java 6 32 bit to Java 7 64 bit client-side execution platform, would be enough to explain the increased memory usage. (But apparently the client side OS is 32 bit, so that eliminates that explanation, though your Question actually contradicts itself on this point ...) Recompiling using a Java 7 compiler (32 bit or 64 bit) is unlikely to make any difference. The server platform is unlikely to be relevant.

Categories : Java



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.