spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » JAVA » Page 2
android NULL values after reading a file into array
try to use openFileInput("VilniusWeatherVU.txt") for read your file txt. for example: FileInputStream fileInputStream= openFileInput("VilniusWeatherVU.txt"); InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); StringBuilder stringBuilder= new StringBuilder(); String line; while ((line = bufferedReade

Categories : Java

Google AppEngine FTS is skipping results
From App Engine documentation: A call to search() can only return a limited number of matching documents. Your search may find more documents than can be returned in a single call. Each search call returns an instance of the Results class, which contains information about how many documents were found and how many were returned, along with the list of returned documents. You can repe

Categories : Java

Font dimensions in different object to JPanel
You can't compute the width of a string without the graphics context you are going to use to draw it. See this question. So you need will need to calculate the string width within your paintComponent method, every time it is called. However, for an approximation, I use the font size as the height and a fudge factor for the width: string.length() * fontSize * 0.545f (where we are working in float

Categories : Java

On button click, close the application Java GUI
Change this: if (result == JOptionPane.YES_OPTION) frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } to if (result == JOptionPane.YES_OPTION) System.exit(0); } frame.setDefaultCloseOperation is what happens when someone clicks the 'x' to close the window. Every other way to exit is controlled by you. The best way is to have your window closing listener and action listener call the

Categories : Java

