Program Error: Int cannot be derefereced

I am writing a program which displays a GUI for a chocolate chip cookies recipe. The user can key in the number of cookies they want, and the program will calculate and display the appropriate amount of ingredients required.
It is a program I have done myself in order to improve my skills.
There is an error in my code which I can't seem to get rid of. It says that "int cannot be derefereced" and it occurs on this line: String text = noOfCookies.getText();
I hope someone will be able to tell me what has gone wrong. Thanks for any help.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CookieGUI
  private int WIDTH = 450;
  private int HEIGHT = 600;
  private JFrame frame;
  private JPanel panel;
  private JLabel inputLabel, outputLabel, outputLabel2, outputLabel3,
  outputLabel4, outputLabel5, outputLabel6, outputLabel7, outputLabel8,
  outputLabel9, outputLabel10, resultLabel, resultLabel2, resultLabel3,
  resultLabel4, resultLabel5;
  private JTextField noOfCookies;
   //sets up the GUI
  public CookieGUI()
    frame = new JFrame("Choc Chip Cookie Recipe Creator.Version 1");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    inputLabel = new JLabel ("Enter the number of cookies required: ");
    outputLabel = new JLabel ("Ingredients required: ");
    outputLabel2 = new JLabel ("Sugar: ");
    resultLabel = new JLabel ("---");
    outputLabel3 = new JLabel ("Butter: ");
    resultLabel2 = new JLabel ("---");
    outputLabel4 = new JLabel ("Self Raising Flour: ");
    resultLabel3 = new JLabel ("---");
    outputLabel5 = new JLabel ("Egg: ");
    resultLabel4 = new JLabel ("---");
    outputLabel6 = new JLabel ("Chocolate Chips: ");
    resultLabel5 = new JLabel ("---");
// Output labels for the steps go here:
    outputLabel7 = new JLabel ("Step 1 : Mix sugar, butter and "
    + "self raising flour thoroughly.");
    outputLabel8 = new JLabel ("Step 2 : Stir in egg, a few "
    + "drops of vanilla essence and chocolate chips.");
    outputLabel9 = new JLabel ("Step 3 : Roll out mixture and "
    + "cut out cookies.");
    outputLabel10 = new JLabel ("Step 4 : Bake in hot oven "
    + "(Gas Mark 6) for 10-12 minutes.");
    panel = new JPanel();
    panel.setPreferredSize (new Dimension(WIDTH, HEIGHT));
    panel.setBackground (Color.cyan);
    panel.add (inputLabel);
    panel.add (noOfCookies);
    panel.add (outputLabel);
    panel.add (outputLabel2);
    panel.add (outputLabel3);
    panel.add (outputLabel4);
    panel.add (outputLabel5);
    panel.add (outputLabel6);
    panel.add (outputLabel7);
    panel.add (outputLabel8);
    panel.add (outputLabel9);
    panel.add (outputLabel10);
    panel.add (resultLabel);
    panel.add (resultLabel2);
    panel.add (resultLabel3);
    panel.add (resultLabel4);
    panel.add (resultLabel5);
    frame.getContentPane().add (panel);
    public void display()
      frame.pack();
      frame.show();
//action listener
private class CookieListener implements ActionListener
  public void actionPerformed (ActionEvent event)
    double sugar, butter, selfRaisingFlour, egg, vanillaEssence,
    chocolateChips;
    int noOfCookies;
    String text = noOfCookies.getText();
    noOfCookies = Integer.parseInt (text);
    sugar =(0.3334 * noOfCookies);
    noOfCookies = Integer.parseInt (text);
    butter = (0.3334 * noOfCookies);
    noOfCookies = Integer.parseInt (text);
    selfRaisingFlour = (0.6667 * noOfCookies);
    noOfCookies = Integer.parseInt (text);
    egg = (0.08334 * noOfCookies);
    noOfCookies = Integer.parseInt (text);
    chocolateChips = (0.3334 * noOfCookies);
//set all the result labels
resultLabel.setText (Double.toString (sugar));
resultLabel2.setText (Double.toString (butter));
resultLabel3.setText (Double.toString (selfRaisingFlour));
resultLabel4.setText (Double.toString (egg));
resultLabel5.setText (Double.toString (chocolateChips));
public class Cookie
//creates and displays the cookie recipe GUI
   public static void main (String[] args)
     CookieGUI chocchip = new CookieGUI();
     chocchip.display();
}

