<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Cannot compile Java application' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Cannot compile Java application' posted on the 'Java' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Mon, 17 Jun 2013 23:12:55 -0700</pubDate>
    <lastBuildDate>Mon, 17 Jun 2013 23:12:55 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Cannot compile Java application</title>
      <link>http://www.programmersheaven.com/mb/java/419436/419436/cannot-compile-java-application/</link>
      <description>Hello, I am new to Java and programming in general. I have a source of an application written in Java that I want to change a part of and compile it. Here is the file I am working on:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;package sarf.ui;

import java.awt.Toolkit;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.Dimension;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.JOptionPane;

/**
 *

Title:

 *
 *

Description:

 *
 *

Copyright: Copyright (c) 2006

 *
 *

Company:

 *
 * @author not attributable
 * @version 1.0
 */
public class MainApp {
    boolean packFrame = false;

    /**
     * Construct and show the application.
     */
    public MainApp() {
       
        // Center the window

        Dimension frameSize = frame.getSize();
        if (frameSize.height &amp;gt; screenSize.height) {
            frameSize.height = screenSize.height;
        }
        if (frameSize.width &amp;gt; screenSize.width) {
            frameSize.width = screenSize.width;
        }
        frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
        frame.setVisible(true);
    }

    /**
     * Application entry point.
     *
     * @param args String[]
     */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                try {
                    //MetalLookAndFeel.setCurrentTheme(new javax.swing.plaf.metal.OceanTheme());
                    UIManager.setLookAndFeel(MetalLookAndFeel.class.ge
tName());
                }
                catch (Exception exception) {
                    exception.printStackTrace();
                }

                new MainApp();
            }
        });
    }
}

&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
When I try to compile it, I get the following error:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;[zand@zand ui]$ /opt/java/bin/javac -verbose MainApp.java
[parsing started MainApp.java]
[parsing completed 39ms]
[search path for source files: .]
[search path for class files: /opt/java/jre/lib/resources.jar,/opt/java/jre/lib/
rt.jar,/opt/java/jre/lib/sunrsasign.jar,/opt/java/
jre/lib/jsse.jar,/opt/java/jre/lib/jce.jar,/opt/ja
va/jre/lib/charsets.jar,/opt/java/jre/classes,/opt
/java/jre/lib/ext/dnsns.jar,/opt/java/jre/lib/ext/
localedata.jar,/opt/java/jre/lib/ext/sunjce_provid
er.jar,/opt/java/jre/lib/ext/sunpkcs11.jar,.]
[loading java/awt/Toolkit.class(java/awt:Toolkit.class)]
[loading javax/swing/SwingUtilities.class(javax/swing:Swing
Utilities.class)]
[loading javax/swing/UIManager.class(javax/swing:UIManager.
class)]
[loading java/awt/Dimension.class(java/awt:Dimension.class)
]
[loading javax/swing/plaf/metal/MetalLookAndFeel.class(java
x/swing/plaf/metal:MetalLookAndFeel.class)]
[loading javax/swing/JOptionPane.class(javax/swing:JOptionP
ane.class)]
[loading java/lang/Object.class(java/lang:Object.class)]
[loading java/lang/String.class(java/lang:String.class)]
[checking sarf.ui.MainApp]
MainApp.java:32: cannot find symbol
symbol  : variable frame
location: class sarf.ui.MainApp
        Dimension frameSize = frame.getSize();
                              ^
