spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » JAVA » Page 4
How to refresh the Java servlet page automatically
You can use this to refresh the page I have used this before just put this at the end of your html or jsp page: <script type="text/javascript"> var cookie = ("" + document.cookie); if(!cookie.match(/S/)) { document.cookie = "refresh"; location.reload(true); } else { document.cookie = "refresh; expires=Thu, 01 Jan 1970 00:00:00 GMT"; } </script> This will set a cookie the

Categories : Java

Calling get() and put() method of Hashmap correctly.
Typically, you would use synchronization to accomplish this. The simplest form of this would be to synchronize the method itself. public synchronized ReentrantReadWriteLock getLock(String tableName) { However, if you are concerned about performance I would consider the following approach which uses a synchronized block, but only if the initial lock isn't found. public ReentrantReadWriteLock g

Categories : Java

Use JSP with Tomcat without connected Servlet
There is no such thing as a JSP that doesn't require a servlet. Every JSP is compiled into a Servlet. It is not a flat requirement to put a Controller Servlet in front of a JSP, and that seems to be what you're really asking. You may put your JSP files in the root of the WAR (anywhere except under WEB-INF, if your JSP files are stored under WEB-INF then you must use a servlet controller) and the

Categories : Java

Android 5.0 ART native DeleteGlobalReference(jobject) is failing
You shouldn't call DeleteGlobalRef on a local ref - only on the actual jobject pointers that you've got returned from NewGlobalRef. So in this case, as long as you aren't calling NewGlobalRef, you don't need to call DeleteGlobalRef either. You only need to use NewGlobalRef if you store a reference to an object on the native side, for use after the JNI function call returns. ART is a little bit s

Categories : Java

ArrayList> IndexOutOfBoundsException
What you want to do is first add something in a Since you are always reading the i value on the outer list we add a new array list on the outer loop. import java.util.ArrayList; public class abc { public static void main(String[] args) { ArrayList<ArrayList<Integer>> a = new ArrayList<ArrayList<Integer>>(); for(int i=0;i<10;i++) { a.

Categories : Java

Java Programming using Objects/ Methods
You are modifying the local variable amount, instead of modifying balance. In getWithdraw, change amount = balance - amount; to balance = balance - amount; and likewise for the getDeposit method. Incidentally, it's unclear why you are calling those methods getWithdraw and getDeposit, since those methods make withdrawals and deposits, respectively. I would have called them withdraw and dep

Categories : Java

Xamarin Android Vertical ViewPager
The reason of black screen is that you set your screen position out of visible bounds. Your visible bounds are from 0 to page height. Try his : "yPos = position * pageHeight;" instead of "yPos = position + pageHeight;"

Categories : Java

Twilio: Twilio.Device.connect() not hitting voice request URL
I had the same problem, You need to call the function generateToken() after calling allowClientOutgoing() and allowClientIncoming() so that the object created by Services_Twilio_Capability() has the app link. This works: $objToken = new Services_Twilio_Capability($accountSid, $authToken); $objToken->allowClientOutgoing('APXXXXXXXXXX'); $objToken->allowClientIncoming($_REQUEST['name']); $s

Categories : Java

Not-null property references a null or transient value for persisted value
Aside from having a Parent with a FK to a Child issue, the persist order is what causes your issue. Your problem is related to flushing. Just because you instructed Hibernate to persist an object, it doesn't mean it automatically serves your request. The persist request goes to an action queue only to be materialized at flush time. So your second persist simply find the Parent entity without an a

Categories : Java

How to extract multiple regex matches from a string in java
You can use this MessageFormat.format(str, list); where the str=hello {1} welcome to {2}. you are enrolled in {3} and the just pass the values in the list

Categories : Java

How do I select list of generic objects in abstract service using CriteriaQuery
Here's what fixed it: //grabs the primaryKeyClass from generic type argument list (this was AbstractService<PK, T>) @SuppressWarnings("unchecked") protected Class<PK> primaryKeyClass = (Class<PK>) GenericTypeResolver.resolveTypeArguments(getClass(), AbstractService.class)[0]; protected Class<PK> getPrimaryKeyClass() { return primaryKeyClass; }

Categories : Java

Unable to reverse a String after converting it to String Array
The compiler message is clear: reverse is not a method of String. Try: String reverse = new StringBuilder(words[i]).reverse().toString();

Categories : Java

How to iterate through LinkedHashMap to the xth element?
Use a counter: int counter = 0; for (Entry<String, Integer> entry : existingFile.entrySet() ) { if (counter == 5) break; builder.append("{" + entry.getKey() + "," + entry.getValue() + "} "); counter++; }

Categories : Java

How much RAM samsung devices do normally allocate for Android apps?
You are asking the wrong question. You should be trying to figure out how to make your application less memory-hungry, not trying to find workarounds for specific vendors/OEMs. For some guidance, this article is particularly helpful: Managing Your App's Memory. Since you mentioned that you are attempting to use the largeHeap attribute in your manifest, you might want to read the following snippet

Categories : Java

Using biginteger to find the sequence of sum of powers
Here is a clue computing some factorials: import java.math.*; public class FactorialBig { public static BigInteger factorial(BigInteger n) { if (n.equals(BigInteger.ZERO)) return BigInteger.ONE; else return n.multiply(factorial(n.subtract(BigInteger.ONE))); } public static void main(String[] args) { for (int n = 0; n < 20; n++) {

Categories : Java

Galton Box; Printing a histogram
First, there is no real need for you to keep the array arrayslot, because you print the array element right away, and you don't do anything with it afterwards. So you can just print the character: if ( k < 0.5 ) { System.out.print("L"); } else { System.out.print("R"); } As you notice, there is also no need for an else if. Ei

Categories : Java

ECC Encryption and Decryption in Java
In general you are required to perform hybrid encryption with ECC. ECIES for instance is basically a key agreement followed by symmetric encryption. So you cannot directly encrypt anything with ECIES, which is the most common ECC method for encryption. Basically you should couple it to a symmetric cipher. This is actually the best scheme for RSA encryption as well, most of the time. As you can

Categories : Java

Online grading says my output values are not correct but I don't see why?
You're printing The " + c.getYearModel() + " " + c.getMake() + "is going: " + s 5 times. You should put that outside the loop so it's printed once only. IMHO I don't think you need to be returning the speed from the accelerate() function either. I'd suggest making that a void function and using the getSpeed() method instead of assigning to an intermediate variable.

Categories : Java

Why is multiplied many times faster than taking the square root?
Squaring a number is effectively an integer operation while sqrt is floating point. Recognizing the run-time allocations for casting and computation the results you have observed are not surprising. The Wikipedia page on sqrt http://en.wikipedia.org/wiki/Square_root has a nice section on computation. As for the faster method I trust you can investigate (sub)linear run-time operation n^2. On the

Categories : Java

Determine When LoopJ has concluded all background connections
The following code should address your problem: Class file: UploadRunner.java public class UploadRunner extends AsyncHttpResponseHandler implements Runnable { private final AsyncHttpClient client; private final ArrayList<String> filesList; private final int filesCount; private final Handler handler; private String baseURI; private boolean isFired; private int filesCounter;

Categories : Java

How to use multiple ServerBootstrap objects in Netty
Following example you referenced and adding your question on sync() method, here an example code: EventLoopGroup bossGroup = new NioEventLoopGroup(numBossThreads); EventLoopGroup workerGroup = new NioEventLoopGroup(numWorkerThreads); ServerBootstrap sb1 = null; ServerBootstrap sb2 = null; ServerBootstrap sb3 = null; Channel ch1 = null; Channel ch2 = null; Channel ch3 = null; try { sb1 = new S

Categories : Java

How can I run a large gremlin script in rexster console?
Someone posted a problem and fix in relation to this error: https://github.com/tinkerpop/rexster/issues/374 The fix was implemented, but it is not in an official release yet. I wonder if your issue is resolved in the 2.7.0-SNAPSHOT. 2.7.0 should be compatible back to 2.5.0 graph implementations so i would expect it to be ok to upgrade. So, you could either build the console from master or mor

Categories : Java

no such column: KEY_PUBNAME
If you see your DatabaseHelper, you've defined following: //---deletes a particular pub--- public boolean deletePub(String Pub_Name) { //delete statement. If any rows deleted (i.e. >0), returns true return db.delete(DATABASE_TABLE, "KEY_PUBNAME = "+ Pub_Name+" ", null) > 0; } The keyname you've mentioned is KEY_PUBNAME. However where you've created the table, the keyname you'

Categories : Java

Can JUnit make assertions about all Strings?
No, there is practically an unlimited number of possible inputs. Its your job to separate them into test cases with (expected) equivalent behaviour. If such an artificial intelligence would exist, then it could also write the code to be tested. There exist test case generators, that auto create test cases, but they are mostly useless. They produce a huge amount of test cases, and mainly only touc

Categories : Java

what broke up in my eclipse?
1.Check whether JRE is properly installed in your system and it is added in Eclipse. You can try re-installing JDK in your system and Add JRE to Eclipse from Window -> Preferences -> Java -> Installed JREs.

Categories : Java

How to run a java jar file which is in amazon s3
It cannot be done. Since Amazon S3 is a Storage Location it is not an instance. To run a jar it need a instance that is a Operating System. To trigger a Jar File. Create a EC2 instance and put it in a location and you can trigger it from a instance.

Categories : Java

Detect click on a line
Have a look at this answer: Shortest distance between a point and a line segment They calculate the shortest distance from a point to a segment. Having calculated this value, you can accept or reject the mouse click event: if ( distanceToSegment(...) < threshold && mouseClicked()) { // insert code here } The threshold will depend on how precise you want the user to be.

Categories : Java

Validation form in Spring using @Valid not work
Are you sure that the validations don't work? Unless you have for example StringTrimmerEditor registered, your fields will actually be String instances with length equal to 0, not null values when you submit the form and therefore the annotation would consider such values to be valid. If you want to validate that String is not blank (not null and not an empty String), use for instance the @NotBla

Categories : Java

Out Of Memory with images in Android 5
Resolved the problem using this guide: http://developer.android.com/training/displaying-bitmaps/index.html

Categories : Java

Creating images in SVG and rendering them in HTML using Base64 encoding URI and JAVA
Why are you returning a data URL from the server? Just return the SVG itself. There is no need for the data:image/svg+xml;base64,. out.write(imageString.getBytes()); You should also make sure you are returning the right MIME type. Ie.: response.addHeader("Content-Type", "image/svg+xml"); This lets the browser know that the response is an SVG file.

Categories : Java

Spring request using list as extension
<entry key="list" value="application/json" /> this is not valid. From the PathExtensionContentNegotiationStrategy javadocs: A ContentNegotiationStrategy that uses the path extension of the URL to determine what media types are requested. The path extension is first looked up in the map of media types provided to the constructor. If that fails, the Java Activation framework is

Categories : Java

Android L 5.0 & libusb 1.0.9 - no permissions?
I uploaded a solution that works. it's based on libusb 1.0.9 and working with Lollipop. https://github.com/Gritzman/libusb

Categories : Java

RCP 4 Toggle a button in the toolbar
When you add the 'Handler Tool Item' to the Toolbar in the Application.e4xmi you can specify the 'Type' as 'Check' to get the pressed / not pressed behavior. In your Handler for the item you can inject the 'MToolItem' so that you can test the checked state: @Execute public void execute(final MToolItem item) { if (item.isSelected()) ... button pressed in else ... button not pressed }

Categories : Java

Getting child class items only from an ArrayList
If you are forced to use a combined list you can use instanceof to check if it's a book.. public void printAllBooks() { for(Item i : items){ if(i instanceof Book){ System.out.println(i); } } } But a better design might be to have separate lists of books and dvds

Categories : Java

Volatile variables and the use of synchronization blocks
If you're simply reassigning the volatile variable, it shouldn't require synchronization. That's the idea behind them. Actually, in this case it wouldn't even have to be volatile because the new value true doesn't depend on the old value of selector so it wouldn't matter if it has been changed by another thread.

Categories : Java

print elements in decreasing order of ArrayList
You don't need to define the size of an arraylist. An array list is a dynamic array where the size can change dynamically. list.add(0,reader.readLine()); for (int i=0;i<=4;i++){ list.add(0,reader.readLine()); } This will add each next element at position 0 moving everything back 1. You were trying to insert at position 4 when the arraylist is size 0.

Categories : Java

What does "java.sql.SQLException: Unsupported feature" mean?
I would say that the feature is not supported in any version of the JDBC driver, and will never be supported. The version of the database in this situation is not relevant. I can't say why there ever was a setCursor() method declared in OraclePreparedStatement. I would guess that it was a mistake in the design of the API. In fact, you get a deprecation warning if you compile any code that atte

Categories : Java

Listing and counting files by their extensions
You can use a Map for it: The code would be: Map<String,Integer> countExt = new HashMap<String,Integer>(); // Start from here inside your if statement ext = fileName.substring(fileName.lastIndexOf(".")+1); // If object already exists if(countExt.containsKey(ext)){ Integer count = countExt.get(ext); count++; //Remove old object and add new

Categories : Java

How can I use this method in conjunction with another method?
First of all I noticed in your last method gradeMessage you create a String variable message and try to print it out rather than trying to print out the result parameter passed into your method. For example your last method should look like this: public static void gradeMessage(String result) { // Compute if grade leads to pass or fail if (result == "F") { System.out.println("Unf

Categories : Java


Recently Add
How to convert this for loop into an enhanced loop
Do-while, try-catch loop error
JavaFx use String with Double on table column
Equal Spacing In print statements
Android Poor Image Quality When Saving Image From takePicture callback
Why ConcurrentHashMap put() return null but the item is put successfully?
Executing the java program from command prompt
Query multiple Entity attributes with List of values
Android Collections.sort - doesn't work properly
Gdx.files.internal(...) wrapper not working correctly
How to do character math?
Android - How to stack the views added dynamically?
Java: implement a loop with duplicate values in Array
Graphics paint component and loop trouble
Java: Transfer a file from server to client and from client to server
Problems with struts2 interceptor
Beginners Java Blue J returning a String in a method
How to pass Array of complex objects as a IN parameter in a stored procedure using JPA 2
Android: Finding fundamental frequency of audio input
Generic Java Logger output null.null for class and member name
How to use semaphores correctly
Hystrix: HystrixBadRequestException for failed validations
Sending a file over java socket
How can I make a variable work in more that one class? (Java)
Java - What are the layout managers available in awt.* and swing.* packages?
Reading ints from file and storing value to an array
random integers between 2 values
Maven -- is there a command to download the parent poms of all dependency jars?
Null Pointer Exception in Array when adding ActionListener
Hystrix Request Caching by Example
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.