[Solved] ArrayList is reinitialising when a method is called

From a quick review of that block : while(a!=0){ … else if(a==2) {d=new User_Interface2(); d.showData();} else if(a==3) {d=new User_Interface2(); d.main();} } You are creating a new instance on each iteration. Create d outside the loop and reuse that instance. d=new User_Interface2(); while(a!=0){ … else if(a==2) { d.showData(); } else if(a==3) { d.main(); } } solved … Read more

[Solved] Visibility of class in Java [closed]

Low visibility = private. High visibility = public. And there are two more visibilities in-between. From higher to lower visibility: public > protected > “default” > private “Default” doesn’t have a keyword associated, it’s the visibility that applies when no visibility is explicitly declared. And here’s the relevant link from the documentation. solved Visibility of … Read more

[Solved] How to concatenate two arrays into 1 single array using java? [duplicate]

Make a for-loop an iterate over Array1 and Array2 Do Integer.parseInt(String.valueOf(Array1[i])+String.valueOf(Array2[i])); Fill the Array3 in the for-loop with the calculated valued. That’s it. int[] Array1 = new int[] {3,3,3}; int[] Array2 = new int[] {3,2,1}; int[] Array3 = new int[Array2.length]; for(int i = 0; i<Array1.length; i++) { Array3[i] = Integer.parseInt(String.valueOf(Array1[i])+String.valueOf(Array2[i])); } Output: Array3[] = {33,32,31} … Read more

[Solved] The static method…should be accessed in a static way [closed]

You are calling your methods correctly (from logical point of view) but apparently you have declared them incorrectly (as static). Make them instance methods by removing the static modifier. That should fix your problem. And learn the the difference between static and instance methods (seems you haven’t quite yet). In particular getName and setName should … Read more

[Solved] Write a function that will sort a string array using Java

First of all a, e and g are variables and not necessarily strings. What you mean is probably “a”, “e” and “g”. Your question is essentially: How do I sort the values in a String[] so that numbers are sorted numerically and prioritized before letters (or words?) which are sorted alphabetically? Your question seems incomplete, … Read more

[Solved] My second if and else if statement produces the wrong answer [closed]

BigDecimal use example vatTotalNoAgeLess5 = BigDecimal.valueOf(dinnerTotal).add(BigDecimal.valueOf(grossTick)).multiply(BigDecimal.valueOf(1.21)).doubleValue(); Example if statement if ((havingDinner.equals(“Y”) || havingDinner.equals(“y”)) && (ageDiscount.equals(“Y”) || ageDiscount.equals(“y”))) { agetick = (grossTick * 0.85); dinnerTotal = dinnerPrice * (standTick + terraceTick); vatTotalForAge = ((dinnerTotal + agetick) * 1.21); System.out.println(vatTotalForAge); } else if ((havingDinner.equals(“Y”) || havingDinner.equals(“y”)) && (ageDiscount.equals(“N”) || ageDiscount.equals(“n”))) { dinnerTotal = dinnerPrice * (standTick + … Read more

[Solved] Exception Thread in java

Your scanner is getting screwed up if you both use nextLine and next/nextInt/nextDouble refer to this for more Information. I changed your main method accordingly, it now works like you wanted it to. public static void main(String[] args) { Scanner input = new Scanner(System.in); Student s1 = new Student(); System.out.print(“Enter your name: “); s1.name = … Read more

[Solved] Android Java error:null pointer exception can’t see why?

You have referenced in Your LoadingMain activity the following layout with setContentView: setContentView(R.layout.loading_main); But this Layout does not have any button1. Instead, You are trying to reference a button from another layout, from activity_main.xml btnStartProgress = (Button) findViewById(R.id.button1); This button1 is inside the activity_main.xml and You cannot reference a button in a layout that is … Read more