w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
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

Java Error "Exception in thread "main" java.util.InputMismatchException" On an Array program
From InputMismatchException's JavaDoc: Thrown by a Scanner to indicate that the token retrieved does not match the pattern for the expected type, or that the token is out of range for the expected type. It seems that you entered a string whereas nextInt() expects an integer.

Categories : Java

Java Scanner Error : Exception in thread "main" java.util.NoSuchElementException: No line found
well, instead of nextLine() you should use hasNextLine() almost always. But you are skipping the input because your System.in might not be pointing to console or any inputstream that can take any input or open an inputstream. That's why its not working at all in case of hasNextLine, while nextLine() being a forced method to read even if there is no data, is expecting an input but being not able to get that its throwing exception. may be you should check where your System.in is pointing. you can manually set it as setIn(Console()) also you can check whether console() is non-null.

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.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: 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

Trying to read from a text file in java getting error: Exception in thread "AWT-EventQueue-0" java.util.NoSuchElementException
You might want to change your = which assigns true to f by a comparaison operator == if (f == true) { this.setVisible(false); w.setVisible(true); } else { System.out.println("It works"); }

Categories : Misc

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

Is it better to return a java.util.List or a java.util.Collection from my Restful Web Service?
It really depends on the requirement. If you wanted to make the implementation more generic and also if you are not sure at where the may be used, Collection usage is more advisable. Please find why?

Categories : Java

java.util.hashmap cannot be cast to java.util.list
Wrap the Map in a List to match the expected type List<? extends Map<String, ?> of the constructor SimpleAdapter: ListAdapter adapter = new SimpleAdapter( MainActivitty.this, Arrays.asList(hm), R.layout.list_item, new String[] { key, value1,value2}, new int[] { R.id.id, R.id.value1,R.id.value2 }); Refer to this example

Categories : Java

How do I run a single Java file having main() in Eclipse, without creating an entire Java project?
You can run the java file in the cmd command window. make sure you have install the java environment. java -version output: java version "1.7.0_07" Java(TM) SE Runtime Environment (build 1.7.0_07-b11) Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode) cd javafilepath java yourjavafilename.java

Categories : Java

