Can someone tell me why i am getting this error

helo, I am trying to write 3 seperate classes and use inheritence between them, a small brek down is class Thought is suppose to have a method messege that prints out "I'm a teacher" and slass Advice is suppose to be a subclass of Thought and suppose to have the same method ut to print out "I'm your student" and class Message is suppose to have a main method that instantiates the two other classes and makes them work. I have written the code, this should have been simple, but these are the errors i am getting when compiling Messeges:
Messages.java [14:1] variable thought might not have been initialized
output =thought.Message() + "\n" +advice.Message();
^
Messages.java [14:1] variable advice might not have been initialized
output =thought.Message() + "\n" +advice.Message();
Here is the code"
public class Thought{
protected String message="";
public String Message()
    message="I'm a teacher.";
    return message;
}//end class
public class Advice extends Thought{
private String message="";
public String Message()
message="I'm your student.";
    return message;
}//end class
import javax.swing.JOptionPane;
public class Messages
    public static void main(String args[])
Thought thought;
Advice advice;
String output="";
output =thought.Message() + "\n" +advice.Message();
JOptionPane.showMessageDialog(null,output,"Inheritence",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}//end main
}//end classAny help would be appreciated.

Hi,
I had gone through the code you have posted and I agree with atmguy that the errors that were thrown were due to the fact that you have not initialized the objects from the main method. You have to use the new keyword to inityialize the objects that you are creating.
Secondly you have stated that you have used inheritance and created three classes. But I find that the inheritance has not been practised at all. Try removing the "extends Thought" portion and then also your code would work just fine. It is as good as creating two seprate classes and using them from a third containing the main function. Hope this clears all your querries.
cheers
Aviroop

