spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » JAVA » Page 53
How to check if I set CLASSPATH correctly? (Junit error)
You need to add hamcrest-all.jar to your classpath also. This question is answered here: java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

Categories : Java

no such sql table error in android
The problem is that since i already created the database and when i try to add another table to the database i get a table does not exist error. To fix this i deleted my database and then recreated the database/tables.

Categories : Java

JAVA Arrays - Need somebody to explain what this code does?
(1) You declare int temp to store the value of variables that are being swapped in the array, so when you overwrite one of the array elements, you still have the variable value. You don't need to use an entire array for this. (2) The code you don't understand swaps the array values at numbers[i] and numbers[numbers.length - 1 - i], using temp as a placeholder.

Categories : Java

Eclipse - Run on Hadoop does not prompt anything
I think the problem is with the jar file you used for hadoop client to server, So What happens is it tries to stay in the following line and try to search for the server Configuration config = new Configuration(); Try to debug and let us know if you face any more problem, If not try the following Have you tried running the program on eclipse by pointing the core-site , hdfs-site Configurat

Categories : Java

Good Practices For Generating Variations of SQL Queries
There are more than one good solutions for this - there are several tools for creating typesafe and easly manipulable SQL strings out there in Java. But since you are using Oracle, the best way to go is probably prepared statements. http://en.wikipedia.org/wiki/Prepared_statement https://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html

Categories : Java

java PrinterJob not printing to fit paper
It looks like you are printing the image with dimensions based on the PageFormat, rather than the actual image's dimensions, your drawImage() method should look something like this graphics.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null)

Categories : Java

Java - JDBC executeUpdate() not working
If you didn't get an exception, which you don't state one way or the other, you need to examine the return value of executeUpdate(), which is the number of affected rows. If it was zero, no rows were deleted, probably because nothing matched the WHERE clause. If it was non-zero, that many rows were deleted. You certainly shouldn't be printing "Record is deleted!" when nothing may have happened at

Categories : Java

Infinite image Scroll
For infinite scroll you can use CWAC MergeAdapter. Here you can read what it is and how it works: https://github.com/commonsguy/cwac-merge

Categories : Java

Fragment application displaying 2 instances of the same fragment in Android Studio
What is the problem here? If you use the <fragment> tag, do not also use a FragmentTransaction to add the same fragment. Those are two separate techniques and should not be mixed. Simply get rid of every line from onCreate() except the call to super.onCreate() and the setContentView() call, and stick with your static <fragment>.

Categories : Java

how to acess image path from onActivityResult method to AsyncTask doInBackground method in android
That's because you made path a local variable of onActivityResult(). Make it a variable of your activity. Change String path = getRealPathFromURI(.. to path = getRealPathFromURI(... And declare String path=""; in the activity.

Categories : Java

