I have been trying to remove two errors in this code, line 12 (non-static variable this cannot be referenced from a static context) and line 204(cannot find symbol:(method compareTo(java.lang.Object)

import java.util.*;



   public class InventoryPart3 {      

 public static void main(String[] args) {

      Inventory invent = new Inventory(); <---[U]non-static variable this cannot be referenced froma static context.[/U]      
        Title dvd;
        Scanner input = new Scanner(System.in);

        Title[] titles = new Title[5];//an array of 5 titles


        dvd = new Title("Return to Never Land", 001, 5,16.99);
        invent.add(dvd);


        dvd = new Title("Tarzan", 002, 5, 19.99);
        invent.add(dvd);

        dvd = new Title("Tarzan II",003, 4, 19.99);
        invent.add(dvd);

        dvd = new Title("Beauty and the Beast", 004, 3, 24.99);
        invent.add(dvd);

        dvd = new Title("Hercules", 005, 3, 15.99);
        invent.add(dvd);

        invent.display();
        //end main

        }//end class Inventory3

 class DVD{


         private int dvdItem;
          private String dvdTitle;
          private int dvdStock;
          private double dvdPrice;

          public DVD(int item, String title, int stock, double price){

              dvdItem = item;
              dvdTitle = title;
              dvdStock = stock;
              dvdPrice = price;
          }//end four-argument constructor

          //set Dvd Item
          public void setDvdItem(int item){
              dvdItem = item;
           }//end method set DVD Item

          //return Dvd Item
          public int getDvdItem(){
              return dvdItem;

         }//end method get Dvd Item

          //set Dvd Title
          public void setDvdTitle(String title){

              dvdTitle = title;

              }//end method set Dvd Title

          //return Dvd Title

          public String getDvdTitle(){
              return dvdTitle;

          }//end method get Dvd Title

          //set dvd stock
          public void setDvdStock(int stock){

              dvdStock = stock;

         }//end method set Dvd Stock

          //return dvd Stock

          public int getDvdStock(){
              return dvdStock;

         }//end method get Dvd stock

          //set dvd price
          public void setDvdPrice(double price){

        dvdPrice = price;

        }//end method setDvdPrice

        //return DVD price
          public double getDvdPrice(){
              return dvdPrice;

      }//end method get Dvd Price

       //calculate inventory value

          public double value(){

              return dvdPrice * dvdStock;
              }//end method value

          public String toString(){

              return String.format("item=%3d title=%-20 units=3%3d price=$%6.2f value=$%7.2f",dvdItem, dvdTitle, dvdStock, dvdPrice, value());

          }

      }//end class Dvd

      class Movie extends DVD {

          private String movieTitle;

          public Movie(String title, int Item, String dtitle, int stock, double price){

          super (Item, dtitle, stock, price);

          movieTitle = title;
          }

          public double value(){

              double value = getDvdPrice() * getDvdStock();

              value = 1.05 * value;

              return value;

          }//end method value

          public String toString(){

              String s = String.format("Movie title=%-12s",movieTitle);
              s = s + " " + super.toString();

              return s;

              }

}//end class Movie


      class Inventory{

          private Title[] dvds;

          private int count;
        private Title[] dvd;

          Inventory(){

              dvds = new Title[10];

              count = 0;

         }

          public void add(Title dvd){

              dvds[count] = dvd;

              ++count;

              sort();

          }

          public double entireValue(){

              double value = 0;

              for (int i = 0; i < count; i++){
                  value = dvd[i].value();
              }

              return value;
          }

          public void sort(){
            int postion = 0;

              for(int index = 1; index < count; index++){

                  Title key = dvd[index];

                  int position = index;

               //Shift larger values to the right
               while(position > 0 && key.getDvdTitle().compareTo(dvds[postion-1].getDvdTitle())< 0 ){  [U]<---cannot find symbol:(method compareTo(java.lang.Object)[/U]                  
            dvds[position] = dvds[position-1];

                   position--;

                   }
                 dvds[position] = key;
               }

              }

              public void display(){


                  System.out.println("\nThe inventory contains " + count +"DVDs\n");

                  for(int i = 0; i < count; i++)

                      System.out.printf("%3d %s\n", i, dvds[i]);
                  System.out.printf("\nThe total inventory value is $%.2f\n\n", entireValue());

               }
    }

}//end class Inventory

I clicked on (code)

Looks like maybe problems with the Title class - which isn't in your post.
ps Please post code in code tags with line numbers and correct indentation

Looks like maybe problems with the Title class - which isn't in your post.
ps Please post code in code tags with line numbers and correct indentation

Thank You, I will try looking for this, plus can you tell me how to use the tags, or is there a section that I can read on how to Tag? I started to enter a new thread, and placed Inventory 3 in the Tag section, but when I previewed it, it did not show any numbers, so I decided not to repost the thread. Would the numbers have come up if I had submitted it?

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.