I Don't understand my mistakes on exercice "3. ArrayList"


#1

Hi guys,

Can you explain me my mistakes please?

import java.util.ArrayList;

public class Temperatures {

public static void main(String[] args) {

ArrayList<Integer> weeklyTemperatures = new weeklyTemperatures;
  ArrayList<Integer>();

}

}

Java says to me:
"Temperatures.java:7: error: '(' or '[' expected
ArrayList weeklyTemperatures = new weeklyTemperatures;
^
Temperatures.java:8: error: not a statement
ArrayList();
^
Temperatures.java:8: error: ';' expected
ArrayList();
^
3 errors"

Thanks a lot :wink:


#2

So the aim is to create an Arraylist object which which will store integer objects. in Java the new keyword is used to achieve that

ArrayList<Integer> weeklyTemperatures = new ArrayList<Integer>();

calling the new ArrayList<Integer>() on the right is what create the ArrayList object


#4

Code is as follows in my exercise:

import java.util.ArrayList;

public class Temperatures {
	
	public static void main(String[] args) {

   ArrayList  <Integer>  weeklyTeperatures = new ArrayList <Integer> ();

	}
}

All I'm getting is "Did you create the object" on the bottom of the page, which from what I can tell, I have done. I appreciate the 'automated' nature of the codeacademy, but some of the messages that it kicks back to the uninitiated come across as 'try again', without any sort of guidance as to what the actual problem is.
Edit: And for some reason it's not actually posting my code correctly. Sorry for the 'OPEN/CLOSECARROT' thing but I can't figure out how to make it display the "<" and ">" with "integer" inside of them.


#5

:green_heart: How to post code in this forum.


#6

Thanks much @albionsrefuge. I've been looking for this for some days now.


#7

If that is you're code as follows posted above @byronginn,
I noticed you're entire code is inbetween Comment lines.
/* */


#8

The comment lines were me trying to get the forum to accept the format. I've edited the post properly now.


#9

Hmm, the code seems to be correct I tried it myself.
Try restarting it by clicking the Get Help button in bottom
right corner and restart exercise.


#10

Hey I had the same issue as well. I managed to remedy this issue by:

  1. clicking get code
  2. restarting the excercise
  3. then typing in the same exact code I had before.

It seems to be some kind of clutch because the code academy code provided was identical to mine yet theirs worked and mine did not for some reason.

Hope this helps!


#11

I am having same issue and not able to go further.

import java.util.ArrayList;

public class Temperatures {

public static void main(String[] args) {

ArrayList weeklyTemperatures = new ArrayList ();
}
}

error:::

Temperatures.java:7: error: cannot find symbol
ArrayList weeklyTemperatures = new ArrayList ();
^
symbol: class Interger
location: class Temperatures
1 error