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 2 of 2

Thread: Instantiation troubles

  1. #1
    Member
    Join Date
    Jul 2011
    Posts
    31
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Instantiation troubles

    I have this variable of type PreciseTime that I need to instantiate to get it into a class called PhoneCall. here's the PhoneCall object signature [PhoneCall(PreciseTime, Precise Time).

    With that said I need to create a precise time object first before instantiating my PhoneCall.

    My user input variable is startIn. I have a method in PreciseTime called PreciseTime fromString(String).

    What am I missing to create my PreciseTime object

    PreciseTime callStart = new PreciseTime(startIn.fromString());

    Here is the compile error I get.
    CallCost.java:48: cannot find symbol
    symbol : method fromString()
    location: class java.lang.String
    PreciseTime callStart = new PreciseTime(startIn.fromString());
    ^
    CallCost.java:48: internal error; cannot instantiate PreciseTime.<init> at PreciseTime to ()
    PreciseTime callStart = new PreciseTime(startIn.fromString());

    Question 2:
    I need to write my PhoneCall object called phoneCall to a custom made string method. The call to the string is inside class PhoneCall. The toString() should call another toString() method inside another class. I want to make the one call and have it cascade to the other classes.

    main -- printOut.write(phoneCall.toString());
    PhoneCall class -- String startTimeOutput = startTime.toString(); startTime is a PreciseTime object and an instance variable in this class
    PreciseTime class -- return twentyFourHrTime; String toString(PreciseTime o) is the method and as you can see, accepts a PreciseTime object.

    What is wrong with the call from main? Below are the error messages.

    CallCost.java:65: write(java.lang.String) has private access in java.io.PrintStream
    printOut.write(phoneCall.toString());

    THANK YOU!
    Last edited by hello_world; July 16th, 2011 at 08:11 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Instantiation troubles

    CallCost.java:48: cannot find symbol
    symbol : method fromString()
    location: class java.lang.String
    PreciseTime callStart = new PreciseTime(startIn.fromString());
    What class is startIn? Does it have a method: fromString()

    CallCost.java:65: write(java.lang.String) has private access in java.io.PrintStream
    printOut.write(phoneCall.toString());
    What class is printOut? The error message says the write(String) method is private.

    You need to post the code that defines all the variables shown in the error messages.

Similar Threads

  1. [SOLVED] What kind of object instantiation is this?
    By Lord Voldemort in forum Object Oriented Programming
    Replies: 3
    Last Post: July 7th, 2011, 07:00 AM
  2. ActionServlet Instantiation
    By tcstcs in forum Web Frameworks
    Replies: 0
    Last Post: April 5th, 2011, 06:12 AM
  3. Instantiation from within Methods
    By John Davies in forum Object Oriented Programming
    Replies: 2
    Last Post: March 10th, 2011, 04:39 PM
  4. Generics and Dynamic Instantiation Problem
    By marcosmarcos in forum Collections and Generics
    Replies: 2
    Last Post: March 4th, 2011, 02:32 PM
  5. JSP Troubles
    By sdkeslar in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 12th, 2010, 02:26 PM