Hello, I'm having problems passing an ArrayList from a method in one class into a method of another class and accessing it. Here's my code.

private static void createData() throws IOException{
	ArrayList<movie> moviesList = new ArrayList<movie>();
	moviesList.add(new movie(1, "Schindler's List", 18, 19.99));
	moviesList.add(new movie(2, "Red Cliff Blu-Ray", 4, 43.50));
	moviesList.add(new movie(3, "Garfield", 34, 16.99));
	moviesList.add(new movie(4, "Dinosaur", 12, 12.87));
	moviesList.add(new movie(5, "The Two Towers", 23, 22.80));
	moviesList.add(new movie(6, "Casino Royale", 8, 19.99));
	moviesList.add(new movie(7, "Warlords", 6, 28.99));
	moviesList.add(new movie(8, "The Inside Man", 15, 29.99));
	System.out.println(moviesList.get(1).printMovies());
	movie.writeData(moviesList, 8, null);
}

and in the other class I have:

public static void writeData(ArrayList<movie> n_moviesList, int Count, File textFile) throws IOException{
	if(textFile == null) { textFile = new File("movieList.dat"); }
		FileWriter fw = new FileWriter(textFile); 
		PrintWriter pw = new PrintWriter(fw); 
	 	String inputLine; 
	for(int i = 0;i < Count;i++){
	    inputLine = n_moviesList.get[i].printMovies();
	    pw.println(inputLine);
	}
	pw.close();   
}

The error I am getting is n_moviesList.get cannot be resolved or is not a field

In one code you do this:

System.out.println(moviesList.get(1).printMovies());

Which is correct.
And at the other, you do this:

inputLine = n_moviesList.get[i].printMovies();

which is wrong.

Did you import the movie (ps should be Movie) class in the second .java file?

Update: parallel post with javaAddict - he's right!

lol I'm as blind as a bat, one of those days I guess. Thanks!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.