escaping sed characters java not working
Try this: package org.script.test; import java.io.IOException; public class Main { public static void main(String[] args) { if (args.length != 1) { System.out.println("Invalid arguments"); return; } String entry=""" +args[0]+ """; System.out.println("adding: " + entry); Process pr = null; try { pr = Runtim

Categories : Java

How to create a data folder for my application?
Just as simple change this to your favorite directory: OutputStream output = new FileOutputStream(Environment.getExternalStorageDirectory() + "/ANYFOLDER/ANOTHERFOLDER/" + downloadedfileName); And remember that in the first create that directory with this code: File dir = new File(yourdirectory); if(!dir.exists()){ dir.mkdirs(); } Above code work if you added related manifest in your And

Categories : Java

Exponent of a number in a product
Well, this is basic math, but lets give you an anwer: first you factorize the small given number, lets call it a. Now you have a as a factor of primes (with some kind of exponents). Now you have to find out the exponents of these primes in the big number. Because they are primes, you can do this by finding the exponents in the factors of the product that you have and adding them together! you'l

Categories : Java

trying to send data to server using ajax post(), but cannot make the servlet linked to the ajax post() call run
Change your web.xml to something like the below <?xml version="1.0" encoding="ISO-8859-1" ?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>Application</display-name> &

Categories : Java

How to Use the same object among 3 different osgi bundles that is 3 different java plugin projects
I would then assume RegInfo is a type in the API package holding the interface. So the APP bundle would construct and configure a RegInfo object and pass it via the interface to the class implementing the interface. You don't mention using OSGi services, but this is the recommended way for the implementor bundle to make its implementation of the interface available to consumers. The app bundle w

Categories : Java

Hibernate foreign key of type String issue
I think you auto generate table by Hibernate entities. In this case you need to specify generate strategy. Select what you need: https://docs.oracle.com/javaee/5/api/javax/persistence/GenerationType.html

Categories : Java

Lwjgl and OpenGL - glTexCoord2f does not work as expected
I found the problem: OpenGL seems to scale the whole texture to the next power of 2, which would be for the height 128, equally to the original image, but for the width 1024. If I do all the calculation for animation.baseImage().width(); instead with 1024 everything looks like expected. Is there a way to avoid this?

Categories : Java

SQLite SELECT no longer works in Android API 21 but did in 18
SQLite MATCH in Android 5 does not work the same way as it did in Android <= 4.4 The prefixed '*' was simply ignored before 5.0. Since 5.0 it searches a string beginning with '*'. Wildcards can only be used as a suffix.

Categories : Java

java keystroke method call
You cannot use JMenuItem to create "hidden" short cuts. The short cuts of JMenuItems become active once the JMenuItem gets indirectly added to a Window (usually via <-JMenu<-JMenuBar<-JFrame). Without that link, it cannot be known whether or not the accelerator is to be triggered or not, as the same accelerator might trigger different actions in different application windows. You need to

Categories : Java

List method Adding always same values (SOLVED)
String [] dizi = new String [3]; dizi is a global variable getting overridden eveytime in the loop. Thats why you are getting same values at all indexes Make a new instance everytime before adding to the list.

Categories : Java

How to can I create an array of 10^15 positions?
Arrays in Java are limited to Integer.MAX_VALUE entries. If you need more elements, you need to have multiple arrays, each storing some part. It could look like this: long[][] array = new long[1_000_000][1_000_000_000]; BigInteger num = your-actual-array-index-you-want-access; int majorIndex = num.longValue() / 1_000_000; int minorIndex = num.longValue() % 1_000_000; array[majorIndex][minorIndex

Categories : Java

@Value -> Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'
If you are trying to access the property values using @Value("") annotation, you should declare PropertySourcesPlaceholderConfigurerBean. Try to add below snippet of code in your configuration class. @Bean public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); } If you don't want to declare it, Try with

Categories : Java

Set/Get Methods for Private Fields in Super/Sub classes
You can create getter and setter methods in the superclass like: public GeometricFigure(int length, int width) { this.length = length; this.width = width; } public Rectangle(int length, int width) { super(length, width); } Your 2 constructors could look like this.

Categories : Java

Apache POI - How to draw tables side by side in XWPFDocument
A table is a block-level item, meaning it will take up vertical space according to its height and span to the right margin of the page, whether it uses that space or not. So there is no way to "flow" two tables side-by-side in the same way there is no way to flow two paragraphs side-by-side. There are a few ways to achieve this effect, but probably the most straight-forward in your case is to cre

Categories : Java

JUnit test user input with Mockito
You need to Mock BufferedReader's readLine() API to return your value. i.e Mockito.when(mockedBufferedReader.readLine()) .thenReturn("1"); Now when you call the readInput() from the Test then your mocked buffered reader's API will be invoked.Hope this answers your question.

Categories : Java

How to add to a database from a web application?
You do not link the button to the Java code, you need to post via HTTP. You can create your form in html by using Spring form tags which provides some data binding facilities, or you can simply add html <form> with parameter names and action="addQuestion" and provide necessary form parameters, then your submit button will post this form to server handler "addQuestion" controller in your exam

Categories : Java

How to get Perticular character from String based on value in Java?
Try mod operator: int value = 6; System.out.println(base.charAt(value % base.length()));//F value = 7; System.out.println(base.charAt(value % base.length()));//L Remember You are saying 0 should give you F, so 10 would give you E and not M as below F L A M E S F L A M E S 0 1 2 3 4 5 6 7 8 9 10 11

Categories : Java

Sum objects based on field value using Streams API
You can still do it. Just change the mapping method : int sum = arr.stream().mapToInt(MyItem::getValue).sum(); You can even reduce your entire code snippet to a single line : int sum = Stream.<MyItem>Of(new MyItem(3),new MyItem(5)).mapToInt(MyItem::getValue).sum(); or even shorter (thanks to @MarkoTopolnik's comment) : int sum = Stream.Of(new MyItem(3),new MyItem(5)).mapToInt(MyItem::

Categories : Java

user input choice not recognized
You create a button but never add an ActionListener. Try this: next = new JButton("Next"); next.addActionListener(this); (I'm assuming Test2 is the ActionListener you want to use)

Categories : Java

Zipf's Law in Java for text generation - too slow
The implementation that you copied ... has some issues. One could probably say that it is plainly wrong, because it is using random values, and when in a computation like rank = rnd.nextInt(size); friquency = (1.0d / Math.pow(rank, this.skew)) / this.bottom; the rank value is 0, then the frequency is Infinity, and messes up some of the statistics. I tried to correct these erros, but have not

Categories : Java

WebLogic Transaction Manager
That is the correct call - from the documentation: If the initial context is obtained from a non-clustered server, then the server name specified should refer to the same server. If the initial context is obtained from a cluster, then the server name specified should refer to a server within the cluster. Just pick any server in your cluster and it should still work the same way. You will probab

Categories : Java

Synchronize across threads
You're constantly changing the sync object on which all threads are supposed to be synchronized. So, effectively, they aren't synchronized at all. Make your sync variable final, as every lock should be, and you'll see that your code doesn't compile anymore. Solution: synchronize on another, final object, or use an AtomicInteger and change its value, or synchronize on this (i.e. make the method sy

Categories : Java

I am getting this error: could not find Factory: javax.faces.context.FacesContextFactory
remove <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-impl</artifactId> <version>2.2.4</version> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-api</artifactId> <version>2.2.4</

Categories : Java

Android/Java - Wait for AsyncTask to end before performing next function
You can start an Indeterminate Progress Dialog (unCancelable) at OnPreExecute and then dismiss it in onPostExecute And if you don't want the code to get started executing before the asyncTask gets Completed, just put that code in onPostExecute method of AsyncTask

Categories : Java

Export doesn't appear when Jbutton is pressed on JFrame Form
The code in jButton1ActionPerformed is wrong: The first line should be enough, actually, as this will create a new X1 object, which sets itself visible. The second line creates another instance (what for??) and assigns it to G1 (please note: in Java, it is advised to use lower-case characters for starting variables). The third line then is invalid: It calls setVisible on the class X1, likely you w

Categories : Java

Spring MVC Java 415 Unsupported Media Type and path issue when posting data
You need to make sure that you are transferring correct HTTP header. In your case it should be: Content-type:application/json Because that what you defined your controller to accept. You also mentioned that you can't catch anything with breakpoint, that is because exception is beeing thrown in springs internal classes before your code is beeing reached. Also, if you don't want to follow stric

Categories : Java

Java 8 - converting an Integer to a long compilation issue
According to the JLS for Java 8 this should not happen: 5.1.2. Widening Primitive Conversion 19 specific conversions on primitive types are called the widening primitive conversions: [..] int to long, float, or double [..] 5.1.8. Unboxing Conversion [..] From type Integer to type int What should happen is an unboxing from Integer to int, and th

Categories : Java

Web service Client application
I am giving you 2 examples from your java application, you post an file to service. Apache HttpClient : String url = "https://yoururl.com"; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); // add header post.setHeader("User-Agent", USER_AGENT); List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePa

Categories : Java

Eclipse-Plugin: Separator Line between FieldEditor possible?
You can use something like: Label label = new Label(getFieldEditorParent(), SWT.NONE); label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 3, 1)); to add a blank like, or Label label = new Label(getFieldEditorParent(), SWT.SEPARATOR | SWT.HORIZONTAL); label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1)); to add a horizontal separator. This assumes