Exception in thread "main" java.util.NoSuchElementException (I'm really new to this)
The error lies here: Name = keyboard.next(); You should use Name = keyboard.nextLine(); The java.util.Scanner.next() method finds and returns the next complete token from this scanner. A complete token is preceded and followed by an input that matches the delimiter pattern, which is a blank space by default. You may want to take a look at the documentation of the Scanner class You should also take a look at the Java naming convention

Categories : Java

Return farthestK from val: Can't import anything other than java.util.Arrays
By storing the distance as an absolute value, you destroy your last for loop which recalculates the original value from the abs-value. How about using a comparator who is using the abs value for comparison, but storing the difference of the array value from the search value in your array b? This would be something like this here: public static int[] farthestK(int[] a, int val, int k) {// This line should not change Integer[] b = new Integer[a.length]; for (int i = 0; i < b.length; i++) { b[i] = a[i] - val; } Arrays.sort(b, new Comparator<Integer>() { @Override public int compare(Integer arg0, Integer arg1) { return Integer.valueOf(Math.abs(arg0)).compareTo(Math.abs(arg1)); } }); int[] c = new int[k]; int w = 0; fo

Categories : Java

Scanner - Exception in thread "main" java.util.NoSuchElementException: No line found
It means that your file doesn't have next line. You should always check hasNextLine() before calling nextLine. You should modify your code like this if (first_line.hasNextLine()){ size_st = Integer.valueOf(first_line.nextLine()); } java.util.NoSuchElementException is thrown by the nextElement method of an Enumeration to indicate that there are no more elements in the enumeration.

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

OutOfMemoryError: Java heap space at java.util.Arrays.copyOfRange
It simply means that the JVM ran out of memory. When this occurs, you basically have 2 choices: Allow the JVM to use more memory using the -Xmx VM argument. For instance, to allow the JVM to use 1 GB (1024 MB) of memory Improve/Fix the application so that it uses less memory In many cases, like in the case of a memory leak, the second option is the only sound choice. A memory leak happens when the application keeps more and more references to objects and never releases them. The garbage collector will therefore never collect those objects and less and less free memory will be available until we reach the point where not enough free memory is available for the application to function normally. At this point, the JVM will throw an OOM. Try this solution.

Categories : Java

Java, ArrayList and Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
You should avoid modifying elements in a list while iterating that list. With the for (int i...) loop, you are not iterating the list, so you can modify the elements inside. In the for (Baseitem item : list) loop, you are iterating the list, so the modification of the elements of the list will raise the ConcurrentModificationException exception. You have to use the first form of the loop if you want to modify the elements inside it.

Categories : Java

Exception java.lang.NoSuchMethodError on java.util.Deque.push
Dequeu.push(E e) requires Object type argument to be inserted. the Dequeu declaration is fine, but __.push(new Matrix()) must cause problem.,br. You have some data field you want to push so declare an instance of Matrix that holds the data fields and then push it to Deque. Here is a sample code, hope it will help import java.util.*; public class DequeExample { private static Matrix matrix = new Matrix(); private static Deque<Matrix> deque = new LinkedList<Matrix>(); public static void main(String[] args) { for (int i = 0; i < 10; i++) { matrix.setValues(i * i, (float)Math.pow(i, 5.6f), new String("String " + Integer.toString(i))); deque.push(matrix); } System.out.println(deque.size()); } static class Ma

Categories : Java

How to handle thousands of threads in Java without using the new java.util.concurrent package
I'd say give up now and figure another way to do it. Default stack size is 512K. At 30k threads, that's 15G in stack space alone. To fit into 2G, you'll need to cut it down to less than 64K stacks, and that leaves you with zero memory for the heap, including all the Thread objects, or the JVM itself. And that's just the most obvious problem you're likely to run into when running that many simultaneous threads in one JVM.

Categories : Java

java.lang.ClassCastException: org.hibernate.internal.SQLQueryImpl cannot be cast to java.util.List how to fix
You forgot .list() at end of the query. It should be something like ................skill.id where skill.id = 1").list(); Refer hibernate documentation for more information.

Categories : Java

Error on SimpleTemplateEngine embedded in Java: Could not instantiate custom Metaclass for class: java.util.ArrayList
I'm guessing that the part Registro[i] is for getting the value of a static property which name is held under the variable i (or at least that is what will happen) unless the getAt(String) method has been overloaded on Registro. Either way I also guess that returns an object that has a listUsers property that should be at least a Collection. Maybe the problem is with the initialization of said listUsers property. Some Registro code could be used for better understanding.

Categories : Groovy

Using new xmlns.jcp.org namespace on composites causes java.lang.NullPointerException at java.util.concurrent.ConcurrentHashMap.putIfAbsent
The way how the new xmlns.jcp.org XML namespaces are been handled is broken in the first Mojarra releases 2.2.0 and 2.2.1. It has been fixed in Mojarra 2.2.2 (note: ticket in the link describes different problem symptom, but under the covers, it's essentially the same cause). It's recommended to upgrade to at least Mojarra 2.2.2 (always pick the newest available, if possible). GlassFish 4.0 has 2.2.0 bundled. You can get the JAR from javaserverfaces.java.net. All you need to do is to replace javax.faces.jar file in GlassFish's /modules folder with the newer version. The Java EE 7 tutorial itself is fine. It was just the implementation which was broken. This kind of trouble is by the way not unusual with the very first major GlassFish release (all hastle to get it ready on time). I recomme

Categories : JSF

java generics runtime error.java.util.ConcurrentModificationException
This has nothing to do with generics, and everything to do with the fact that you're modifying a collection directly (in insert) and then trying to use an iterator which was created before the insertion. Don't do it. From the docs of ArrayList: The iterators returned by this class's iterator and listIterator methods are fail-fast: if the list is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove or add methods, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future. If you must keep the iterator around, use that to add a new value inst

Categories : Java

How are is the seekbar in main.xml linked to the java file? Programming in Android
If you put an element in your layout (e.g. SeekBar) with the id "@+id/customSeekBar", it will be mapped in the code to R.id.customSeekBar. This "magic" is done by the R automatically generated file. Thus findViewById(R.id.customSeekBar) can be used to reach exactly that layout element. The R file (located in the /gen folder) can map layout elements (called views - for example R.id.myView), layouts themselves (R.layout.myLayout), predefined strings (R.string.my_string), and other elements you will learn in due time.

Categories : Java

Threads in Java. "AWT-EventQueue-0" java.util.ConcurrentModificationException
You haven't shown enough code to pin-point the problem but one of your threads have tried to modify a collection that one of your other threads is iterating over currently. The JavaDocs for ConcurrentModificationException say This exception may be thrown by methods that have detected concurrent modification of an object when such modification is not permissible. For example, it is not generally permissible for one thread to modify a Collection while another thread is iterating over it. If a thread is allowed to continue iterating over a collection which is simultaneously being modified the program behaviour would become non-deterministic and it would fail at an undetermined time leading into hard to find bugs. Hence, this exception is thrown by the Iterator and the program is said t

Categories : Java

What is the difference between java.util.ArrayList and java.sql.Array
I agree with what Jeffery is saying, there is no java.sql.ArrayList class. If you meant java.sql.Array (there is such a class), the difference is that Array is used to retrieve SQL arrays from a datastore, and ArrayList is used as an all-purpose way to have a collection of objects.

Categories : Java

java.io.NotSerializableException: java.util.HashMap$Values
Found the problem! The remote service was trying to throw an Exception encapsulating a Collection of String from HashMap.values(): if (!identifiersMap.isEmpty()) { context.setRollbackOnly(); BusinessException e = new BusinessException(); e.setValues(identifiersMap.values()); // here is where the problem is throw e; } HashMap has an inner class named Values (as you can see here), which is an implementation of Collection and is NOT Serializable. So, throwing an exception having the content of HashMap.values(), the remote method will throw a serialization exception instead! ArrayList, for example, is Serializable and could be used to resolve the issue. Working code: if (!identifiersMap.isEmpty()) { context.setRollbackOnly(); BusinessException e = new Business

Categories : Java

why java returns java.util.LinkedHashMap when ... complex
/** * Returns the runtime class of this {@code Object}. The returned * {@code Class} object is the object that is locked by {@code * static synchronized} methods of the represented class. * * <p><b>The actual result type is {@code Class<? extends |X|>} * where {@code |X|} is the erasure of the static type of the * expression on which {@code getClass} is called.</b> For * example, no cast is required in this code fragment:</p> * * <p> public final native Class<?> getClass(); It doesn't matter what reference type is . Method getClass() returns runtime class.

Categories : Java

Java 8: Where is TriFunction (and kin) in java.util.function? Or what is the alternative?
If you need TriFunction, just do this: @FunctionalInterface interface TriFunction<A,B,C,R> { R apply(A a, B b, C c); default <V> TriFunction<A, B, C, V> andThen( Function<? super R, ? extends V> after) { Objects.requireNonNull(after); return (A a, B b, C c) -> after.apply(apply(a, b, c)); } } Following small program shows how it can be used. Remember that result type is specified as a last generic type parameter. public class Main { public static void main(String[] args) { BiFunction<Integer, Long, String> bi = (x,y) -> ""+x+","+y; TriFunction<Boolean, Integer, Long, String> tri = (x,y,z) -> ""+x+","+y+","+z; System.out.println(bi.apply(1, 2L)); /

Categories : Java

getting java.util.ConcurrentModificationException in java swing
TABhs = new CopyOnWriteArraySet(TABhs); for(Iterator <PrintWriter> it=TABhs.iterator();it.hasNext();) { PrintWriter ot=it.next(); ot.println("tableupdate#"+tables+"#"+kotno+"#processing"); ot.flush(); JOptionPane.showMessageDialog(rootPane, "<html><body>Table Kot Status Changed to <b>Processing</b></body></html>"); }

Categories : Java

java exception java.util.InputMismatchException
Docs Thrown by a Scanner to indicate that the token retrieved does not match the pattern for the expected type, or that the token is out of range for the expected type. Looking at your stacktrace: java.util.Scanner.nextInt(Scanner.java:2160) 5 Ann 2201.94 5 at That means whatever you are inputting is not an integer. p = sc.nextInt();

Categories : Java

Java Events - java.util.ConcurrentModificationException
I don't know if this will help any but what is gameSpeed variable set to? And what are lines: Line 15 in EventCaller Line 10 in TickEvent Line 213 in Main Those may help solve the problem.

Categories : Java

Java. InetAddress.getLocalHost returns strange IP
InetAddress.getLocalHost() doesn't do what most people think that it does. It actually returns the hostname of the machine, and the IP address associated with that hostname. This may be the address used to connect to the outside world. It may not. It just depends on how you have your system configured. On my windowsbox it gets the machine name and the external ip address. On my linux box it returns hostname and 127.0.0.1 because I have it set so in /etc/hosts

Categories : Java

Fortify Often Misused Authentication java.net.InetAddress
The vulnerability is effectively just warning you as a developer not to trust the output from these. One effective way to determine whether a server is who they say they are is with SSL. It sounds like on your application that you are just getting a list of servers and forward authentication request to them. If the user is then connecting via SSL to authenticate with the machines, it probably shouldn't be a problem (as long as connection isn't allowed with self-signed certificates)

Categories : Java

Java InetAddress.getByName.isReachable() Alternative
Your application should just try to connect and handle the ConnectException when and if it arises. These games where you try to foresee the future and guess what's going to happen are basically a waste of time. The best way to discover whether any resource is available is to try to use it. In this case: The server could be responding to ICMP but not TCP at all. The server could respond to ICMP or TCP port 7 but the service could still not be running. The server could respond to ICMP or TCP port 7 and the service could be running at that instance but be down an instant later when you try to connect. The server could not respond to ICMP or TCP port 7 but the server could be running. Etc etc. Don't try to foretell the future.

Categories : Java

Random access zip file using java.util.zip
Here is an example of getting the zip entry as a stream (ZipFile.getInputStream(entry)); ZipEntry entry = zipFile.getEntry(entryName); InputStream xmlInStream = zipFile.getInputStream(entry); //process the stream- below one is for xml parsing. DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); return documentBuilder.parse(xmlInStream);

Categories : Java

Bundle using Android API shows "java.lang.UnsatisfiedLinkError: android.util.Log.println_native"
Please read the JavaDocs for UnsatisfiedLinkError: "Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native." In other words, the native implementation of the println_native method is missing from your bundle. Also I note that you do not have a Bundle-NativeCode header that would enable OSGi to find the native code, if it were present. UPDATE In the comment thread it was agreed that we should not even be trying to deploy a bundle that contains this API, because the API is already supplied by the Android platform. So the above advice is moot. There was some confusion about build dependencies versus runtime dependencies. The android.jar can be added to the project build dependencies in order to compile the bundle, but it does n

Categories : Android

OSGI Bundle using Android API is showing "java.lang.RuntimeException: Stub! at android.util.Log.d"
This copy of android.util.Log appears to be saying that's it's only a stub, rather than a real implementation. Probably it was created purely for compiling against, and is not expected to be used at runtime. UPDATE: The following stackoverflow question appears to confirm my guess: Error java.lang.RuntimeException: Stub! in Android with Fitnesse testing Are you actually running on an Android device or emulator?? It seems you may be running on the standard JVM.

Categories : Android

deep within JUnit Parameterized test runner: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.util.List
In the example given for JUnit (which your Javadoc links to), the method annotated @Parameters returns Collection<Object[]>, presumably where each Object[] is an array of arguments to be passed to the test case's constructor via Constructor.newInstance. Your return value from data() should be a Collection<Object[]> instead of just Object[]; I think you need to have an argument-taking constructor for ExpectNoAltTagsInSellerNamesTest, but the JUnit docs are lacking.

Categories : Java

Java.util.zip adding a new file overwrites entire jar?
The code you showed overrides a file no matter if it would be a zip file or not. ZipOutputStream does not care about existing data. Neither any stream oriented API does. I would recommend Create new file using ZipOutputStream. Open existing with ZipInputStream Copy existing entries to new file. Add new entries. Replace old file with a new one. Hopefully in Java 7 we got Zip File System that will save you a lot of work. We can directly write to files inside zip files Map<String, String> env = new HashMap<>(); env.put("create", "true"); Path path = Paths.get("test.zip"); URI uri = URI.create("jar:" + path.toUri()); try (FileSystem fs = FileSystems.newFileSystem(uri, env)) { Path nf = fs.getPath("new.txt"); try (Writer writer = Files.newBufferedWriter(nf, Stand

Categories : Java



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