[Solved] Passing String from one class to another

There are two ways: create an instance of your printer class and evoke the method on the printer object: public class MyPrinter { public void printString( String string ) { System.out.println( string ); } } in your main: MyPrinter myPrinter = new MyPrinter(); myPrinter.printString( input ); or 2. you create a static method in your … Read more

[Solved] Convert Date in Java [duplicate]

I would use the DateTimeFormatter for this. You can find more information in the docs. https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html However, here an example: DateTimeFormatter parser = DateTimeFormatter.ofPattern(“EEE MMM dd HH:mm:ss zzz yyyy”, Locale.US); LocalDateTime date = LocalDateTime.parse(“Sun Apr 01 01:00:00 EEST 2018”, parser); DateTimeFormatter formatter = DateTimeFormatter.ofPattern(“dd-MM-yyyy HH:mm:ss”); System.out.println(formatter.format(date)); //01-04-2018 01:00:00 The Locale.US part is required even if … Read more

[Solved] Code does not wait for FirebaseDatabase to be read

As Selvin commented: data is loaded from Firebase asynchronously. You can’t reliably wait for the data to become available. See Setting Singleton property value in Firebase Listener. The solution is to move the code that needs the data from Firebase into the onDataChange in checkDataNew: fun checkDataNew() { var rootRef=FirebaseDatabase.getInstance().getReference(“BG Data”) // Read from the … Read more

[Solved] Java constructor requires argument

Your constructor declaration is wrong. Constructors look like this: public Dog(String name) { this.name = name; } It does not have the void modifier. The constructor declaration in the class MyDog is correct but it is not correct in Dog. 0 solved Java constructor requires argument

[Solved] Java – Deleting certain lines from a file

This is partly finished code, to show you the idea what has to be done, but it may have some flaws, it uses Google Guava – http://code.google.com/p/guava-libraries/ import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import com.google.common.io.Files; public class LinesDeleter { private static boolean between; public static void main(String[] args) throws IOException { … Read more

[Solved] I want to separate several parts of a String in Java [closed]

This approach should work… // The variable ‘parts’ will contain 2 items: your 2 integers, though they will still be String objects String[] parts = myString.split(“mod”); try { int firstInt = Integer.parseInt(parts[0]); int secondInt = Integer.parseInt(parts[1]); ) catch(NumberFormatException nfe) { // One of your Strings was not an integer value } 0 solved I want … Read more

[Solved] printing Prime numbers in java

The first loop just for generating numbers from 2 to 100. The second loop tries to find if the number is divisible by any other number. Here we try to divide a the number with a set of numbers (2 to prime_index). Let’s say the number is 10, the prime index is 10/2 = 5 … Read more

[Solved] How to create list with combination of two list elements in java

I made a working solution, please find below. public class TestClass { static ArrayList<ArrayList<Integer>> fullData = new ArrayList<>(); static ArrayList<ArrayList<Integer>> finalList = new ArrayList<>(); static int listTwocounter = 0; public static void main(String[] args) { int listOne[] = {1, 2, 3}; int listTwo[] = {7, 8, 9}; int listOneCombination = 2; int listOneSize = 3; … Read more

[Solved] Java call a method from object

You have to pass the child object the parents own instance: public class Test { private ObjectClass object; public Test (){ object = new ObjectClass(this); } public void testMethod(){ //does something } } ObjectClass: public class ObjectClass { Test parentInstance; public ObjectClass(Test instance){ parentInstance = instance; } public void callMethod(){ parentInstance.testMethod(); } } solved Java … Read more

[Solved] Split Email:passrwords to list of emails and list of passwords [duplicate]

You can use split to first split at all linebreaks, then to split each line at the :. Of course you might run into trouble if the password contains a :, but that is a different task. String text = textArea.getText(); String[] lines = text.split(“\r?\n”); List<String> users = new ArrayList<>(lines.length); List<String> passwords = new ArrayList<>(lines.length); … Read more

[Solved] error compilation in print method [duplicate]

You have written the following code: private void print(String string) { return string; } But void here is the return type. It thus means you cannot return anything. If you write String instead of void then it will mean that the return type will be a string which is the case and the error will … Read more

[Solved] Android listview array out of bounds

Try this, you have to pass in your Adapter and call notifyDataSetChanged on it after you clear the list. @Override protected void onPreExecute() { super.onPreExecute(); postList.clear(); yourAdapter.notifyDataSetChanged(); } Edit: Alternative way private class LoadMoreDataTask extends AsyncTask<Void, Void, List<PostRow>>{ @Override protected void onPreExecute() { super.onPreExecute(); //postList.clear(); //do not clear } @Override protected List<PostRow> doInBackground(Void… params) { … Read more