0

so i'm working on my CS project in which we need to sort a list of DVD's by director. it'll compile, however when i run it i'm getting a null(in java.util.Arrays) i've called java.text.numberformat and java.util.* is that i forgot to add anything in my imports? thanks friends.

 public void addDVD(String title, String director, int year, double cost, boolean bluray)
{
    DVD newDvd = new DVD(title, director, year, cost, bluray);
    int index = Arrays.binarySearch(collection, newDvd);
    if(index >= 0) {
        System.out.println("DVD with title " + newDvd.getTitle() + " already exists.");
    }
    else {
        int index1 = -index - 1;
        collection = insertDVD(collection, newDvd, index1);
        System.out.println("DVD with title " + newDvd.getTitle() + " added.");
    }
    totalCost += cost;
}
Kris
  • 1
  • 2
  • 1
    can' tell from the code you've posted. Try posting a stack trace if you have one. – duffymo Oct 23 '16 at 23:55
  • My immediate presumption from the code snippet you've posted and from your description of the error is that `collection` is `null`. Also, from a functional standpoint, I have my doubts that this particular search would work anyway since `Arrays.binarySearch` may be looking [for the actual, concrete instance](http://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#binarySearch-java.lang.Object:A-java.lang.Object-) rather than its properties, since `Arrays` wouldn't know to inspect them. – Makoto Oct 23 '16 at 23:58
  • @Reborn: We don't 100% know for certain what the initialization state of `collection` is, but from the error they're encountering, it's a *very* strong hunch. More information from the OP is definitely necessary here. – Makoto Oct 24 '16 at 00:01
  • @Makoto has good point :it may return null since you didn't initialized Collection – Malakai Oct 24 '16 at 00:02
  • @makoto sorry, i should have stated above i initilized collectionabove that method with unless it didn't carry through? public DVDCollection() { collection = new DVD[100]; totalCost = 0.0; }' – Kris Oct 24 '16 at 00:07
  • Add *all* relevant code and information to your question. Include the stack trace of it too. – Makoto Oct 24 '16 at 00:29

0 Answers0