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

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

The import javax.inject cannot be resolved while import Guava source
You can get the javax.inject jar here. You don't need to use maven, just download the binary.

Categories : Eclipse

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

NoClassDefFoundError: org/apache/tomcat/util/codec/binary/Base64
The wrong pathref was used for the necessary targets, one that did not contain a path to the much-needed tomcat-util.jar. Kudos to @akostadinov for the prod in the right direction.

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

Creating Image Data Url using android.util.Base64.encodeToString from Byte Array
The actual problem is caused by the buffer size of logcat being limited. The stringBuilder indeed holds the correct data, however when printed in the log it is truncated by the limited buffer size. Simply add a for loop and everything will get printed. Refer to this question for more info about logcat's buffer size.

Categories : Android

The import edu cannot be resolved
Add a project reference in the ProjectName build path for the jar or project containing the edt.emory.mathcs.jtransforms.fft package. Here's a tutorial on how to do that in Eclipse.

Categories : Java

The import com.example.myfirstapp.R can not be resolved
You don't need the com.example.myfirstapp.R unless it is in a library. If it is in com.example.myfirstapp, remove it. Also, trying cleaning your project and rebuilding it.

Categories : Android

The import com.google cannot be resolved
You also need to set the build target (Project > Properties > Android) to be a build target that has the Google APIs in it, to use Maps V1. That being said, Raghunandan is correct -- you should be using Maps V2, as you can no longer get Maps V1 API keys. Note that Maps V2 does not require you to have a "Google APIs" build target.

Categories : Java

the import javax.media cannot be resolved
The Java Media Framework is an optional package. I believe you have to download it separately. The Java Media Framework API (JMF) enables audio, video and other time-based media to be added to applications and applets built on Java technology. This optional package, which can capture, playback, stream, and transcode multiple media formats, extends the Java 2 Platform, Standard Edition (J2SE) for multimedia developers by providing a powerful toolkit to develop scalable, cross-platform technology. (source) After downloading it, you need to add it to your classpath.

Categories : Misc

The import com.company.projectname.R cannot be resolved
Try to clean the project, sometimes clean my projects have solved my problems on Eclipse/Android. If it doesn't work, you can see there if it corresponds with what you did: Question like yours

Categories : Android

Domino XPages Import cannot be resolved
If you are trying to use non-standard libraries inside a Java agent, i think you have to import them in another way. When you open the agent in Domino Designer perspective, you'll see a drowdown button "Import". If you have, for example, the additional libraries as jar files, use Import > Archive.

Categories : Misc

The import android.support cannot be resolved
Please follow these Steps: Go to your Project's Properties Navigate to the Java Build Path Then go to the Libraries tab. There click the Add External JARs Button on the Right pane. Select the android-support-v4.jar file, usually the path for the Jar file is : YOUR_DRIVEandroid-sdksextrasandroidsupportv4android-support-v4.jar After adding andorid-support-v4.jar Library, navigate to the Order and Export tab and put check mark on the android-support-v4 Library file. After doing the above, Clean the Project and Build it. Problem Solved. Further reading regarding this Question: Support Library - Android Dev what is android support library How Android Support Library work? I hope this helps.

Categories : Java

The import javax.xml.rpc.encoding cannot be resolved
Add the relevant jars to your build path : axis.jar, jaxrpc.jar and xerces.jar. You can use the JARFinder to locate the jars.

Categories : Java

Android: Import DrawerLayout cannot be resolved
How do I update the JARs in libs? I usually do it by copying the file. You will find the JARs inside $ANDROID_SDK/extras/android/support, where $ANDROID_SDK is wherever your Android SDK is installed. If you use Eclipse, if you copy this at the filesystem level, and Eclipse is open, press <F5> with the project highlighted in Package Manager so Eclipse picks up the changes. Easier is to drag it out of the SDK and drop the JAR into libs/ right in Eclipse, which will both update the filesystem and let Eclipse know about the change. It's possible that the Eclipse option to add the JARs (right-click over the project, then choose Android Tools > Add Support Library... from the context menu) will also do this. That particular approach doesn't work for me due to some peculiarities with

Categories : Java

