[Solved] Checking int cast from null

If you try and cast null to an int, you will get a NullPointerException. If you want to null-check it, you can use an Integer or Object variable. Integer r = (Integer) map.get(“some_integer”); if (r==null) { // whatever you want to do in this case } else { int result = r; // whatever you … Read more

[Solved] Writing to a file errors – Android Studio

Well… In android you should save the info in a DB or use SharedPreferences. Its really simple: SharedPreferences sp = getSharedPreferences(SHARED_PREF, getApplicationContext().MODE_PRIVATE); Editor editor = sp.edit(); editor.putString(SP_NAME, etName.getText().toString()); editor.commit(); And if you want to recover the information: SharedPreferences sp = getSharedPreferences(SHARED_PREF,getApplicationContext().MODE_PRIVATE); String cadName = sp.getString(SP_NAME, “”); if (cadName.length()>0){ Log.d(“HELENA”,”info saved : “+cadName); } else Log.d(“HELENA”,”No … Read more

[Solved] File not found in Java [duplicate]

If it is a regular file outside a .jar, you are using a relative path. That means, the path to the file is formed from the path where you are calling the file from + the relative path. To make it work, you should invoke java within src folder solved File not found in Java … Read more

[Solved] What is the reason behind this infinite loop?

You must also reevaluate the boolean expression to set your value in the loop body for it to work, like final int LIMIT = 5; // <– try to avoid magic numbers. boolean myBoolean = (value < LIMIT); // <– assigns the result of the expression // `value < LIMIT` to `myBoolean`. while(myBoolean) { System.out.println(value); … Read more

[Solved] why for loop is taking too much time in given java code

my problem is resoled by following code : String extractText(String s) throws IOException { String html = fj.toHtmlString(s); String filtered_text=””; System.out.println(“extracted \n\n”); html=html.replaceAll(“(?i)</strong>”, “”); html=html.replaceAll(“(?i)<strong[^>]*>”, “”); filtered_text = html; long end = System.currentTimeMillis(); System.out.println(“loop end in “+(end-start)/1000+” seconds”+” or “+(end-start)+” miliseconds”);//System.out.println(++i2+” th loop end in “+(end-start)/1000+” seconds”); return filtered_text; } solved why for loop is … Read more

[Solved] Calculating weekly salary – Total value not correct

The problem lies in this method. public void increaseHours (double x) { Hours = increaseHours + Hours; } Firstly, you are using the wrong field (increaseHours) instead of x. So please delete this line: private double increaseHours = 10; And now update your method: public void increaseHours (double increaseHours) { Hours = increaseHours + Hours; … Read more

[Solved] Mouse event handling in Swing

Add an actionlistener to your JButton and it will tell you when its been clicked like so: someButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { //the button was pressed and do your stuff here. } } 3 solved Mouse event handling in Swing

[Solved] com mysql jdbc exceptions jdbc4 mysql syntax error exception

‘Post_held=”+post_held+”‘where should be Post_held='”+post_held+”‘ where. On a different note: DO NOT build a SQL statement using string concatenation like that, or you leave yourself open to SQL Injection attacks, which will allow attackers to delete/steal all you data. Use a PreparedStatement with parameter markers (?) and set the values on the statement object. solved com … Read more

[Solved] Inputting Number in Array and Displaying it? [closed]

I think you are a beginner. So i will help you to get stand. Try this code. class InputTest { public static void main(String[] args) { System.out.print(“Enter size of array: “); Scanner scanner = new Scanner(System.in); int numberOfArray = scanner.nextInt(); Integer[] input = new Integer[numberOfArray]; for (int i = 0; i < numberOfArray; i++) { … Read more

[Solved] Random boolean is always false [closed]

boolean nice = rand.nextBoolean(); is declaring and assigning a local variable. You aren’t assigning the field, so it will always have its default value, false, when you access it with the getter. Drop the boolean. 1 solved Random boolean is always false [closed]

[Solved] GeometricObject and circle class

If you mean why can’t you invoke the getArea() and getPerimeter() methods, it is because they are abstract. You cannot invoke an abstract method. An abstract method must have an implementation in a concrete class. Also, you cannot instantiate an interface or an abstract class. You can only instantiate concrete classes (and they may implement … Read more

[Solved] JAVA – How to get last/recently CREATED folder name in a directory? [closed]

It takes a few steps, for example: list all elements of a directory filter for directories get file creation time save up the path + time combo in a list find the minimum of the list with respect of time import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.FileTime; import java.util.ArrayList; import … Read more