Similar Messages

  • Please can someone tell me why I am getting this error?

    I want to call a method (setSquare()) when a JLabel is clicked by the user, the following code should work:
    *private void grid11MouseClicked(java.awt.event.MouseEvent evt) {*
    setSquare();
    But I get this error, please can someone tell me what this means? The method is already defined in the class and I have imported javax.swing etc
    Frame.java:181: setSquare(javax.swing.JLabel) in p1.Frame cannot be applied to ()

    drew22299 wrote:
    I want to call a method (setSquare()) when a JLabel is clicked by the user, the following code should work:
    *private void grid11MouseClicked(java.awt.event.MouseEvent evt) {*
    setSquare();
    But I get this error, please can someone tell me what this means? The method is already defined in the class and I have imported javax.swing etc
    Frame.java:181: setSquare(javax.swing.JLabel) in p1.Frame cannot be applied to ()
    As i dont know what that method needs i can't help you there but i do know you cannot leave it blank. Try adding a number/text whatever or null and see what it does. or check the api and take a look what it needs.
    Edited by: deAppel on Oct 31, 2007 10:35 PM

  • Can someone tell me why we are getting this error message when users try to open?

    It was created in LiveCycle and Reader Extensions were given before posting it to the website.  Normally if you open in Firefox or IE, it will work (sometimes).

    We would also really appreciate an answer to this question.  We are having the exact same issue with some new forms we have created.  They were created in Adobe LiveCycle Designer ES4, and then usage rights were extended in Adobe Acrobat XI Pro. 
    When this issue is encountered we send the old version of the form, it was created using the same process a number of years ago, so the only difference is that we were using older versions of both programs.  The same recipients who have an issue with the new form are always able to open the old forms.
    Help!  Does anyone have a solution. Thanks very much!

  • Can anyone tell me why I'm getting this error when trying to make visibility variables

    I have set these up in previous versions of Illustrator. CS and illustrator 10 worked just fine with Variables. Now I can't seem to switch between data sets. I just keep getting this error when I try to switch from one data set to another.

    I'll start with the permissions and see if it changes the behavior.

  • Can anyone tell me why i'm getting this: java.lang.NullPointerException

    Please lend me your expertise.I hava a feeling its got something to
    do with the session.When I run the servlet I get this error:
    java.lang.NullPointerException
         at ConnectionPerClient.doGet(connectionperclient.java:85)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at filters.ExampleFilter.doFilter(ExampleFilter.java:149)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
         at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
         at java.lang.Thread.run(Thread.java:484)
    Here is my code:
    import java.io.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    class ConnectionHolder implements HttpSessionBindingListener
    private Connection con = null;
    public ConnectionHolder(Connection con)
    this.con = con;
    try
    con.setAutoCommit(false);
    catch(SQLException e)
    public Connection getConnection()
    return con;
    public void valueBound(HttpSessionBindingEvent event)
    public void valueUnbound(HttpSessionBindingEvent event)
    try
    if(con!=null)
    con.rollback();
    con.close();
    catch(SQLException e)
    public class ConnectionPerClient extends HttpServlet
    public void init(ServletConfig config)throws ServletException
    super.init(config);
    try
    Class.forName("oracle.jdbc.driver.OracleDriver");
    catch(ClassNotFoundException e)
    public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();
    HttpSession session = req.getSession(true);
    ConnectionHolder holder = (ConnectionHolder) session.getAttribute("servletapp.connection");
    if(holder == null)
    try
    holder = new ConnectionHolder(DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:macha","username","password"));
    session.setAttribute("servletapp.connection",holder);
    catch(SQLException e)
    Connection con = holder.getConnection();
    try
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * FROM david.Emp");
    //Print start of table and column headers
    out.println("<TABLE CELLSPACING=\"0\" CELLPADDING=\"3\" BORDER=\"1\">");
    out.println("<TR><TH>EMPNO</TH><TH>ENAME</TH><TH>JOB</TH><TH>SAL</TH></TR>");
    //Loop through results of query.
    while(rs.next())
    out.println("<TR>");
    out.println(" <TD>" + rs.getString("EMPNO") + "</TD>");
    out.println(" <TD>" + rs.getString("ENAME") + "</TD>");
         out.println(" <TD>" + rs.getString("JOB") + "</TD>");
    out.println(" <TD>" + rs.getString("SAL") + "</TD>");
    out.println("</TR>");
    out.println("</TABLE>");
    catch(SQLException e)
    out.println("SQLException: " + e.getMessage() + "<BR>");
    while((e = e.getNextException()) != null)
    out.println(e.getMessage() + "<BR>");
    finally
    //Clean up resources, close the connection.
    if(con != null)
    try
    con.close();
    catch (Exception ignored) {}

    Take this code:
    ConnectionHolder holder = (ConnectionHolder) session.getAttribute("servletapp.connection");
    if(holder == null)
    try
    holder = new ConnectionHolder(DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:macha","username","password"));
    session.setAttribute("servletapp.connection",holder);
    catch(SQLException e)
    }and change it to:
    ConnectionHolder holder = (ConnectionHolder) session.getAttribute("servletapp.connection");
    if(holder == null)
    try
    holder = new ConnectionHolder(DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:macha","username","password"));
    session.setAttribute("servletapp.connection",holder);
    catch(SQLException e)
        e.printStackTrace(); // THIS IS THE LINE TO ADD IN

  • Can someone tell me why I keep getting a spinning wheel on my screen and it won't go away and I can't do anything while it is there Thank you

    I keep getting a spinning wheel in colors on my screen it will not go away and when it is there, I can't do anything it is as if the computer freezes Has anyone else had this problem or can someone help me out? Thanks very much

    the wheel comes and goes, it looks like the wheel of fortune wheel if you will it has colors all around it and keeps blinking, when it is there, I can't use the computer, it freezes up

  • Can someone tell me why i cant get music videos on my ipod?

    i just downloaded a couple of music videos onto my computer from limewire and put it into my file in i-tunes. i can play the music videos on i-tunes but i can not transfer them to my ipod. i tried to convert them using vidoria and still i can not get them into my video ipod. i have no problems with converting dvd but dont know what i am doing wrong on the music videos? can anyone give me some direction?

    Try projecting one of the images without using Powerpoint.  Just open the original jpeg file in Preview or something.  What's the quality?  If it's good then it's likely something Powerpoint is doing to the image.  For that you'd have to ask on a Microsoft forum or be lucky and somebody here might be more familiar with Pp than I.
    I don't think it should be a matter of Mac vs Dell.  I'm not very familiar with projectors but probably by the time it is coming out of your computer it is just a video signal and people have been using non-Mac displays with Macs for 15+ years.

  • Can someone tell my why I cant get my Iphone to connect to Itunes

    Having trouble getting IPhone to connect to Itunes

    Unless you provide more details, we would just be guessing.
    Let's start with the obvious.....
    Your computer is turned on, correct?
    The iPhone is powered on, correct?
    You plugged the cable into the iPhone and the computer, correct?

  • Can't figure out why I'm getting this error on New-ADUser

    The command is:
    New-ADUser –SamAccountName “TestProvider” -UserPrincipalName "[email protected]” -GivenName “Test” -Surname “Provider” -DisplayName “Test Provider” -Name "Test Provider" -Enabled $true -path “ou=CompanyName,ou=Users,ou=Providers,DN=intranet,DN=CompanyName,DN=com” -AccountPassword (ConvertTo-SecureString "TEST123test" -AsPlainText -force) -PasswordNeverExpires $True
    The error is: 
    New-ADUser : No superior reference has been configured for the directory service. The directory service is therefore un
    able to issue referrals to objects outside this forest
    At line:1 char:11
    + New-ADUser <<<< -SamAccountName "TestProvider" -UserPrincipalName "[email protected]" -GivenName "Test" -
    Surname "Provider" -DisplayName "Test Provider" -Name "Test Provider" -Enabled $true -path "ou=CompanyName,ou=Users,ou=
    Providers,DN=intranet,DN=CompanyName,DN=com" -AccountPassword (ConvertTo-SecureString "TEST123test" -AsPlainText -force
    ) -PasswordNeverExpires $True
    + CategoryInfo : NotSpecified: (CN=Test Provide...panyName,DN=com:String) [New-ADUser], ADException
    + FullyQualifiedErrorId : No superior reference has been configured for the directory service. The directory servi
    ce is therefore unable to issue referrals to objects outside this forest,Microsoft.ActiveDirectory.Management.Comm
    ands.NewADUser
    I think it has something to do with the way I'm specifying the "path" but i'm not sure.
    The user should be created in an OU: CompanyName > Users > Providers
    The domain is intranet.companyname.com

    Hi,
    Instead of ou=CompanyName,ou=Users,ou=Providers,DN=intranet,DN=CompanyName,DN=com, try ou=CompanyName,ou=Users,ou=Providers,DC=intranet,DC=CompanyName,DC=com.
    Don't retire TechNet! -
    (Don't give up yet - 12,700+ strong and growing)

  • Please can someone tell me why I cannot reinstall my upgrade from lightroom 4 (lightroom 3 installed off disc with serial no) my hard drive crashed, and I am trying to get lightroom 3; 4 and 5 back on so that I can link my catalogues and continue work. I

    Please can someone tell me why I cannot reinstall my upgrade from lightroom 4 (lightroom 3 installed off disc with serial no) my hard drive crashed, and I am trying to get lightroom 3; 4 and 5 back on so that I can link my catalogues and continue work. I cannot install lightroom 5 until the upgrades from 4 are on the pc, (lightroom 3 installed off disc but 4 is a copy of the upgrade download I got when I bought it) These serial no's are legit and  are registered under my account with adobe, but it still gives me the Big Red Cross when I put my serial no in! Please can someone help. I am at a loss. Thx Heidi

    Please can someone tell me why I cannot reinstall my upgrade from lightroom 4 (lightroom 3 installed off disc with serial no) my hard drive crashed, and I am trying to get lightroom 3; 4 and 5 back on so that I can link my catalogues and continue work. I cannot install lightroom 5 until the upgrades from 4 are on the pc, (lightroom 3 installed off disc but 4 is a copy of the upgrade download I got when I bought it) These serial no's are legit and  are registered under my account with adobe, but it still gives me the Big Red Cross when I put my serial no in! Please can someone help. I am at a loss. Thx Heidi

  • Plerase can someone tell me why I cannot reinstall my upgrade from lightroom 4 (lightroom 3 installed off disc with serial no) my hard drive crashed, and I am trying to get lightroom 3; 4 and 5 back on so that I can link my catalogues and continue work. I

    Please can someone tell me why I cannot reinstall my upgrade from lightroom 4 (lightroom 3 installed off disc with serial no) my hard drive crashed, and I am trying to get lightroom 3; 4 and 5 back on so that I can link my catalogues and continue work. I cannot install lightroom 5 until the upgrades from 4 are on the pc, (lightroom 3 installed off disc but 4 is a copy of the upgrade download I got when I bought it) These serial no's are legit and  are registered under my account with adobe, but it still gives me the Big Red Cross when I put my serial no in! Please can someone help. I am at a loss. Thx Heidi

    BrightBluephotograph wrote:
    I cannot install lightroom 5 until the upgrades from 4 are on the pc,
    You don't need to have Lightroom 3 and 4 installed on your computer to install Lightroom 5.  Just install Lightroom 5 and input your serial number for 3 in the previous version box and your serial number for 5 in the upgrade box.

  • Most of the time I get The Connection Was Reset. Can someone tell me why this happens?

    When I click on Firefox or when browsing or going from one site to the other I get "The connection was reset" then have to click on Try Again.
    Can someone tell me why this is happening?
    Thank you.
    THE CONNECTION WAS RESET again this morning. I even get this message when I click on the Firefox Icon to get on the net. When for example I download something then it returns me to their site I get The Connection Was Reset. When I uninstall a program and it sends to to their site in order to answer as to why I am uninstalling their program then I get The Connection Was Reset.
    Every time this happens I have to click on Try Again and find this to be annoying.
    This does not happen once or twice a week, it happen ALL THE TIME.
    This morning I went to Safe Mode and followed the instructions on INTERRUPTED OR RESET CONNECTION which tells us what to do but this did not work either.
    Would be great if someone was able to let me know what to do in order to prevent this message appearing all the time.

    Do not know how to delete this reply. I replied instead of editing my question. I have edited the above now.

  • Can someone tell me why the Yahoo mail server (IMAP) keeps requesting my Yahoo email password and says it's incorrect?  Yahoo is my Mac mail server.  This has happened before, but this time I can't get it to 'Cancel'

    Can someone tell me why the Yahoo mail server (IMAP) keeps requesting my Yahoo email password and says it's incorrect?  Yahoo is my Mac mail server. This has happened before, but this time I can't get it to 'Cancel'.

    You will have to contact Yahoo Support.

  • Can someone tell me why can't I delete a picture of a text message conversation? I touch and hold a picture in IOS7.0.3; I touch More, I click the picture(s) and I click the garbage bin. The picture gets deleted, but then it comes back in a seconed!

    Can someone tell me why can't I delete a picture of a text message conversation? I touch and hold a picture in IOS7.0.3; I touch More, I click the picture(s) and I click the garbage bin. The picture gets deleted, but then it comes back in a second!

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]
    * [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")

  • Can someone tell me why, since upgrading to Yosemite, I keep getting a message window saying "Another device on the network  is using your computer's IP address?"

    Can someone tell me why, since upgrading to Yosemite, I keep getting a message window saying "Another device on the network  is using your computer's IP address?"

    That may be what is a fairly common problem of 2 devices mistakenly assigned the same address. Try shutting off all of the devices connected to your router, reboot the router and then the devices connected to it.

Maybe you are looking for