java


java: using an array of objects across files


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).
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());
}
}

Related Links

When does getPrivateKey get called in X509KeyManager?
I ran out of ideas for this nested for loop
JDBC physical vs logical
Storm - Class Cast Exception while using the parameter in next bolt
How to get list of file names inside a specific folder in stash repository using stash rest API in Java
Spring boot - Externalize config properties
Access Parent Field with Child Object Java
overwriting objects in arraylist when adding temp object
Java Spring MVC 404 not found
Two tables in one ( java )
Pom.xml that run only in Windows
Connect Java to Access DB on network drive
What is the best way to navigate a complex tree of dissimilar objects?
Input to assign value to double variable
Eclipse doesn't generate new class files when running
Is this proper encapsulation for java? I'm confused

Categories

HOME
vim
magnific-popup
image-processing
iot
objectgears
mean-stack
spagobi
bookshelf.js
adb
razor
malloc
sql-server-2016
ravendb
bs4
tomcat6
numeral.js
collectd
windows-azure-storage
static-libraries
quickfix
ups
designer
iolanguage
foselasticabundle
fatal-error
http-status-code-504
google-cloud-speech
google-pagespeed
emulator
swingx
cloudhub
kvc
telerik-reporting
autosys
centos6.5
poltergeist
brunch
greendao
neo4j-spatial
subdomains
preg-match-all
uisplitview
http-get
noraui
calibre
typed.js
phpfreechat
asset-pipeline
accelerate-framework
mozilla
http-referer
atl
html5-fullscreen
libraries
c11
twitch
webix-treetable
squib
ruby-on-rails-3.1
keydown
vao
eclipse-gef
wptoolkit
babel-core
parentheses
promela
celery-task
lowpass-filter
knpmenubundle
jspdf-autotable
hittest
visual-c++-2008
color-picker
disque
react-native-listview
lua-5.1
prettytensor
goose
asp.net5
independentsoft
freelancer.com-api
historian
ford-fulkerson
intel-fortran
cannon.js
jmeter-maven-plugin
tmuxinator
libressl
deis
sailfish-os
web-controls
unity5.2.3
key-management
android-imagebutton
rdtsc
responsive-slides
bundles
meteor-velocity
openlaszlo
imdbpy
geos
coverflow
odata4j
excel-2003
orchardcms-1.7
factory-method
rdoc
dbproviderfactories
reddot
spyware
deobfuscation
infobox
xdomainrequest
ecl
blitz++
gallio
suppress
kdbg
text-coloring
genealogy

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App