spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » JAVA » Page 1
How to enable Swagger UI? Tomcat, SpringMVC, REST
I solved my problem by adding swagger-ui resources to srcmainwebappdocs I also added <mvc:default-servlet-handler/> To pom.xml Now I can access swagger UI under: http://localhost:8080/myapp/docs/

Categories : Java

Decryption pad block corrupted
You should not rely on available() to detect the end of the stream. It may work now (for files), but it may not in the future. Instead, use the output of read(). More importantly however you are calling cipher.doFinal(). One of the features of doFinal() is that it checks the padding for ciphers that require it (CBC and ECB mostly). Now padding is only applied at the end of the plaintext message,

Categories : Java

Is java toBinaryString Incorrect?
You aren't parsing your input string as a HEX representation. You're taking each character, getting its char value and converting that to binary representation. What you want is to parse the input text as a base 16 integer String hexCode = "A1E1F1"; int val = Integer.parseInt(hexCode, 16); System.out.println(Integer.toBinaryString(val));

Categories : Java

Why does JDBC not support Oracle Boolean type
From: PL/SQL TABLE, BOOLEAN, and RECORD Types It is not feasible for Oracle JDBC drivers to support calling arguments or return values of the PL/SQL RECORD, BOOLEAN, or table with non-scalar element types. However, Oracle JDBC drivers support PL/SQL index-by table of scalar element types. ... As a workaround to PL/SQL RECORD, BOOLEAN, or non-scalar table types, create container proce

Categories : Java