MainApp.java:33: cannot find symbol
symbol  : variable screenSize
location: class sarf.ui.MainApp
        if (frameSize.height &amp;gt; screenSize.height) {
                               ^
MainApp.java:34: cannot find symbol
symbol  : variable screenSize
location: class sarf.ui.MainApp
            frameSize.height = screenSize.height;
                               ^
MainApp.java:36: cannot find symbol
symbol  : variable screenSize
location: class sarf.ui.MainApp
        if (frameSize.width &amp;gt; screenSize.width) {
                              ^
MainApp.java:37: cannot find symbol
symbol  : variable screenSize
location: class sarf.ui.MainApp
            frameSize.width = screenSize.width;
                              ^
MainApp.java:39: cannot find symbol
symbol  : variable screenSize
location: class sarf.ui.MainApp
        frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
                           ^
MainApp.java:39: cannot find symbol
symbol  : variable screenSize
location: class sarf.ui.MainApp
        frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
                                                                     ^
MainApp.java:39: cannot find symbol
symbol  : variable frame
location: class sarf.ui.MainApp
        frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
        ^
MainApp.java:40: cannot find symbol
symbol  : variable frame
location: class sarf.ui.MainApp
        frame.setVisible(true);
        ^
[loading java/lang/Runnable.class(java/lang:Runnable.class)
]
[loading java/lang/Class.class(java/lang:Class.class)]
[loading javax/swing/LookAndFeel.class(javax/swing:LookAndF
eel.class)]
[loading java/lang/Exception.class(java/lang:Exception.clas
s)]
[loading java/lang/Throwable.class(java/lang:Throwable.clas
s)]
[total 349ms]
9 errors&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
As far as I understand I am missing some standard class library to work .getSize though it seems to load some classes from /opt/java/jre/lib/.</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/419436/419436/cannot-compile-java-application/</guid>
      <pubDate>Mon, 01 Nov 2010 04:29:21 -0700</pubDate>
      <category>Java</category>
    </item>
    <item>
      <title>Re: Cannot compile Java application</title>
      <link>http://www.programmersheaven.com/mb/java/419436/419508/re-cannot-compile-java-application/#419508</link>
      <description>Your file is in a package named sarf.ui and this will affect the kind of compiling command you have to use and where to store your file.&lt;br /&gt;
&lt;br /&gt;
Make a file directory structure like this for your code:&lt;br /&gt;
sarf&lt;br /&gt;
 - ui&lt;br /&gt;
 -   - MainApp.java&lt;br /&gt;
&lt;br /&gt;
In other words, make directory sarf.  make a directory ui to go within sarf.  make file MainApp.java to go within ui.&lt;br /&gt;
&lt;br /&gt;
Your MainApp.java had some undeclared variables like frame and screensize so it was updated to work.  Here is the contents of MainApp.java:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
package sarf.ui;

import java.awt.Toolkit;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.Dimension;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.JOptionPane;
import javax.swing.JFrame;

/**
 *

Title:

 *
 *

Description:

 *
 *

Copyright: Copyright (c) 2006

 *
 *

Company:

 *
 * @author not attributable
 * @version 1.0
 */
public class MainApp {
    boolean packFrame = false;
  JFrame frame;

    /**
     * Construct and show the application.
     */
    public MainApp() {
        // create the frame.
        frame = new JFrame("The Window");
        frame.setSize(400,400);
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension screenSize = toolkit.getScreenSize(); 
       
        // Center the window


        Dimension frameSize = frame.getSize();
        if (frameSize.height &amp;gt; screenSize.height) {
            frameSize.height = screenSize.height;
        }
        if (frameSize.width &amp;gt; screenSize.width) {
            frameSize.width = screenSize.width;
        }
        frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
        frame.setVisible(true);
    }

    /**
     * Application entry point.
     *
     * @param args String[]
     */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                try {
                    //MetalLookAndFeel.setCurrentTheme(new javax.swing.plaf.metal.OceanTheme());
                    UIManager.setLookAndFeel(MetalLookAndFeel.class.ge
tName());
                }
                catch (Exception exception) {
                    exception.printStackTrace();
                }

                new MainApp();
            }
        });
    }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
To compile that from command line, go to the directory above sarf, the root directory of your code.  From there, use this command:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
javac sarf/ui/*.java
&lt;/pre&gt; &lt;br /&gt;
&lt;br /&gt;
To run the resulting .class file, execute from the same directory as compilation, the following command:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
java sarf.ui.MainApp
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Without the line "package sarf.ui;" in your code, there would be no need to worry about the directory structure.</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/419436/419508/re-cannot-compile-java-application/#419508</guid>
      <pubDate>Wed, 03 Nov 2010 13:33:13 -0700</pubDate>
      <category>Java</category>
    </item>
  </channel>
</rss>