You dont have to instantiate it, just declaringit
is
enough..
I do believe that is false. It is assigned null if
you do not instantiate it. Meaning when youreference
it you will get a null pointer exception.Yes, that's true, but you'll still have these
shadowing problens in your code... The OP declared
(not instantiated) JTextField noOfCookies , then
declared int noOfCookies in a method. Referring to
'noOfCookies' within this method will refer to the
int.. This is true whether you instantiate the global
JTextField noOfCookies or just declare it.Right, but the lack of instantiation was pointed out as a possible solution to a second problem, once the program runs, it crashes and issues an error report. The suggestion was made to point out that the user should instantiate the noOfCookies JTextField before adding it to the GUI, and definitely before calling noOfCookies.getText(); (assuming the int was changed to another name, or she correctly referenced the textfield noOfCookies so as not to get the compile time error)

Similar Messages

  • ERROR: int cannot be dereferenced

    hi everyone i am trying to copmile the following code
    public void refreshGUI() {
            MessageBoardQueries MBQ = new MessageBoardQueries();
            Date date = Calendar.getInstance().getTime();
            DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
            String argDate = df.format(date).toString();
            int pNumber = MBQ.queryPending(argDate);
            int aNumber = MBQ.queryAccepted(argDate);
            int dNumber = MBQ.queryDeclined(argDate);
            pendingNumberField.setText(pNumber.toString());
            acceptedNumberField.setText(MBQ.queryAccepted(argDate));
            declinedNumberField.setText(MBQ.queryDeclined(argDate));
        }but i keep getting the error:
    int cannot be dereferenced on the line
    pendingNumberField.setText(pNumber.toString());
    does anyone know why?

    because int is a primitive datatype, hence doesn't inherit from java.lang.Object, and as such doesn't have a toString method
    try Integer.toString(pNumber) or String.valueOf(pNumber). either is equally valid

  • I cannot save in Editor.... error message = program error preview cannot be generated.

    I cannot save changes in Editor when I work with a picture.
    Could not build a preview because of a program error.

    Photoshop has no editor so I assume you are working with Photoshop Elements. Ask your question at
    Photoshop Elements

  • "int cannot be dereferenced" error.. help me please

    I'm working with an array list class called PersonList and it uses attributes from a normal class called Person.
    I would like to make this method PrintPerson inside the PersonList class that should search for a specific Person given the ID as parameter to the method. the method should print all info of the Person if found, otherwise a message saying id is not valid.
    I solved it like this:
    public void PrintPerson(int id)
              System.out.println("Enter ID of the person ");
              id = Stdin.readInteger();
              //search the ID if it is in the List
              int i=0;
              while
              ((i<next)&&(!(list.getID().equals(id))))
              i++;
              //if found
              if (i<next)
                   list[i].OutputWindow();}//display the object ouput of this ID
                   else{
                   System.out.println("The following ID: " id "is not valid!");
              }//end if
         }// end of method
    my problem is with this code:
    ((i<next)&&(!(list.getID().equals(id))))
    I get this error "int cannot be dereferenced"
    what should I do? help me please
    -- Matt

    list.getID() == id                                                                                                                                                                                                                               

  • Sudden attack program error on ge70 2pe

    when i start the game, it pop up the program error and cannot play ... how to fix it???

    There are some people talking about the same problem.
    Give it a try for the solution:https://www.youtube.com/watch?v=kyUErAJ3KRU

  • Using Adobe Photoshop CS2 version 9 and have updated it, but when stacking photos, it comes up with PSD, whereas I want Jpeg, and I change the format to Jpeg and the box then comes up with cannot save as there is a program error. Be very grateful for help

    Using Adobe Photoshop CS2 version 9 and have updated it, but when stacking photos, it comes up with PSD, whereas I want Jpeg, and I change the format to Jpeg and the box then comes up with cannot save as there is a program error. Be very grateful for help with this, please.

    jpg does not support Layers.
    Just to make sure, what exactly do you mean by "stacking photos" and what do you want to achieve thereby?

  • Error Message in PSE 12. Cannot complete request due to a Program Error

    Hi,
    I have just bought Photoshop Elements 12 and have checked for updates. All ok. My laptop meets the system requirements. The OS is Windows 7 Home Premium 64-bit. There is stacks of room on the dedicated hard drive I use for Elements. I use a Nikon 7100. When I am editing my RAW images sometimes everything is fine with the edit completed and saved as designed. At other times I do my editing, click on "open image" and I get an error message that my request cannot be completed because of a program error. The only thing I can do to get editing again is to re-start Elements. Sometimes I get the error message at my first edit and at other times on my second, after a successful first save.
    I'd be grateful for any ideas as to why I'm getting this message and what I need to do to fix it.
    Thanks.
    Miceal Zimmer

    Well, your info is inadequate/ insufficient/ vague. We need exact info about your system, exact memory and file handling settings, what files you work with, what tools/ features/ functions you use when the errors occur and so on. There's always a specific cause.
    Working with your Operating System’s Tools
    Mylenium

  • Not enough Ram memory and cannot save due to a program error in photoshop cs6

    Hi, I'm currently a beginner at photoshop cs6, and I've been using it since december last year, mostly to draw stuff and it has worked fine with few to no errors at all.
    However, recently when I've been drawing, the same message keeps popping up over and over again "Can't use (tool) due to the computer not having enough ram" followed by either "cannot save due to program error" or, it just simply crashes.
    This is obviously a something that worries me A LOT since at first, I thought that it was just a small error, but recently, it's been like this for several day s and I've been forced to re-start the computer (and photoshop) countless times... It really slows down my working progress and is VERY annoying to deal with.
    As a beginner though, I don't really know how to fix this. I've been trying to look up some answers on this site, but I've just not found any answer yet...
    I'm currently using photoshop cs6 that's up to date and I've got lots of memory left on my computer, so, I'm wondering. What exactly is the cause of this problem, and how can I fix it? Please answer as fast as you can.. I'm getting a bit desperate...
    Oh, in case you're wondering, they're all saved as PSD files and every single one of them has about 15+ layers on them.

    It would help if you could list a few things:
    1. Your operating system
    2. How much physical RAM do you actually have in your machine?
    3. Under Preferences > Performance, have you allocated "Scratch Disk(s)"?
    4. Also under Preferences > Performance > Memory Usage, what is the "Ideal Range" listed there, and what % is "Let Photoshop Use"?

  • I cannot open photo's stored in my i photo library to edit in Photoshop Elements.  Adobe comes up with the message program error. I use a Macbook Air.

    I cannot open photo's stored in my i photo library to edit in Photoshop Elements.  Adobe comes up with the message program error. I use a Macbook Air.

    No, that is done deliberately, since letting other programs poke around in the iphoto library is the fastest known way to corrupt it and make it wither up and die, along with your photos. If you want to use PSE with iphoto you have two choices:
    1. Set PSE as your external editor and send the photos from iphoto. Edit them, then save without changing the name or format and iphoto will remember your last saved edits + original, although you have to lose the edits to see the original again. You may need to set the editor prefs>saving files>on first save to save over existing to make this work.
    2. Export the photos from iphoto, use file>open in PSE, make all the changes of any sort that you like, save the file, and import it to iphoto as a new file.

  • BUILD PROGRAM ERROR - CANNOT CREATE PAYMENTS

    Hi, I'm trying to run a payment batch using payments manager and encountered this error.
    In my test data I used two suppliers that belongs to the same operating unit.
    Payments: Version : 12.0.0
    Copyright (c) 1979, 1999, Oracle Corporation. All rights reserved.
    IBYBUILD module: Build Payments
    Current system time is 09-NOV-2009 11:26:11
    **Starts**09-NOV-2009 11:26:11
    **Ends**09-NOV-2009 11:26:13
    BUILD PROGRAM ERROR - CANNOT CREATE PAYMENTS
    Start of log messages from FND_FILE
    IBY_PAYGROUP_PUB.performPostHookProcess: Fatal error - Payment count mismatch after hook operation. # payments passed to hook: 1, # payments returning from hook: 2
    IBY_PAYGROUP_PUB.performPostHookProcess: Aborting program ..
    End of log messages from FND_FILE
    Executing request completion options...
    Finished executing request completion options.
    Exceptions posted by this request:
    Concurrent Request for "Build Payments" has completed with error.
    Concurrent request completed
    Current system time is 09-NOV-2009 11:26:13
    Please help
    thanks,
    Renz

    Hi
    Please review the below note from Metalink,
    Bug No. 6771847
    Filed 24-JAN-2008 Updated 13-MAR-2008
    Product Oracle Payments Product Version 12.0.4
    Platform Linux x86 Platform Version ENTERPRISE 4
    Database Version 10.2.0.2 Affects Platforms Generic
    Severity Severe Loss of Service Status Closed, Verified by Filer
    Base Bug N/A Fixed in Product Version 12.0.4
    Problem statement:
    R12: AFTER APPLYING 12.0.4 BUILD PAYMENT PROGRAM ERRORS
    please review the same if it resolvs your error.
    Thanks
    Manish Jain.

  • Plugin development for premiere, adobe example  error LNK1104: cannot open file 'C:\Program Files\Ad

    Hello,
    I downloaded the Premiere Pro CS 5.5 Win SDK, i open the project SDK_Exporter in Visual Studio 2008, when i hit debug i get the following error
    Error
    1
    fatal error LNK1104: cannot open file 'C:\Program Files\Adobe\Common\Plug-ins\CS6\MediaCore\ExporterSDK.prm'
    How can i resolve ?

    RESOLVED LOOKING AT THE PAST
    1.Zac Lam,01-dic-2013 10:43   in reply to Alex B MartinReport 
    Hi Alex, Are you launching Visual Studio with administrative privileges?  If not, you won’t be able to generate the .aex in certain protected folders because of a Windows security restriction.
    Was this helpful? Yes   No
    Reply 
    |Mark as:
    Unmark as Correct 
    |Translate
    7 posts
    03-ene-2013 
    2.Alex B Martin,01-dic-2013 12:34   in reply to Zac Lam 
    Yes it works, thanks Note: For CS 5.5 Administrative privileges are not need, so thats only with visual studio 2010 and premiere cs6 where i need to run vs2010 as admin.

  • INT-0115: Null Poiner Exception. This is programming error. Please contact

    Hello, good day
    I am fulfilling one interface between maximo eam and sap r3 but to the quere to purchaise requisition of sap to maximo marks the following mistake,
    INT-0115: Null Poiner Exception. This is programming error. Please contact your System Administrator.; nested exception is:
    java.lang.NullPointerException

    Please contact your System Administrator
    Did you?

  • PSE9 does not open – cannot initialize because program error?

    Hello all,
    I have Photoshop Elements 9 installed on my computer (MacBook Pro running Lion). However, I had not used it for a couple of months because I was using the CS6 beta, which finally expired. When I tried to open PSE9, the splash screen loads fine and finishes loading everything, but when it disappears I get a dialog of "Cannot open Photoshop Elements because of a program error."
    This is while running on my main admin account. It opens normally on another admin account which I do not use often, except for some text encoding issues which were not present before.
    I tried repairing permissions, but no luck.
    Does anyone have any ideas? Thank you very much.

    Hi,
    Please try couple of probable solutions as mentioned below:
    Solution 1:
    1. Close Elements.
    2. Launch the Photoshop Elements Welcome Screen and hold down CMD + alt/option + shift as you click Editor.
    3. Continue to hold the keys until you see a message box asking if you want to delete Photoshop Elements settings file; click Yes. Elements will open with default preferences.
    Solution 2: In case any network printer is attached try to launch without network or printer uninstall or make different printer as default.
    Solution 3: Try launching with anti-virus off or removing PSE from conflicting list.
    Solution 4: Remove tha TWAIN plug-in from that location and copy it somewhere  else if you have moved it in past.
    http://helpx.adobe.com/photoshop-elements/kb/twain-installed-photoshop-elements-9.html
    Now launch PSE and check if it works.
    Any further info and clear steps would help further if not sorted. Also just to be on safe side if you can edit your admin name with normal letters (and not any localized one like in german or french) amd then try.
    Thanks,
    Garry

  • A critical program error has occurred. BEx Analyzer. Cannot find trace file

    I have now spent about 20 hours trying to resolve this issue.  I receive the following error message when attempting to open any BEx Query: u201CA critical program error has occurred.  The program will now terminate.  Please refer to the trace for further information()u201D.  Iu2019ve provided a video example of the scenario (couple minutes long): http://www.altnetwork.net/misc/Analyzer%20Critical%20Error.html
    I cannot find the trace file in the standard C:\DOCUME1\BaldwiJE\LOCALS1\Temp\BexAnalyzerTrace.txt path.  I cannot set/change the path/name of the trace file because the Trace File Name text box is grayed out (disabled) in BEx Analyzer > Global Options (see the above flash video link).  I know that I am using the same Business Explorer and GUI build as my colleagues and I am able to login with my ID on their machines and not receive an error.  We are using SAP BW 7.01 and I am using Excel 2007.  I have entirely reinstalled Microsoft Excel, and the SAP Frontend including Business Explorer and SAP GUI.  Iu2019ve monitored using both windows process monitor and windows process explorer but nothing is readily apparent as an issue (glad to share the process information if someone thinks it might help).  No relevant event logs in the Windows event viewer.
    Per the sapbexc.xla file, my system configuration is as follows:
    Computer Name:      DEN-SSI-SYS-L61
    File Location:      C:\DOCUME1\BaldwiJE\LOCALS1\Temp\sapBEX_PC_0614_103147.xls
    Check done on:      6/14/2011   10:31:47 AM
    Excel Version:      Excel 2007 (12.0.6535.5002)
    Windows Version:      Windows 2000  (2195)  Theme: %SystemRoot%\resources\Themes\Windows Classic.theme
    Default Browser:      Internet Explorer (7.0.6000.17093)
    SAP GUI:      720 Patch 1

    Resolved!  It actually seemed to be related to my windows profile.  I notice that if a co-worker logged into windows on my machine that he was able to run the same BEx queries that I couldn't.  I renamed my profile folder at c:\documents and settings\<myaccountname> to ...<myaccountname.bak>.  I did this using a local administrator account on my computer.  Then I logged back in to windows using my AD credentials.  A new profile was created and then I was able to use BEx Analyzer again.
    I also went back and tried to reload everything from my .bak profile into the newly created folder under documents and settings and hoped that I could isolate what specifically was causing the issue.  However, even after moving everything over to my newly created profile I could not get the error to generate again.  Sorry.
    Highly recommend to anyone with the same issue that you confirm that a new profile works by a) having someone else login to your computer who has not already logged in before b) if that works, replace your c:\documents and settings\<myaccountname> folder.
    Thanks to all who offered support.
    Jerimiah

  • Any know how to help with PS Elements ERROR Cannot complete your request because of a program error?

    I just opened PhotoShop Elements 12 and tried saving a file and keep getting the ERROR: Cannot complete your request because of a program error. I cannot save a single file One person said hold SHIFT key while PS was loading and Click Yes about the 3rd party plugins. This did NOT solve the issue. Please any help would be much appreciated!

    That's a well known bug on MacOS 10.10. Apple is aware of it, and working on a solution.

Maybe you are looking for

  • Firefox (or any browser) will not load one particular website. It shows NO error message, just remains blank

    I have the site bookmarked and I try through google as well. Neither Safari or Opera will load this particular website for me. I had this problem in an internet cafe this summer but when i got home it seemed to go away, now it's back. No matter which

  • Can we run SQL query on a XML file?

    Hi All I have an XML document which stores data of a table. My requirement is to retreive data from this XML document by firing SQL query. i.e "SELECT * FROM EMP" should give me the data from the EMP.XML file whose name is the table name. Does Oracle

  • Auto copy command for terminal?

    I want to make Safri history folder auto copy to the other folder as it gets new history. So I can monitor activities.

  • System.out.println does not print out anything

    I'm wonder why the dos mode does not print out the System.out.println. My code has: import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class test extends HttpServlet {    public void doGet(HttpServletRequest request,    Htt

  • Probleme de connection Adobe Flash player Mac

    Bonjour. Voila je vous explique mon problème, j'ai un compte sur le site Adobe ID et je souhaiterai installer adobe flash player pour mac. Le soucis c'est que lorsque le téléchargement est fait, ils me demandent de me connecter, donc je mets mes iden