-4

OK so, im very new to java and the solution is probably simple so please bear with me, but basically i'm trying to make a film database using an array of a movie class. i have 3 .java files: the tester, the database, and the movie class. my problem is i'm really not sure how to make my tester file recognize the movies array from the database file, and every solution ive found has just given me more errors.

tester:

public class DatabaseTester extends MovieDatabase{

    public static void main(String[] args) {

        System.out.println(MovieDatabase.movies[1].getTitle());


    }
}

the database:

public class MovieDatabase {
    public static Movie movies[] = new Movie[2];
    public static void movieDb(String[]args){
    movies[1].setTitle("Test Title");
    }
}

^the movie class has a set title method. i'm not too sure about the database's code in particular but it was the only way i could find that didn't give me errors. i'll post the full movie class if necessary but it's quite long so... only if needed

the error i get if i try to getTitle(); from the MovieDatabase:

Exception in thread "main" java.lang.NullPointerException at DatabaseTester.main(DatabaseTester.java:35)

i'm aware this error is from the program thinking the array is not initialized, so it just must not be recognizing my database file... if i try to getTitle from the MovieDatabase, it simply doesn't recognize it, and will either give me an error or nothing. i cannot find a way to get around this aside from putting the Movie initialization in the main (which i have confirmed works, but it's not what i want to do).

froggy
  • 5
  • 1
  • 1
    Possible duplicate of [What does a "Cannot find symbol" compilation error mean?](http://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean) – azurefrog Jan 26 '17 at 22:37
  • Please add more code to clarify issue – John Down Jan 26 '17 at 22:37
  • Because your code cant find the movies variable in the `DatabaseTester` class. The variable is defined inside another class and this is not correct the way you are accessing the variable. You have to call `Database.movies[0]` instead as the variable is static – Md Johirul Islam Jan 26 '17 at 22:39
  • 1
    It looks like you have a variable and a method both named `movies`. That is, at the least, extremely confusing. – D M Jan 26 '17 at 22:39
  • i tried `Database.movies[0]` and it still says "cannot find symbol". also, my method is named Movie, whereas my array is just named movies. i suppose i could rename it to movieDatabase or movieArray if it is clearer.... – froggy Jan 26 '17 at 23:15
  • alright, instead of giving me cannot find symbol now, it simply refuses to read data from the initialized public arrays in the `MovieDatabase` file. any ideas?? – froggy Jan 27 '17 at 08:22

1 Answers1

1

You can try this the following changed code In the class DatabaseTester

public class DatabaseTester {
      public static void main(String[] args) {
               System.out.println(Database.movies[0].getTitle());
          }
    }
Md Johirul Islam
  • 5,042
  • 4
  • 23
  • 56
  • I am considering your static array `movies` is defined in the class `Database` – Md Johirul Islam Jan 26 '17 at 22:43
  • i tried this by putting the name of my database class before the array as you demonstrate but unfortunately no luck. maybe i need to import it somehow, or something... – froggy Jan 26 '17 at 23:26