Java RMI: Rejecting requests when saturation is reached
RMI offers you a way to control the server socket creation, if you control the creation of client-server socket, you can decide whether to serve the incoming request or not, and of cause you can monitor rejections of service. here you need to extend ServerSocket. And if you want to reject "method invoke request", you can use a proxy object. public class T { public static void main(String[] a

Categories : Java

My random numbers are always zero?
Instance field initialization expressions are executed before the constructor body. So private int num1 = rand.nextInt((max - min) + 1) + min; is executed before this.max = max; this.min = min; in the constructor. At that point, the value of max and min is therefore the default 0. Move the initialization statement of num1 to the constructor body, after the assignments of max and min.

Categories : Java

Use DelimiterBasedFrameDecoder, StringEncoder, etc outside of pipeline in Netty
It's possible to put all encoders/decoders logic into the handler, but it's bad idea from architecture point. Would be better to write new codec (encoder/decoder), maybe even based on them, you can look inside of StringEncoder or StringDecoder or even to DelimiterBasedFrameDecoder to understand how to do it, in fact they are pretty simple, or check on the netty site how they implementing TimeEnc

Categories : Java

Play 2.x: Binding model which contains a list to the template
As mentioned in comment probably JavaScript and AJAX would be most comfortable solution, you can i.e. create an User as unactive and activate him only when at least one address is added later. Other solution can be using custom class with fields from both (User and Address) so after validating all required fields you can create an User and associated Address. Sample User model: public class Us

Categories : Java

My activity is going to potentially hold a lot of fragments (5+) how should I create them?
In one of my activities, I add all the fragments onWindowFocusChanged (so I have proper screen measurements): private void addFragments() { if(mPassedMachine.getMachineType() == MachineType.ZR7) addZeroFragment(ANIMATION_TYPE_NONE, false); else addLevelFragment(ANIMATION_TYPE_NONE, false); addHeartRateFragment(ANIMATION_TYPE_NONE, false); addMaxMinAvgFragment(ANI

Categories : Java

How do I convert 16-bit char array to 8-bit char array and send to c code using JNA?
If your native signature requires const char*, then JNA will automagically work when you pass a Java String. No conversion necessary. Internally, JNA will create a temporary buffer (for the duration of the call) and encode the Java String as a native NUL-terminated byte array (defaults to utf8 encoding, but can be modified by setting the system property jna.encoding).

Categories : Java

apache commons-validator alternative for new gTLDS
If you are not concerned about internationalized addresses, you could change last part of address, and continue to use Apache commons. This approach is based on the fact that whatever the TLD is, the validity of the whole domain name is equivalent to the validity of the same domain name with the TLD replaced with com. For example: abc.def.com is valid. Similarly abc.def.name, abc.def.xx--kput3i

Categories : Java

Wicket Panel inside of a Fragment
Yes, it is. Here's a simple example: Page: package com.mycompany; import org.apache.wicket.request.mapper.parameter.PageParameters; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.panel.Fragment; import org.apache.wicket.markup.html.WebPage; public class HomePage extends WebPage { public HomePage(final PageParameters parameters) { super(param

Categories : Java

when to use constructor injection in spring?
The correct approach is to use constructor injection whenever it's possible. Thanks to that it's clear what are the object dependencies and you are not able to create one if you do not provide all that are required. Use constructor injection as below. public class ProjectService { private final ProjectRepository projectRepository; private final TaskRepository taskRepository; @Aut

Categories : Java

Afterburner.fx fail load resource from object injected
Finally, I found the problem that no have relation with Afterburner.fx: When I create Project with maven, I not include resources from folder img in my POM, so I get always the above error. Perhaps, I can load other default resources like css styles. After configure correctly my POM, all things work.

Categories : Java

Unable to run under Jetty from Eclipse: Unknown scope: debug
I am not a regular jetty user. Just now installed Jetty 8.1.14 from eclipse marketplace on my Eclipse Luna 4.4.0 (Mac) and it is working like a charm. Please try to upgrade eclipse/jetty if you are using older versions.

Categories : Java

Drawing multiple lines (minimum 9x9) in JFrame
I had to modify your code just to get it to compile. I made several changes to give you a starting point for your continued development. Here's what my version of the Go Frame looks like. So, here are the changes I made. First, you must always start a Swing application with a call to SwingUtilities.invokeLater. public static void main(String[] args) { SwingUtilities.invokeLater(new GoB

Categories : Java

Can't solve "Java heap space" error in eclipse
Where is the "vmargs" option? If you set the min/max heap, you probably need to do it on the main process, not the launcher. See the Eclipse FAQ item on setting VM options. That launcher PermSize opt is a bit ridiculous. Unless you know it is launcher PermSize causing the OOM, keep it at the default of 256m. [EDIT] As pointed out else-thread, if this is happening when you run your Java progra

Categories : Java

generic signature to accept Map or Map
If you were only reading the values out of the Map you could have done something like this: public static Report createReport(Map<String,?> parameters) {...} However, since you also want to add enteries, you need to know the type, or at least be able to know that the type in the Map is the same as the type you are adding. If it is variable, then I would suggest having another parameter t

Categories : Java

Value isn't being brought over
I tried to fix some of your logic. You were in an infinite loop since there was no way to ever break out of it. I fixed this by making a valid number boolean. Also why the outer while loop? That increases the time complexity for no reason. So got rid of it and replaced with an if if (invalidInput) finalNum = JOptionPane.showInputDialog(null, "Please enter a number

Categories : Java

Integrating Selenium Test Suite (Eclipse) with TFS
You can call UI scripts as you describe and I would additionaly recommend that you use Release Management to do this rather than build. It makes much more sense to use a deployment engine rather than a compilation engine to maintain this. One does not usually have an instance of ones application running on the build server. http://nakedalm.com/execute-tests-release-management-visual-studio-2013/

Categories : Java

Java - How to create a new class that extends JFrame and has all GUI components in it while another class has all functionality?
Provide a Controller as Singleton for the gui: http://en.wikipedia.org/wiki/Singleton_pattern e.g. class Controller{ private Controller _instance; private Controller(){ } public static Controller getInstance(){ if(_instance == null){ _instance = new Controller(); } return _instance; } public void addCard(Card card){ } publ

Categories : Java

How to correctly use Apache Common BeanUtil's BeanComparator to benefit of introspection?
You've gotta look at the various constructors on there: BeanComparator(String property) Constructs a property-based comparator for beans. BeanComparator(String property, Comparator comparator) Constructs a property-based comparator for beans. Here's the former's javadoc (2nd para is your answer): Constructs a property-based comparator for beans. This compares two beans by the proper

Categories : Java

Java memory issue with animated gif frames
Ok, I found the solution Thanks to http://stackoverflow.com/a/16234122/2655623 and http://stackoverflow.com/a/8935070/2655623 You may also get a deprecation warning because of com.sun.imageio.plugins.gif.* files. But that is fine. I copied these files into my project so the issue is solved. Now I can get images (Search them by index) without putting all images into the memory. ;) Edit: Please u

Categories : Java

converting ArraList to JSON (in Java) and accessing it with Javascript
You may need to create a REST service end point and expose Array content as JSON. then you should be able to retrieve JSON from browser and consume it. Simple way of creating such end point is given in spring documentation https://spring.io/guides/gs/rest-service

Categories : Java

How to properly close threads and file handles in async object
Finalize is where I'm thinking I should handle such things Finalizers are called by garbage collection, and the garbage collector runs when there's a need to reclaim unused memory. The garbage collector does not run because of a shortage of file descriptors or database connections or any other resource. It does not run because there's a transaction that's been left hanging open... Don't us

Categories : Java

TreeMap Element does not removed
returning 0 would merge keys Returning 0 means the elements are equal. If you don't return 0, elements are never equal. Your TreeMap uses the given Comparator to put and remove. Your Comparator never identifies two keys as equal and therefore cannot remove anything.

Categories : Java

Index out of bounds exception when trying to swap the colums of a matrix
This is because you rows and columns are not same. Consider an example : A 3x4 matrix [1,2,3] [4,5,6] [7,8,9] [10,11,12] now interchanging rows and columns [1,4,7,10] [2,5,8,11] [3,6,9,12] This becomes a 4x3 matrix EDIT : public static void main(String[] args) { int [][] arr={{1,2,3},{4,5,6},{7,8,9}}; printArray(arr); System.out.println(); swapAllcolumn

Categories : Java

How to fix ad to the screen while in scrollview?
Easy. Don't put the ad in the ScrollView. instead of <ScrollView> <!-- your ad here --> <!-- your content --> </ScrollView> try something like <LinearLayout> <!-- your ad here --> <ScrollView> <!-- your content --> </ScrollView> </LinearLayout>

Categories : Java

Making CRUD in Liferay MVC
You seem to be missing some fundamental understanding about how to pass around the proper ids. My recommendation is to build this portlet, including the entity, with xmlportletfactory. That one will use servicebuilder, but generate all of the code that you currently are implementing on your own, including the frontend portlet. You can take a look at this code, debug and inspect it. Then transfer y

Categories : Java

type-casting can be an example of adapter design pattern?
No. Since an adapter pattern requires Object instances, and type-casting primitives uses no Object(s) at all, it isn't an Adapter pattern. Even if you cast between Object instances (which you could only do if they were in the same type-hierarchy), it would not be an adapter pattern. From the Wikipedia article (emphasis added), the adapter pattern is a software design pattern that allows the interf

Categories : Java

insert data into database(mongodb)
"i have a front end which has 4 text boxes saying "name","manufacturer","colour" and "price"....so whatever i enter in the text box should be put into the database....however in the above code insertion can be done only by explicitly specifying the values....so i need to change this for a generlized method" Just change it to something like: String name = nameField.getText(); String manufactu

Categories : Java

How to use a JNI lib, with associated libs, at an arbitrary location?
This can not be done with an unknown location at run time. According to jni documentation "To load your shared native library module in Java, simply use Java's System.loadLibrary method in a Java class:" as well as "Another common reason for the native library not loading is because it is not in your path. On Windows make sure the path environment variable contains the path to the native lib

Categories : Java

IllegalArgumentException: Path resources/primefaces-mytheme does not start with '/'
Found it. I thought it had something to do on how I use the resource folder and how I reference it, but it was actually right there before my eyes: in the deployment descriptor web.xml where the resources directory is declared: GlassFish 3.1.2.2 accepted this: <context-param> <param-name>javax.faces.WEBAPP_RESOURCES_DIRECTORY</param-name> <param-value>resources<

Categories : Java

Converting .cer to .jks using java
this should help to import cer files into java key store: http://docs.oracle.com/javase/6/docs/technotes/tools/solaris/keytool.html http://www.agentbob.info/agentbob/79-AB.html How to import a .cer certificate into a java keystore?

Categories : Java

Extracting dates using Java by matching date format from string
SimpleDateFormat#toPattern gets the pattern String of your SimpleDateFormat instance! So instantiate a SimpleDateFormat with the constructor of your choice and use toPattern to extract the pattern String.

Categories : Java

What is the difference between PermGen and Metaspace?
Bye, Bye PermGen, Hello Metaspace PermGen has been completely removed. Metaspace garbage collection - Garbage collection of the dead classes and classloaders is triggered once the class metadata usage reaches the MaxMetaspaceSize. The space Metadata was held is no longer contiguous to the Java heap, The metadata has now moved to native memory to an area known as the Metaspace. In Simple words,

Categories : Java

Spring Cloud Configuration Server not working with local properties file
Using spring.profiles.active=native is that what Spring documentation seems to suggest, but I couldn't get it to work either. My application.properties file is server.port=8888 spring.cloud.config.profiles=native but the response from the URL http://localhost:8888/config-server/env is {"name":"env","label":"master","propertySources":[{"name":"https://github.com/spring-cloud-samples/confi

Categories : Java

PRYMARY KEY must be unique exception while calling update mehtod
The error itself is descriptive. PRYMARY KEY must be unique. Check if the room no value that you are going to update already exists in the database. Since setting default for a column will add the value if it is not provided in the insert statement. 3.You can check the room no value by printing its value and if it is equal to 111 or any other value that is already available in the table, then

Categories : Java

Spring Hibernate validator issue about model add and update method
You can use groups. For example, your model would be: @NotEmpty(groups = CreateAdmin.class) @Size(min = 4, max = 40) private String password; The create admin group. public interface CreateAdmin { } In your Spring controllers, use Spring's @Validated instead of @Valid. Admin creation method: @Validated(value = CreateAdmin.class) @ModelAttribute Admin admin And use the default group in th

Categories : Java


Recently Add
Android change order of cursor
How to enable Swagger UI? Tomcat, SpringMVC, REST
Decryption pad block corrupted
Is java toBinaryString Incorrect?
Why does JDBC not support Oracle Boolean type
Java RMI: Rejecting requests when saturation is reached
My random numbers are always zero?
Use DelimiterBasedFrameDecoder, StringEncoder, etc outside of pipeline in Netty
Play 2.x: Binding model which contains a list to the template
My activity is going to potentially hold a lot of fragments (5+) how should I create them?
How do I convert 16-bit char array to 8-bit char array and send to c code using JNA?
apache commons-validator alternative for new gTLDS
Wicket Panel inside of a Fragment
when to use constructor injection in spring?
Afterburner.fx fail load resource from object injected
Unable to run under Jetty from Eclipse: Unknown scope: debug
Drawing multiple lines (minimum 9x9) in JFrame
Can't solve "Java heap space" error in eclipse
generic signature to accept Map or Map
Value isn't being brought over
Integrating Selenium Test Suite (Eclipse) with TFS
Java - How to create a new class that extends JFrame and has all GUI components in it while another class has all functionality?
How to correctly use Apache Common BeanUtil's BeanComparator to benefit of introspection?
Java memory issue with animated gif frames
converting ArraList to JSON (in Java) and accessing it with Javascript
How to properly close threads and file handles in async object
TreeMap Element does not removed
Index out of bounds exception when trying to swap the colums of a matrix
How to fix ad to the screen while in scrollview?
Making CRUD in Liferay MVC
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.