Results 1 to 13 of 13
  1. #1
    lewisbc is offline Member
    Join Date
    Oct 2013
    Location
    England
    Posts
    6
    Rep Power
    0

    Default java error: cannot find symbol - variable Samsung, how can i resolve this??

    Hi I have managed to compile my code but when I go to create a new object from outside the compiler, this happens, when I select the option new Mobile (String mobilephonetype, int mobilescreensize,
    int mobilememorycardcapacity,int mobilecameraresolution,String mobileGPS, String newserviceprovider)

    and I type in following information

    Name of instance: mobile
    new Mobile ( Samsung, String mobilephonetype
    1024, int mobile screensize
    2, int mobilememorycard capacity
    8, int mobilecameraresolution
    GPS, String mobileGPS
    Verizon ) String newserviceprovider

    I get the following Error back in the compiler (but can still compile again with no syntax errors) ERROR:
    Java.lang.StackOverflowError: null, what does this mean ??



    my code (compiles fine no syntax errors):

    Java Code:
     <  /**
         * to write a simple java class Mobile that models a mobile phone.
         * 
         * @author (jamal) 
         * @version (20/10/13)
         */
        public class Mobile
        
        {
            // type of phone
            private String phonetype;
            // size of screen in inches
            private int screensize;
            // menory card capacity
            private int  memorycardcapacity;
            // name of present service provider
            private String serviceprovider;
            // type of contract with service provider
            private int typeofcontract;
            // camera resolution in megapixels
            private int cameraresolution;
            // the percentage of charge left on the phone
            private int checkcharge;
            // wether the phone has GPS or not
            private String GPS;
            // instance variables - replace the example below with your own
            private int x;
        
            // The constructor method
        
            public Mobile(String mobilephonetype, int mobilescreensize,
                    int mobilememorycardcapacity,int mobilecameraresolution,String mobileGPS, String newserviceprovider) {
                this.phonetype =  mobilephonetype;
                this.screensize = mobilescreensize;
                this.memorycardcapacity = mobilememorycardcapacity;
                this.cameraresolution = mobilecameraresolution;
                this.GPS = mobileGPS;
                
                // you do not use this ones during instantiation,you can remove them if you do not need or assign them some  default values 
                //this.serviceprovider = newserviceprovider;
                //this.typeofcontract = 12;
                //this.checkcharge = checkcharge;
        
           Mobile samsungPhone = new Mobile(
            "Samsung" // String mobilephonetype
        ,   1024    // int mobilescreensize 
        ,   2      // int mobilememorycardcapacity 
        ,   8       // int mobilecameraresolution 
        ,   "GPS"    //String mobileGPS
        ,   "verizon" // String newserviceprovider 
        );
        
        
                //typeofcontract = 12;
                //checkcharge = checkcharge;
                
            }
        
            // A method to display the state of the object to the screen
            public void displayMobileDetails() {
                System.out.println("phonetype: " + phonetype);
                System.out.println("screensize: " + screensize);
                System.out.println("memorycardcapacity: " + memorycardcapacity);
                System.out.println("cameraresolution: " + cameraresolution);
                System.out.println("GPS: " + GPS);
                 System.out.println("serviceprovider: " + serviceprovider);
                System.out.println("typeofcontract: " + typeofcontract);
        }
        
              /**
         * The mymobile class implements an application that
         * simply displays "new Mobile!" to the standard output.
         */
        public class mymobile {
            public void main(String[] args) {
                System.out.println("new Mobile!"); //Display the string.
            }
        }
            public static void buildPhones(){
            Mobile Samsung = new Mobile("Samsung", 3, 4, 8, "verizon",
                        "GPS");
            Mobile Blackberry = new Mobile("Blackberry", 3, 4,
                        8, "verizon", "GPS");   
        }
            public static void main(String[] args) {
                buildPhones();
        }  
               
        }  >
    any answers or replies and help would be greatly appreciated as I really lost!
    Last edited by lewisbc; 10-20-2013 at 11:57 PM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: java error: cannot find symbol - variable Samsung, how can i resolve this??

    Please edit your post and wrap your code with code tags:
    [code]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    StackOverflowError is usually caused by the code making recursive calls. That would be shown in the stack trace.
    Can you post more lines of the stack trace?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    lewisbc is offline Member
    Join Date
    Oct 2013
    Location
    England
    Posts
    6
    Rep Power
    0

    Default Re: java error: cannot find symbol - variable Samsung, how can i resolve this??

    sorry, whats the stack trace??

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: java error: cannot find symbol - variable Samsung, how can i resolve this??

    How do you execute the program?
    Where did you get the error message?

    A stack trace can be shown when the program has an error. It shows a history of the method calls made by the program.

    Here's a sample stack trace:
    Java Code:
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -5
    	at java.lang.String.substring(Unknown Source)
    	at TestCode15.main(TestCode15.java:154)
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    lewisbc is offline Member
    Join Date
    Oct 2013
    Location
    England
    Posts
    6
    Rep Power
    0

    Default Re: java error: cannot find symbol - variable Samsung, how can i resolve this??

    Quote Originally Posted by Norm View Post
    How do you execute the program?
    Where did you get the error message?

    A stack trace can be shown when the program has an error. It shows a history of the method calls made by the program.

    Here's a sample stack trace:
    Java Code:
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -5
    	at java.lang.String.substring(Unknown Source)
    	at TestCode15.main(TestCode15.java:154)
    Hi I am using Bluej

    below is an example of images, this shows how I would execute the program

    firstly bluej opens object: [url]http://i.stack.imgur.com/Zegsl.png and then you double click on object test2 (mobile in my case) and then you type in code, so therefore you have two windows


    code: http://i.stack.imgur.com/Ef0ee.png, object: http://i.stack.imgur.com/Zegsl.png, i select new mobile: http://www.horstmann.com/ccj2/help/bluej-5.png, and it comes up with a box new like this called new mobile: http://nestor.coventry.ac.uk/~lisa/b...ct-inspect.gif

    however my fields for the above are:

    Name of instance: mobile
    new Mobile ( Samsung, String mobilephonetype
    1024, int mobile screensize
    2, int mobilememorycard capacity
    8, int mobilecameraresolution
    GPS, String mobileGPS
    Verizon ) String newserviceprovider

    however I get the following message Error back in the compiler (but can still compile again with no syntax errors) ERROR:
    Java.lang.StackOverflowError: null.
    Last edited by lewisbc; 10-22-2013 at 04:44 PM.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,005
    Blog Entries
    7
    Rep Power
    20

    Default Re: java error: cannot find symbol - variable Samsung, how can i resolve this??

    Quote Originally Posted by lewisbc View Post
    Java Code:
        
    public class Mobile {
    ...
           Mobile samsungPhone = new Mobile(
            "Samsung" // String mobilephonetype
        ,   1024    // int mobilescreensize 
        ,   2      // int mobilememorycardcapacity 
        ,   8       // int mobilecameraresolution 
        ,   "GPS"    //String mobileGPS
        ,   "verizon" // String newserviceprovider 
        );
    }
    I copied the essential parts of your code; so a Mobile object has a Mobile object (which has a Mobile object wich has a Mobile object etc. ad nauseam).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: java error: cannot find symbol - variable Samsung, how can i resolve this??

    Java.lang.StackOverflowError: null.
    Is that all the text of the error message?
    That is an unusual text for the message. Normally there are more lines.

    Please copy and paste the full text of any error messages here on the forum. Not images.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    lewisbc is offline Member
    Join Date
    Oct 2013
    Location
    England
    Posts
    6
    Rep Power
    0

    Default Re: java error: cannot find symbol - variable Samsung, how can i resolve this??

    @ josAH

    when you open bluej and and create a new class it opens object: [url]http://i.stack.imgur.com/Zegsl.png and then you double click on object test2 (mobile in my case) and then you type in required code, i compile, go back to object mobile, right click, i select new mobile: http://www.horstmann.com/ccj2/help/bluej-5.png, and it comes up with a box new like this called new mobile: http://nestor.coventry.ac.uk/~lisa/b...ct-inspect.gif

    however my fields for the above are:

    Name of instance: mobile
    new Mobile ( Samsung, String mobilephonetype
    1024, int mobile screensize
    2, int mobilememorycard capacity
    8, int mobilecameraresolution
    GPS, String mobileGPS
    Verizon ) String newserviceprovider
    Last edited by lewisbc; 10-22-2013 at 05:07 PM.

  9. #9
    lewisbc is offline Member
    Join Date
    Oct 2013
    Location
    England
    Posts
    6
    Rep Power
    0

    Default Re: java error: cannot find symbol - variable Samsung, how can i resolve this??

    @ Norm

    yes that is all the text, my code (compiles fine no syntax errors), error does not come up on a specific line, just displays the error message: Java.lang.StackOverflowError: null at the bottom of the page, also that is the full error message, I did not paste an image of the error, these images are me explainig how everything has been executed in bluej.
    Last edited by lewisbc; 10-22-2013 at 05:12 PM.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: java error: cannot find symbol - variable Samsung, how can i resolve this??

    Your IDE is hiding the full text of the error message. Try running the program using the java program in a command prompt so that you get a FULL error message which has lots of good info in it.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,083
    Rep Power
    4

    Default Re: java error: cannot find symbol - variable Samsung, how can i resolve this??

    I don't get the continuation of this thread. Jos nailed it didn't he? You get a stackoverflow because instantiating one Mobile instance will create a Mobile object, which will create a Mobile object, which will create a Mobile object, which will create a mobile object, etc. etc. etc.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: java error: cannot find symbol - variable Samsung, how can i resolve this??

    It's MobilePhones all the way down...
    Please do not ask for code as refusal often offends.

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,005
    Blog Entries
    7
    Rep Power
    20

    Default Re: java error: cannot find symbol - variable Samsung, how can i resolve this??

    Quote Originally Posted by Tolls View Post
    It's MobilePhones all the way down...
    I thought those were turtles; but then again, I maybe old ...

    kind regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. How to resolve : Cannot find symbol....?
    By Kareng in forum New To Java
    Replies: 5
    Last Post: 10-08-2012, 06:20 PM
  2. Cannot resolve symbol error
    By name in forum New To Java
    Replies: 4
    Last Post: 12-07-2011, 05:35 PM
  3. Java cannot find symbol- variable img
    By crutchfieldj in forum New To Java
    Replies: 3
    Last Post: 04-13-2010, 10:47 PM
  4. Cannot Resolve Symbol error...
    By seral1969 in forum New To Java
    Replies: 4
    Last Post: 02-18-2008, 12:17 AM
  5. Error: cannot resolve symbol, help me
    By mathias in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 08-06-2007, 02:46 PM

Posting Permissions

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