[Solved] how to add string array elements to arraylist in java

Your budgetEntityList is empty when you do budgetEntity= budgetEntityList.get(k); Doing a new ArrayList<>(capacity) does not fill your ArrayList with BudgetList objects, it only sets the initial capacity of your ArrayList. So, what you need to do is: for(int k=0; k < budgetEntityList.size() ; k++) { budgetEntity = new BudgetEntity(); budgetEntityList.add(budgetEntity); } And then, set the … Read more

[Solved] Error in JAVA code while running it [duplicate]

Your issue is Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 10 because you use array and fixed the size by 10 and you try to add more than 10 elements int this array, please read this arrayindexoutofboundsexception for more details. you have to use array list instead of array ArrayList<Integer> arr = new ArrayList<Integer>(); arr.add(num); // use … Read more

[Solved] TreeMap implementation in java returns only last element [closed]

You are using static in your parameters. This means that everytime you run they get overriden which perfectly explains why you are always getting the last element. You need to change to this: private String jobDescription; private String datasetName; private String jobName; private String responsiblePerson; solved TreeMap implementation in java returns only last element [closed]

[Solved] Output the array so that 10 elements per line are printed

You have not called print method from main method. One more mistake is in your code that, you mentioned about 3 times of index variable and in your code you are taking cube of index variable. public class progprblm5{ public static void main(String []args){ double alpha[] = new double[50]; for(int i =0;i<25;i++){ alpha[i]= i*i; } … Read more

[Solved] Final local variable error

There are two problems. One, you cannot modify final variables. Two, you have to use final variables to have scope within the listeners. This code needs serious refactoring. However, here is a quick solution that requires minimal intervention. Remove all of the boolean tleft; boolean tmid; … variables Add this enum outside of the main() … Read more

[Solved] Update TextView from another Activity

I don’t think there is a good way to do this, as your first activity could get collected by the system, and you generally don’t want to do work after onPause has been called. I would move that logic that updates the views into a service that runs in the background. Since it sounds like … Read more

[Solved] Need help understanding the output of this code. [closed]

Alright let’s see. First you call Circle9() that starts the constructor: /** No-arg constructor */ public Circle9() { this(1.0); System.out.print(“C”); } As you can see the constructor first calls this(1.0) This means that another constructor is opened and afterwards we print “C” Alright the next Constructor is: public Circle9(double radius) { this(radius, “white”, false); System.out.print(“D”); … Read more

[Solved] How can i prevent my Currency converter app from crashing when button is pressed?

if (dollarfield.getText().toString().equals(“”)) { Toast.makeText(getApplicationContext(), “no value has been entered”, Toast.LENGTH_LONG).show(); } else { Double dollarAmount = Double.parseDouble(dollarfield.getText().toString()); Double poundAmount = dollarAmount * 0.7; Toast.makeText(getApplicationContext(), poundAmount.toString() + “Pounds”, Toast.LENGTH_LONG).show(); } 4 solved How can i prevent my Currency converter app from crashing when button is pressed?