w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » JAVA » Page 5
In Java how do I evaluate XPATH expression on XML using SAX Parser?
Here is an exemple : //First create a Document DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new File("test.xml")); //Init the xpath factory XPath xPath = XPathFactory.newInstance().newXPath(); String expression = "/company/employee"; //read a nodelist using xpath NodeList nodeList = (NodeList) xPath.c

Categories : Java

Android: Errors occured during the build?
Such an error is a sign that you're combining the DexGuard plugin with an incompatible version of the Android plugin in Eclipse. You should check the compatible version numbers that are documented in the DexGuard manual. Upgrading both plugins to the latest versions should work.

Categories : Java

get substring from string Java(Android)
Explanation - youtube:(.*?)" matches for text in between youtube: and " public static void main(String[] args) { String s = "<p class="youtube_sc mobile "><a href="vnd.youtube:bMHJODdp7-U" title="YouTube video player"><img src="http://i.ytimg.com/vi/bMHJODdp7-U/hqdefault.jpg" /><span class="play-button-outer" title="Click to play video"><span class="play-butto

Categories : Java

dictionary in java using java.io
//This code is reading a file that is situated like this: Hello - to greet Circle - a round shape //Then the code can be done like so, is this ok? public static void main(String []args) throws IOException{ BufferedReader in = null; Scanner input = new Scanner(System.in); String str; boolean notfound = false; char again = 'a'; try{

Categories : Java

How to get integer value of a spinner value?
use the below code sample. int myNum = 0; try { myNum = Integer.parseInt(Spinner_NAME.get(position).toString()); } catch(NumberFormatException nfe) { System.out.println("Could not parse " + nfe); } How to retrieve the selected text from spinner ? Step 1 - In OnCreate Method, add this line. Spinner_NAME.setOnItemSelectedListener(this); Step 2 - In Activity cl

Categories : Java

Can't select between Maven installations in Netbeans
That would be a bug that you should report at https://netbeans.org/bugzilla (component project, subcomponent maven). Along with details of your setup.

Categories : Java

hibernate table per month
Uwe Allner already mention about archiving. You can archive to csv files as well. About the periodic backup process, you can use Quartz Shedular

Categories : Java

Java - file.length() returns 0
Please read the specs: The return value is unspecified if this pathname denotes a directory.

Categories : Java

Select div -class tag using Jsoup with Java
The documentation obviously says it is ok. Element masthead = doc.select("div.masthead").first(); // div with class=masthead So, I think _ is causing the problem. Try with div[class=article_text] as selector, and if that doesn't work then div[class^=article] (class starts with article), but it could select more than you would want. UPDATE div.article_text works on online Jsoup tester (http://

Categories : Java

In EJB 3.1, how technically does the container proxy and effectively spoof my no-interface object?
The container generates a proxy class that is a subclass of your no-interface EJB class, and then it overrides all of the methods to do its normal proxying (setup, teardown, and invoking an actual bean instance) rather than calling methods in your instance. Since java.lang.reflect.Proxy doesn't support extending a class, containers have to use another approach to generate a class, likely using a

Categories : Java

Create a jar with dependencies from bash
You can specify at runtime what JAR's you wish to be included with your JAR. In your case, the following should work. java -cp ../libs/1.jar;../libs/1.jar MyMain

Categories : Java

assign Integer type to int
Assuming that parameters.get("PO_PAGE_CNT") returns an instance of Integer, there is no problem with this assignment. It would be more readable to simply write : int x = (Integer) parameters.get("PO_PAGE_CNT"); An int can always be assigned to Integer (Boxing) and vice versa (Unboxing).

Categories : Java

Polygon with rounded corners
If you need rounded corners for arbitrary angles, Bezier curves are pretty much the worst possible choice, because the maths is stupidly complex. instead, let's use Catmull-Rom curves, because they're defined as "the curve goes through the following points: ..." instead of being simply controlled by points. For any 2 edges between 3 points, p1, p2 and p3, we can create new points p2l and p2r on t

Categories : Java

Android app need help connecting to a JAVA localhost server
You need tcp server socket communication > http://developer.android.com/reference/java/net/Socket.html

Categories : Java

How to output in JLabel if a JCheckbox is selected?
Well, of course it doesn't. setText takes a String as parameter, not a JCheckBox, which is what you are trying to pass. try this: if(yuan.isSelected() == true){ Converter.yuan(); label6.setText("yuan"); } even better, would be: if(yuan.isSelected()){ Converter.yuan(); label6.setText("yuan"); } the '== tr

Categories : Java

Need help accessing data file in Jar File
Where is your SoundDir directory located in the JAR file? Try unpacking the JAR file and checking if you are not sure. If your SoundDir directory is located in the immediately inside the JAR'd directory, then it is relative to the JAR root directory, and you need to use /SoundDir/sonar-beep.wav - note the leading slash. This makes the path absolute, or relative to root Without that slash, you ar

Categories : Java

how to access WorkManager attributes value in weblogic server from our application
You can access the JMX MBean: MaxThreadsConstraintRuntimeMBean to get information about your workmanager. JMX in Weblogic 12c: http://docs.oracle.com/cd/E24329_01/web.1211/e24415/accesswls.htm#JMXCU145 Runtime MaxThreadsConstraintRuntimeMBean: https://docs.oracle.com/middleware/1212/wls/WLAPI/weblogic/management/runtime/MaxThreadsConstraintRuntimeMBean.html

Categories : Java

Android .setColor for Large Icon
According to this: http://stackoverflow.com/a/27023679/327011 There is no way to change the Large Icon background when having both. The large icon should not be a transparent.

Categories : Java

java convert String windows-1251 to utf8
First java text, String/char/Reader/Writer is internally Unicode, so it can combine all scripts. This is a major difference with for instance C/C++ where there is no such standard. Now System.in is an InputStream for historical reasons. That needs an indication of encoding used. Scanner sc = new Scanner(System.in, "Windows-1251"); The above explicitly sets the conversion for System.in to Cyril

Categories : Java

JSON Deserialization error in Java
put private ArrayList<CompletedListing> item in your SearchResult class and remove it from CompletedListingContainer look at your json file structure: { "searchResult":[ { "count":"100", "item":[ {"itemId":["281492499859"]... }, .... } try this online tool to generate Java classes from json

Categories : Java

"FileReadingTools" not working in JAVA
just use: public void read() { String fileName = "your/path/yourFile.txt"; try { List<String> lines = Files.readAllLines(Paths.get(fileName), Charset.defaultCharset()); for (String line : lines) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } }

Categories : Java

Spring MVC InterceptorHandler called twice with DeferredResult
You need to use org.springframework.web.servlet.AsyncHandlerInterceptor: public interface AsyncHandlerInterceptor extends HandlerInterceptor { void afterConcurrentHandlingStarted( HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception; } Spring MVC execute sequence: preHandle afterConcurrentHandlingStarted preHandle postHandle a

Categories : Java

When I run my app on Android Studio, emulator starts but it says that the test app crashed
the problem is here : btn_sign_up = (Button) findViewById(R.id.btn_sign_up); you are trying to find a view by id = btn_sign_up but you are defining it by another id here : android:id="@+id/sign_up"

Categories : Java

Do-while loop issue
You must add a nextLine after your nextInt to consume the rest of the line that contained that int : if(nimi.length()>0){ System.out.println("Anna ko. valtion pääkaupunki: "); pääkaupunki = lukija.nextLine(); System.out.println("Anna ko. valtion asukasluku: "); asukasluku = lukija.nextInt(); Valtio valtio = new Valtio(nimi, pääkaupunki, asukasl

Categories : Java

How to use a Java List as the values of a Hql Insert?
You could iterate over your result list and save professional by calling sessionFirebird.save() inside of transaction. Also take a look here

Categories : Java

Selenium safari web driver doesn't launch safari browser using jenkins on Mac
Jenkins executes without access to a display. It's a server application. That said Jenkins cannot start a safari browser. What you can do, however, is using PhantomJS (http://phantomjs.org/) with GhostDriver (https://github.com/detro/ghostdriver). That's a browser that is pretty full featured but has no GUI at all. It renders everything to buffers. So you still can take screenshots and save those

Categories : Java

Deviding strings and integers of user input
import java.util.Scanner; public final class Test { private static boolean quit = false; private static final String PROMPT = "prompt> "; int add( int i, int j) { int result = i + j; System.out.println(result); return result; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(!quit) { System.out.print(PROMPT); String input =

Categories : Java

How to get Cartesian product from Lists
You can use recursion to achieve it, your base case of recursion is when input is empty then return empty list, else process the remaining elements. E.g. import java.util.List; import java.util.ArrayList; import java.util.Arrays; public class CartesianProduct { public static <T> List<List<T>> calculate(List<List<T>> input) { List<List<T>> re

Categories : Java

ServletConfig with out xml configuration in jsp?
In JSP, we have implicit objects, in which we have config (This is the ServletConfig object associated with the page) object. But I guess we can't add parameters manually as their is not method for adding init parameter in ServletConfig interface. If you want to save any parameters you can save in 4 scopes of JSP (page,request,session and application) and use it wherever you needed. <c:set va

Categories : Java

Circles drawn mainly in X an Y axises, WHY?
Its an artefact of the way you calculate location, you're pulling two different random values for the X and Y component: int locationY = (int)(sin(radians(omega))*random(width/2+1)); //location calcualtion int locationX = (int)(cos(radians(omega))*random(width/2+1)); You should use one random value "distance" from the center for both X and Y, that will remove the clustering towards the axes.

Categories : Java

Get missed element of array
I'm writing this just to give a solution. I'm sure there will be better answers. public static int getMissed(int[] array) { int difference, difference_2; if (array.length < 3) // we need at least 3 elements return -1; difference = array[1] - array[0]; difference_2 = array[2] - array[1]; if (difference == difference_2) { for (int i = 3; i < array.l

Categories : Java

jerssey anotation to filter request based on header value
There is no way to do this by using annotations. However, you can access the HttpServletRequest, for example public Response foo( @Context HttpServletRequest request ) { if( request.getHeader( "version" ).equals( "v1.1" ) } // ... } }

Categories : Java

Redhawk crashing with Java error - Killed by signal 6, SIGABRT
Per someone way smarter than me on the subject: This is an issue that has just come up with the release of CentOS6.6 as it uses a newer version of gtk2 than CentOS6.5. Eclipse detects this and erroneously assumes it can use the cairo graphics API which is either not available or not at the expected version. It's actually a bug within the Eclipse Version used by the v1.10 and v1.9 ser

Categories : Java

ObservableList: how to reliably detect a setAll?
Unfortunately there is no reliable way of detecting this on the Listener side. The struggle starts with the default implemention, which mostly looks like this: @Override public boolean setAll(Collection<? extends E> col) { beginChange(); try { clear(); addAll(col); } finally { endChange(); } return true; } If you pass an empty Collection to se

Categories : Java

Ellipse added with docx4j but not displayed in document
Your problem is that - for Word 2010 anyway - you are missing some required attributes on w:drawing. You need some or all of the following: distT="0" distB="0" distL="114300" distR="114300" simplePos="0" Also, you need some or all of the following extra children for wp:anchor: <wp:simplePos x="0" y="0"/> <wp:positionH relativeFrom="column"> <wp:pos

Categories : Java

How do I replace a basic exception with another one?
Because throwing an exception means creating your own Exception that your method throws so you need to declare that the method throws it so that users of the method know to catch it. Like how you had to surround whatever it was in a try-catch in the first place. If it wasn't enforced that you declare that your method throws then Exceptions could just go missing.

Categories : Java

Error in maven package/test commands due to external package
If you compile/test your project with maven, you need to specify the dependencies to other libraries in the POM file. It is not enough to add a reference in the eclipse build path. If you have a local library that is not in the maven repository, you can add this library to your local repository with the following mvn command: mvn install:install-file -Dfile=<path-to-your-jarfile> -DgroupId

Categories : Java

Java decryption from byte to text
Assuming you are having byte[] bytes and you can convert it using bytes.toString() OR you can change byte by byte byte[] bites = new byte[]{24,4,72,56}; for(int i = 0; i < bites.length; i++) System.out.println(new String(bites, i,1));

Categories : Java

ProGuard on Android + reflection = NoSuchFieldException
Try this in your proguard.cnf file -keep public class * extends com.yoursite.android.yourappname.YourClassName -keepclassmembers class * extends com.yoursite.android.yourappname.YourClassName{ public <init>(android.content.Context); } Ref: Proguard and reflection in Android

Categories : Java




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