How to handle the exception in a code


Discuss the below:

Task:

You coded the following in the Test.java class:

ArrayList a = new ArrayList ( );

a. add ("Cloudy");

a. add ("Snowy");

a. add("Cloudy");

System.out.println ( "Weather is " + a. get (3 ) ); // line 14

The code compiles properly, but when you run, you get the following output:

Exception in thread "main" java.land.IndexoutBoundsException:

Index: 3, Size 3

at java.until.ArrayList.RainCheck (ArrayList.java:599

at java.until.ArrayList.get (ArrayList.java:377)

at Test.main (Test.java:14)

Q: Explain what the problem is and how to fix it.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: How to handle the exception in a code
Reference No:- TGS01934165

Now Priced at $20 (50% Discount)

Recommended (93%)

Rated (4.5/5)