[Solved] Error:(106, 20) error: method onCreate(Bundle) is already defined in class MainActivity

The part I’m trying to add You should be adding this part into the existing onCreate method, not the entire method body // Load an ad into the AdMob banner view. AdView adView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder() .setRequestAgent(“android_studio:ad_template”).build(); adView.loadAd(adRequest); // Toasts the test ad message on the screen. Remove this after … Read more

[Solved] Return something in a java method in a if condition

All possible code paths must return a value. In this case, if none of those if conditions are satisfied, nothing is being returned. You must have a final else that returns something. public static char Feld(){ if (vertical == 1 && horizontal == 1) { return Feld11 = Player1; } else if (vertical == 1 … Read more

[Solved] Printing out multiple random results

The reason why you’re getting the same answer 5 times is because your do-while loop runs 5 times without changing the ‘creatures’ . System.out.println(a +” “+ b + ” ” + c + ” ” + d + ” ” +e); If you remove the do-while loop you’ll get the same answer only once however … Read more

[Solved] Let’s say I have an array of characters (a string ) and I want to count how many time each character appears. However there should be no if

Let’s say I have an array of characters (a string ) and I want to count how many time each character appears. However there should be no if solved Let’s say I have an array of characters (a string ) and I want to count how many time each character appears. However there should be … Read more

[Solved] Generating a Random String Array

You can do it using nested loop, as you said in the question: public String[] randomArrayString(int length, int numberOfChar) { Random random = new Random(); char[] chars = “abcdefghijklmnopqrstuvwxyz”.toCharArray(); String[] array = new String[length]; String str; for (int i = 0; i < length; i++) { str = “”; for (int j = 0; j … Read more

[Solved] Java Incompatible types: inputstream cannot be converted to scanner

private ArrayList<Student> readFile() throws FileNotFoundException { String fName = “p02-students.txt”; Scanner scan = new Scanner(new File(fName)); ArrayList<Student> studentList = new ArrayList<Student>(); while (scan.hasNext()) { String studentType = scan.next(); if (studentType.equals(“C”)) { studentList.add(readOnCampusStudent(scan)); } else { studentList.add(readOnlineStudent(scan)); } scan.nextLine(); } scan.close(); return studentList; } I didn’t get the error you mentioned earlier, but I was getting … Read more

[Solved] Word count in descending order using java lambdas

This is one way (it does create two streams and does merge the two lines of code): Map<String, Long> map = Arrays.stream(“some text some spaces”.split(” “)) .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())) .entrySet() .stream() .sorted(Map.Entry.<String, Long>comparingByValue().reversed()) .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue(), (v1, v2) -> v2, LinkedHashMap::new)); System.out.println(map); // This prints: {some=2, spaces=1, text=1} solved Word count in descending … Read more