Categories : Java

Can`t I use jsf 2.0 el expression in f:attribute?
Is your toDoItemList list have field title? if yes , does title have getter and setters? And also please review jsf f:attribute

Categories : Java

Unable to configure Hikaricp 2.2.5 with Java 6
Couple of things. The exception in your stacktrace: at com.zaxxer.hikari.pool.HikariPool.addConnection(HikariPool.java:412) does not line up with a call to isJdbc41Compliant() in the 2.2.5 branch. That code was removed in 2.2.5. Second, if you are using 2.2.5 and you are setting jdbcUrl you do not need dataSourceClassName, they are mutually exclusive. Try a clean build, and as a last resort

Categories : Java

using string split failed in hadoop mapper
this is due to blank or space comes as a line, you have to filter it. if(s.length>1){ String[] s = value.toString().split("\s+"); String date = s[1]; } your problem solution // Map function: public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, DoubleWritable> { // private final static IntWritable one = new IntWritable(1); //private Text w

Categories : Java

I am looking for some sample code for SOAP messaging for my Web Service
I have tried to understand and help you. When you deploy the web service the SOAP message will look like. ` <definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.intech.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.intech.com/" name="HelloWorldImplService"> <types> <xsd:schema&

Categories : Java

Unable to start activity ComponentInfo{}: java.lang.NullPointerException Android
ListView located in fragment xml so you intialize ListView in fragment using fragment xml reference which v : v.findViewById(R.id.lv_produitsList) Instead of getActivity().findViewById(R.id.lv_produitsList)

Categories : Java

Timestamp resolution fails
Problem is in Java multiply/division operations are done before add/subtract try: if ((System.currentTimeMillis() - timestamp) < MAX_AGE) { Definition of MAX_AGE is also wrong: private static final long MAX_AGE = 1000 * 60 * 60 * 24; // 24h

Categories : Java


Recently Add
Redirecting the output directory of 'mvn package' or 'mvn compile' command
No suitable constructor found for ProductoExtranjero
java Composite design pattern(Directory &File)
Java JTree's ui refresh after removing node from parent
First REST Spring application
How to cancel Indexing of a Solr document using Update Request Processor
PowerMock - Mock a Singleton with a Private Constructor
Calling a Postgres stored function SQL error
Where to store Morphlines Java custom command class?
Generic repository using map
How can I scroll a ScrolledComposited in Eclipse SWT Design view?
2 Frames/layout in 1 Activity
Writing a switch differently
Next button opens another activity when its reaches the array limit
Is EclipseLink MOXy capable of applying JSR-303 Bean Validation when unmarshalling XML to object?
Why my jdk can't work,and before the java_home, there is a space that is not from me
How to add List of objects in a Map
How to make notepad++ function like regular notepad in cmd?
Cell renderer and the lost focus
how can I implement iterable for LinkedList>
Disable Androids image-crunch in eclipse (run as) builds
java 8 lambda myMap.stream().count() != myMap.size() after merging myMap
Issue with Calendar calculation that spans 2 calendar years
JSF 2.0 Spring bean injection
Java Regex ReplaceAll with grouping
Getting any word and last word using sed
Clicking on link on JEditorPane throws IOException
printing out difference of two arrays
Spring Bean Alias in JavaConfig
Using Factory Method to Create Generics
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.