Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Program errors because it cannot find something it shouldnt be looking for

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Program errors because it cannot find something it shouldnt be looking for

    Hi there I've got this java program:

    /*
     * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     *   - Redistributions of source code must retain the above copyright
     *     notice, this list of conditions and the following disclaimer.
     *
     *   - Redistributions in binary form must reproduce the above copyright
     *     notice, this list of conditions and the following disclaimer in the
     *     documentation and/or other materials provided with the distribution.
     *
     *   - Neither the name of Oracle or the names of its
     *     contributors may be used to endorse or promote products derived
     *     from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
     * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */ 
     
    class InstanceofDemo {
        public static void main(String[] args) {
     
            Parent obj1 = new Parent();
            Parent obj2 = new Child();
     
            System.out.println("obj1 instanceof Parent: "
                + (obj1 instanceof Parent));
            System.out.println("obj1 instanceof Child: "
                + (obj1 instanceof Child));
            System.out.println("obj1 instanceof MyInterface: "
                + (obj1 instanceof MyInterface));
            System.out.println("obj2 instanceof Parent: "
                + (obj2 instanceof Parent));
            System.out.println("obj2 instanceof Child: "
                + (obj2 instanceof Child));
            System.out.println("obj2 instanceof MyInterface: "
                + (obj2 instanceof MyInterface));
        }
    }
     
    class Parent {}
    class Child extends Parent implements MyInterface {}
    interface MyInterface {}

    It errors with: Error: Could not find or load main class ArithmeticDemo

    This was part of a previous example I'd pasted in, but its not in the new code, so it shouldnt be looking for it?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,607
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: Program errors because it cannot find something it shouldnt be looking for

    How are you compiling and running this? What file is this code located in?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program errors because it cannot find something it shouldnt be looking for

    its compiled by eclipse and the file its in is called "Testcode.java".

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,607
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: Program errors because it cannot find something it shouldnt be looking for

    The class containing main has to be in a file with the same name as the class. You either need to rename InstanceofDemo to Testcode, or rename your Testcode.java file to InstanceofDemo.java.

    However, the error you listed mentions yet another class, so I'd take a closer look at what you're running and compiling if I were you.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Java Program Help! Cant find errors
    By frenchsasha in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 6th, 2013, 11:30 AM
  2. Cannot Find Variable/Symbol Errors... why?
    By bgroenks96 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 9th, 2011, 05:12 AM
  3. [SOLVED] Could someone help me find my errors on this program?? (homework)
    By r19ecua in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 20th, 2011, 11:25 PM
  4. Replies: 3
    Last Post: February 23rd, 2011, 01:27 AM
  5. Help with Cannot Find Symbol Variable errors
    By skboone in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 20th, 2010, 11:52 AM