not able to import abeel util in a maven project
It might not have been deployed to Maven Central or another Maven Repository. In this case you can do the following: Add the JAR to your corporate Maven Repository (see here for Nexus: http://blog.sonatype.com/people/2008/11/adding-a-jar-to-a-maven-repository-with-sonatype-nexus/) Try to get the JAR deployed to Maven Central: Ask the project owner to deploy the JAR to Maven Central. Here is the documenation how the project owner can do this: https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-9.StageaRelease If the project owner does not respond but the license is compatible with Maven Central requirements: https://docs.sonatype.org/display/Repository/Uploading+3rd-party+Artifacts+to+The+Central+Repository

Categories : Java

New PhoneGap 3.0 The import org.apache.cordova cannot be resolved
Update: If you upgrade to Phonegap 3.3 you shouldn't need to do this anymore. Details on updating Phonegap: http://phonegap.com/blog/2013/12/13/phonegap-release/ Note: Make sure in eclipse you import Existing Android Code into Workspace NOT 'Existing Projects into Workspace I had the exact same problem and found a solution that works: Download the source ZIP for Cordova: http://cordova.apache.org/#download Extract the 'cordova-android' ZIP anywhere. Inside will be a 'framework' folder. In eclipse open the newly unzipped 'cordova-android/framework' folder as an existing project. In eclipse right click on this new 'Cordova' project -> Properties -> Android . Make sure 'Is Library' is checked. Right click on your app's project -> Properties -> Android. In the Library section choose 'Ad

Categories : Java

The import javax.annotation cannot be resolved during Maven build
Does your pom.xml set the Java Compiler version? Some (all?) versions of maven-compiler assume the Java 1.4 compiler... which of course causes issues since Annotations were new in Java 1.5. You can force it to Java 7 by including a plugin block for maven-compiler-version in your project's pom.xml and set its source and target properties... something like this: <project> [...] <build> [...] <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin>

Categories : Java

What do I need to configure in an Eclipse project to fix incorrect “The import XXX cannot be resolved”
The problem is that the generated sources folder has many other class definitions which are also needed by the RegistryResourceImpl class. You need to add the generated source folder as a source code location in the maven pom. A similar question has a decent answer. Appropriated from that answer: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>${project.

Categories : Java

"R cannot be resolved" may have wrong build path or libraries import
Make sure you installed the Android build tool form sdk manager project right click properties-> Java BuildPath select Library and add android-support.jar the follow these step. Go to Project->Properties->Java Build Path than select Order and export tab. Set android-support .jar library checked and up it into top of the list. And clean and rebuild..It works for most of the cases

Categories : Android

How can I import base64 image in JSON into core data binary via RESTkit 2.0 in iOS 6?
You should be able to use an RKValueTransformer to do this for you. Basically, these are objects for mapping between native types and JSON responses (and vice versa). Here's mine that does base64 strings (which could be from JSON) to NSData. [RKValueTransformer.defaultValueTransformer insertValueTransformer: [RKBlockValueTransformer valueTransformerWithValidationBlock:^BOOL(__unsafe_unretained Class inputValueClass, __unsafe_unretained Class outputValueClass) { return [inputValueClass isSubclassOfClass:[NSString class]] && [outputValueClass isSubclassOfClass:[NSData class]]; } transformationBlock:^BOOL(id inputValue, __autoreleasing id *outputValue, __unsafe_unretained Class outputClass, NSError *__autoreleasing *error) { RKValueTransformerTestInputValueClassI

Categories : IOS

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

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

Difference between java.util.Scanner and java.util.Scanner.*
import java.util.Scanner; This imports Scanner (as you already know). import java.util.Scanner.*; This imports any public nested classes defined within Scanner. This particular import statement is useless, as Scanner does not define any nested classes (and the import does not import Scanner itself). However, this can be used with something like import java.util.Map.*, in which case Entry (an interface nested in Map that is commonly used when dealing with maps) will be imported. I'm sure there are better examples, this is just the one that came to mind. All of this is specified in JLS §7.5 (specifically, see §7.5.1: Single-Type-Import Declarations). In response to the OP's edit: Ok so import java.util.Scanner.* imports the public nested classes. But what if there was also a

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

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

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, 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

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

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

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

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

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

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

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

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



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