Structure for Employee Supervisor hierarchy approval
The best way to lay out a class design is to use the "IS A" test. An employee "IS A" human, therefore the employee class should extend the human class. A supervisor "IS A" employee, therefore the supervisor class should extend the employee class. In regards to having a supervisor with a supervisor, the supervisor should be a field in the employee class, this way every employee (And remember a s

Categories : Java

Variable (matrix) changing its value - Java
When you do this ... int[][] auxiliar_matrix = mc.matrixStructure.matrix; int[] original_ordering = mc.matrixStructure.matrixOrder; ... you are making auxiliar_matrix and original_ordering references to the same objects that mc.matrixStructure.matrix and mc.matrixStructure.matrixOrder refer to. Modifying those objects via one set of references is equivalent to modifying them through the other,

Categories : Java

How Can newInstance() Work If There Is No Constructor Written?
This is because Java will create a default, no-arguments constructor if none is provided. It will set all reference fields to null, numeric types to 0, and booleans to false, and invoke the superclass constructor. JLS 8.8.9: If a class contains no constructor declarations, then a default constructor is implicitly declared. The form of the default constructor for a top level class, member

Categories : Java

Create an Arraylist from a String
I understand that your elements you want to add to the ArrayList are separated with a space in your string: List<String> l = Arrays.asList(tmp.split(" "));

Categories : Java

Access fragment from activity besides main activity
Well, first of all, here is the code I was talking about in my comment: btnSearch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { menuActivity m = dialog.getOwningActivity(); final TabInfo tab = m.getCurrentTabInfo(); final PlacesSearchFragment fragment = new PlacesSearchFragment().setNAV(m).setSearch(txtsearch.ge

Categories : Java

Pass non printing character to shell command for Hadoop Streaming Separator
If you're talking about bash or other common Linux shells, you can enter any character literally by preceding it with ctrlV. I'd put it in single quotes just to be sure the shell doesn't treat it specially in any way. So it will be something like stream.map.output.field.separator='^A' where you produce the ^A by typing ctrlV followed by ctrlA. Mind you, the shell will pass it correctly, but I can

Categories : Java

Exception when passing value from scanner
By using this code: try (Scanner input = new Scanner(System.in)) { how_much = input.nextInt(); } You are using the auto-closing feature of the try-with-resources syntax of Java. The Scanner gets a call to close(), which closes the underlying System.in, so creating a new Scanner the next time on System.in doesn't work, because System.in is closed. Instead create one scanner and use it for eve

Categories : Java

How to change Android Notification bar, but color system bar at the bottom a different color
I figured it out, this may not color the nav bar, but it gives me the desired result: tintManager.setNavigationBarTintEnabled(false); This line set the nav bar to clear, which was my desired result. I also found: tintManager.setNavigationBarTintColor(Color.BLACK); which can set the nav bar to any color. I am closing this question with this answer.

Categories : Java

Will Not Compare 2 strings that are equal that were read in from PrintWriter
Let us look at showCountries method: public boolean showCountries(String paramCountry, int where) { //.... return false; } I removed every line, that does not contain a return statement. As you can see, you always return false no matter if the searched element was found or not. Therefore this loop: while (error == false) { //... } is like an infinite loop. Change the code in yo

Categories : Java

what happens when java builds the jar (war)
That will depend on how you configure the dependencies in Maven. Using a dependency scope "Runtime" for externalProject while configuring dependencies for myProject in its pom.xml file, indicates to the dependency management framework within Maven that it is not required for compilation, but is for execution. Similarly using "compile" which is also the default scope, indicates that project be incl

Categories : Java

Java File I/O: Why do I always get an I/O exception?
You cannot read from and write to the file at the same time, this will throw an IOException. You should close anything that has access to the file before trying to access it with something else. Invoking the close() method on BufferedWriter before trying to access the file with BufferedReader should do the trick. EDIT: Also, as others have mentioned, you can use e.printStackTrace() to see where a

Categories : Java

method calling and sending is off
Doesn't it work or you just get errors and can't compile? If the secon one, ofc there is a problem that 'max' is not defined in secondaryMethodCalls and count is not defined ither in printMax. As long as they aren't global variables.

Categories : Java

Argument dump format error on starting a rails server
update JRuby to it's latest 1.7.x (1.7.16.1 or at least 1.7.13) ... there's been a lot of Ruby (1.9.3) compatibility (e.g. encoding related) fixes since 1.7.3, it's not worth exploring the issue on it. if it still happens, you should try if it's the same failure on MRI. it also would be valuable (esp. for yourself) to upgrade to latest Rails in 3.1.x if you can not go to a supported 3.2.x release

Categories : Java

How to loop through an array and create substrings from an ArrayList?
Use a foreach loop: List<String> list = new ArrayList<String>(); List<String> msgs = new ArrayList<String>(); for (String s : list) { msgs.add(s.replaceAll(".*'(.*)'.*", "$1")); } list = msgs; Using regex to extract the string is cleaner and still scalable enough.

Categories : Java

Share objects from phone to android wear
Yes, this approach is good and correct one. Yes it is possible to send multiple but you should be aware that they are not "send" they are more something like shared or synchronized between phone and Wear, and can be modified in any further point in time (however I would recommend to save them to SharedPreferences on Wear to be able to access them in offline mode. So Message API sends objects (f

Categories : Java

concrete facade for JPA controller classes from abstract, generic facade
You are right with the assumption that these parts are repetitive and therefore evitable. Netbeans shows you a way to realize it when you use the wizard to create JSF Pages form Entity Classes. The result looks like this: AbstractFacade.java: public abstract class AbstractFacade<T> { private final Class<T> entityClass; public AbstractFacade(Class<T> entityClass) {

Categories : Java

Hibernated error embedding object with primary key
I believe a @MappedSuperclasss can only be extended by @Entitys, not @Embeddables. The documentation says Designates a class whose mapping information is applied to the entities that inherit from it. Anyway, I think the issue is when you @Embed the City in Country you are also embedding a second @Id attribute. You have an @Id attribute inherited by Country from Place and also an @Id attribut

Categories : Java

Class cast exception while adding a second tree node to PriorityQueue
The exception is telling you, make Node implement Comparable<Node>. You can insert the first node because it has nothing to compare to, so the comparison is not needed.

Categories : Java

hadoop cluster is using only master node or all nodes
Discussed in the chat. The problem is caused by incorrect Hadoop installation, in both cases job was started locally using LocalJobRunner. As a recommendations: Install Hadoop using Ambari (http://ambari.apache.org/) Change platform to CentOS 6.4+ Use Oracle JDK 7 Be patient with host names and firewall Get familiar with the cluster commands for health diagnostics and default Hadoop WebUIs

Categories : Java

Java Google App Engine Task Queue freezes / stalls
Your tasks take between 1 and 2.5 seconds to execute. You set the concurrent limit at 10 and the execution rate at 25/s. These settings are obviously impossible to achieve with the aforementioned execution time. Notice how App Engine quickly accepted your first 10 tasks, accepted 11th after a slight pause, then realized that none of the tasks completed and decided to wait. Then it accepted anothe

Categories : Java

"Exception in thread "main" java.util.InputMismatchException"**
Nothing is wrong with your code. Respect the type when you are entering your data. Do not enter a double while you are expecting an integer, etc. You can get around this type of error by applying defensive coding where you only accept data from the user when it complies with the expected value. public static void main(String[] arg) { Scanner keyboard = new Scanner(System.in); System.

Categories : Java

How to find the floor and remainder of a fraction in Java?
Implementation 1: Floating Point Uses floating point math to simplify the logic. Be warned that this will produce incorrect results for large numbers due to loss of precision. public static long[] floorAndRemainder(long a, long b) { long floor = (long) Math.floor(a / (double) b); long remainder = Math.abs(a - floor * b); return new long[] { floor, remainder }; } Implementation 2: Find, t

Categories : Java

How to populate 2 array's from one txt file
It will break because you have a total of 9 + 7 = 16 integers. With your loop, you will read 2 * 8 and arr1 is only of size 7. So you will only read 14 integers and won't affect them correctly. You need to read a full line at a time into a string, splits that string on spaces ("s+" see javadoc of String.split() ...)and convert each item to an int to store it in your arrays.

Categories : Java

How to add object to existing ArrayList? (java)
You method requires a Lamp argument, thus you should provide a Lamp object. Depending on how your Lamp method looks like, your main code should do something like: public static void main (String[] args) { Lamps ls = new Lamps(); ls.addLamp(new Lamp());//or provide additional arguments, if required. }

Categories : Java

Unchecked generics or object boxing?
You appear to have the logic of Class.isAssignableFrom() backwards. If the objective is to retrieve the first component that is assignment-compatible with a given type, then I would probably write it like so: public <T extends Component> T getComponent(Class<T> type) { for (Component c : this.components) { if (type.isAssignableFrom(c.getClass())) { return type

Categories : Java

Java template method pattern
If I understood your question correctly, you can try the following: public abstract class Reporting { public void setUp(Job job) { // set things up } public void tearDown(Job job) { // post-processing stuff } public void process(Job job) { setUp(job); doProcessing(job); tearDown(job); } public abstract void doProcessing(Job job); } public class Processor1 ext

Categories : Java

NullPointerException when getting WindowManager from Service under Robolectric
No Context, no ContextWrapper. You have to attach a Context before your create a Service instance. So just call attach() before create(). So it will look like this: @RunWith(RobolectricTestRunner.class) public class MyServiceTest { @Test public void someTest() { Robolectric.buildService(UpdateService.class) .attach() .create() .get()

Categories : Java

How to make a method that searches a parallel array?
You're looking for the user submitted country in your array to use the corresponding index : for ( int i = 0; i < country.length; i++ ) { if (country[i].equals(user_input)) { System.out.println(country[i] + "'s population: " + population[i]); break; // gets you out of the loop } } It's also a good programming habit to save an array's length in a variable as such : f

Categories : Java

Reading Into GSON for list of top level tags
Assuming that... Region names are all different. Logo names in a given region are all different. Logo's attribute names in a given logo are all different. ... the most flexible way to parse your JSON I can think of would be using Map classes. Something like: Type mapType = new TypeToken<Map<String, Map<String, Map<String, String>>>>() {}.getType(); HashMap<Str

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.