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

Cache a whole database using Spring, Hibernate, and Ehcache
2D projectile movement from coordinate pair
JPA - Create or use Foreign Key
Get the lat and lng sometime is NULL with google map api json
How to get term-document matrix from multiple documents with Spark?
Using BlueMix trying to insert JSON data into a Cloudant database without having to Hard Code the format of the file inside Java
Main method not found error Java [closed]
Selenium - xpath has stopped finding the elements
Unable to instantiate activity ComponentInfo - AndroidStudio
Can't get Spring #CacheEvict to work
Menu Style CSS Java
A cat tracking a mouse, minigame
How do I override “java.io.tmpdir” when running ant/mantis junitreport?
InstantiationException when using a generic java class
NestedScrollView not scrolling when dragging from Clickable LinearLayouts
Can spring execute a factory bean on #RequestBody

Categories

HOME
openlayers
debugging
omnet++
nullpointerexception
include
rsyslog
routes
kalman-filter
infragistics
packages
survey
fsm
adobe-analytics
user-input
handsontable
collectd
commonmark
size
static-libraries
dtrace
hex-editors
fallback
circuit
caml
ghc
saxon
propel
nhibernate-envers
crystal-reports-2008
reverse-proxy
object-detection
web-sql
cultureinfo
spark-jobserver
tooltipster
fopen
replaceall
jspm
javascriptcore
gammu
ghost4j
picasso
host
io-redirection
libvpx
angularjs-factory
grid.mvc
texmaker
http-redirect
gpx
s
businessworks
sencha-touch-2.3
angular2-meteor
logfiles
rainbowtable
parentheses
typed-lambda-calculus
sqldf
synchronous
watchconnectivity
adxstudio-portals
measures
pcf
transmitfile
player
whois
yaws
livequery
design-by-contract
energy
msys
cartesian-product
citrus-pay
quicklisp
coveralls
arcanist
remobjects
web-controls
device-orientation
google-style-guide
project-planning
tld
mechanize-ruby
prettify
oam
ccss
xsockets.net
tidy
blending
orchardcms-1.7
tinn-r
javaspaces
hosts-file
ticoredatasync
assembly-loading
custom-backend
netdna-api
doh
zpt
gcj
heartbeat
rfc1123
oncheckedchanged
cxxtest
yslow
meego
virtual-functions
swing-app-framework
grid-system
.net-1.0

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App