[Solved] I want to extract strings from a line

Don’t use StringTokenizer: StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead. You can use split() if you split on 2 or more spaces: split(” {2,}”) … Read more

[Solved] I want to search for a product by its name and display the name and selling price in a JTextField in java [closed]

When you use a PreparedStatement you need to replace each “?” with a valid value before doing the actual query. So the basics of the code would be: String sql = “Select * from SomeTable where SomeColumn = ?”; PreparedStatement stmt = connection.prepareStatement(sql); stmt.setString(1, someColumnVariable); ResultSet rs = stmt.executeQuery(); solved I want to search for … Read more

[Solved] Project runs in eclipse but not in command line: File not found exception [duplicate]

I assume you are starting the program from the Builds directory – not the project root. Therefore the path src\data\pokemon.csv can’t be resolved. You have to either copy the jar to the project root or start the program from the project root dir with java -jar Builds\v1.0.jar 2 solved Project runs in eclipse but not … Read more

[Solved] Min/Max Values of an Array

Methods: public static int getMax(int[] a) and public static int getMin(int[] a) have int[] as their input parameter, but they are later called without any parameters: arr.getMax(); and arr.getMin();. This is the cause of the error you are getting from the compiler. EDIT: You probably want to modify your methods not to be static and … Read more

[Solved] Adding a number to the day or month or year in a date [duplicate]

In .NET you could do use the AddMonths method: DateTime date = new DateTime(2013, 5, 19); DateTime newDate = date.AddMonths(14); As far as parsing a date from a string using a specified format you could use the TryParseExact method: string dateStr = “19/05/2013”; DateTime date; if (DateTime.TryParseExact(dateStr, “dd/MM/yyyy”, CultureInfo.InvariantCulture, DateTimeStyles.None, out date)) { // successfully … Read more

[Solved] For loop not executed

I’m not sure what you are going for exactly but this is your problem in your loop t == 5 it should be something like for(int t = 1; t <= 5; t = t+1) { t is never 5 here so it will never iterate. Also, you can simplify the last part so it … Read more

[Solved] Java: split text [duplicate]

You can use Pattern and Matcher: String input = “Java: split text [duplicate],[description blablablablablabla]”; Pattern pattern = Pattern.compile(“\\[(.*?)\\]”); Matcher matcher = pattern.matcher(input); ArrayList<String> stringList = new ArrayList<String>(); while(matcher.find()) { stringList.add(matcher.group(1)); } //If you just need the results to be stored in an array of Strings anyway. String[] stringArray = stringList.toArray(new String[stringList.size()]); 1 solved Java: split … Read more

[Solved] Saving the current view as a bitmap

You try to add this listener to the onCreate event: myCustomView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { myCustomView.getViewTreeObserver().removeOnGlobalLayoutListener(this); do_your_logic_to_save_bitmap_from_view; } }); addOnGlobalLayoutListener will register a callback to be invoked when the global layout state or the visibility of views within the view tree changes. For example when the view is rendered completely. 3 solved … Read more

[Solved] Regex: find word with extra characters

I’m going to demonstrate required steps to cook a regex for word help but the requirements are not clear, rules are not strict hence some drawbacks are usual. \bh+[a-z&&[^e]]*e+[a-z&&[^le]]*l+[a-z&&[^ p l e ]]*p+\b ^ ^^ ^ ^ ^ | || | |–|-> [#2] | || |-> [#1] | ||-> Previous char(s) [#2] | |-> [#1] … Read more

[Solved] How to pass value from protected method to a public method?

Just tried to guess your code. Please find bellow explanation public class Main { String str = null; public static void main(String[] args) { Main m1 = new Main(); m1.setTheValueHere(); m1.getTheValueHere(“called by m1”); Main m2 = new Main(); m2.getTheValueHere(“called by m2”); } protected void setTheValueHere(){ str = “hello”; } public void getTheValueHere(String objName) { System.out.println(objName … Read more