Results 1 to 6 of 6
  1. #1
    Mr.b165 is offline Member
    Join Date
    Jul 2014
    Posts
    3
    Rep Power
    0

    Default Methods from my original class are receiving an error when in a test class

    I am working on a program that simulates a bug moving along a horizontal line, My code works correctly when I test it in it's own class but when I tried testing my constructor and methods in a test class I recieved an error saying, "package stinkBug does not exist" on lines with my methods. However, stinkbug is not a package so I'm not sure why I am receiving these errors.

    Java Code:
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package bug;
    
    /**
     *
     * @author Luke
     */
    public class Bug {
    
        /**
         */
       
        public int position;
        public int turner = 1;
        public static void main(String[] args) {
        
          Bug juneBug = new Bug(0);                         <--- This part of the code works fine, turn determines the bugs direction and move increases the bugs direction
          juneBug.move();
          juneBug.turn();
          juneBug.move();
          juneBug.move();
          System.out.println(juneBug.getposition());     <---
            
        }
        public Bug(int initialPosition){
            position = initialPosition;
            turner = 1;
            
        }
        public void turn(){
            
            turner = turner + 1;
        }
        public void move(){
            if (turner % 2 == 0){
                 position = position - 1;
            }else{
                 position = position + 1;
        }
         
        }
        public int getposition(){
            return position;
    }
    }


    Java Code:
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package bug;
    
    
    /**
     *
     * @author Luke
     */
    public class BugTester {
        Bug stinkBug = new Bug(0);                    <---- This section of my code is the same  as above except I created a new bug object called stinkBug instead of juneBug
        stinkBug.move();                                          
        stinkBug.move();
        stinkBug.turn();
        stinkBug.move();
        System.out.println(juneBug.getposition()); <---- I keep receiving the error I mentioned above on all of the following lines
        
        
    }
    Last edited by Mr.b165; 07-05-2014 at 01:43 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default Re: Methods from my original class are receiving an error when in a test class

    "package stinkBug does not exist"
    Where is that package located?
    Is it on the classpath?

    I don't see the import statement for that package.
    Please copy the full text of the error message and paste it here.

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Mr.b165 is offline Member
    Join Date
    Jul 2014
    Posts
    3
    Rep Power
    0

    Default Re: Methods from my original class are receiving an error when in a test class

    Quote Originally Posted by Norm View Post
    Where is that package located?
    Is it on the classpath?

    I don't see the import statement for that package.
    Please copy the full text of the error message and paste it here.

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    Methods from my original class are receiving an error when in a test class-java-error.png
    I believe the package is on the class path, I'm not sure exctaly what that is but I believe its the window at the top left.
    I tried typing import bug but I just recieved another error after search the internet I don't think the statement is necessary, I just need to call the class because the classes are in the same package.
    The full error is:
    package stinkBug does not exist
    <identifier expected>

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default Re: Methods from my original class are receiving an error when in a test class

    Please copy and paste the code here in code tags. Not as images.

    The full error is:
    package stinkBug does not exist
    <identifier expected>
    That error message doesn't show the source line where the problem is.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Mr.b165 is offline Member
    Join Date
    Jul 2014
    Posts
    3
    Rep Power
    0

    Default Re: Methods from my original class are receiving an error when in a test class

    Quote Originally Posted by Norm View Post
    Please copy and paste the code here in code tags. Not as images.


    That error message doesn't show the source line where the problem is.
    I edited my original post so its in the code format, The error is on lines 15 through 20. The image was to show that the classes are both in the same path. Sorry it's my first time using this forum and I'm very new to java.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,513
    Rep Power
    25

    Default Re: Methods from my original class are receiving an error when in a test class

    It looks like there is a lot of code outside of any method that needs to be inside of a method or constructor.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: 01-21-2014, 04:41 AM
  2. Error: Could not find or load main class Test.class
    By java_aim in forum New To Java
    Replies: 11
    Last Post: 08-13-2013, 05:05 PM
  3. Error: Could not find or load main class Test
    By java_aim in forum New To Java
    Replies: 2
    Last Post: 11-17-2012, 10:25 AM
  4. Receiving error "Could not find the main class"
    By Kalpesh in forum New To Java
    Replies: 2
    Last Post: 02-02-2011, 06:31 PM
  5. Calling a method on original class from created class
    By kpedersen in forum Advanced Java
    Replies: 4
    Last Post: 08-20-2008, 12:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •