CSC300: Eclipse Problems

Contents [0/9]

The most common problem with eclipse [1/9]
Installation problems? [2/9]
What to do if you get errors on the format function [3/9]
What to do you have lots of red marks in Eclipse [4/9]
How to add a JRE [5/9]
What to do if you cannot see package explorer in Eclipse [6/9]
Run problems? [7/9]
About the code from the textbook [8/9]
Disassemblers and decompilers [9/9]

(Click here for one slide per page)


The most common problem with eclipse [1/9]

The most common problem with eclipse is that the compiler compliance level gets messed up. Try this. If it does not work, then contact me.

With the compliance level issue, you may get a lot of compiler errors, such as this:

eclipse-common1

To fix it, pull up eclipse preferences. On windows, this is under the window menu.

eclipse-common2

Navigate to the compiler pane so that you can see the compliance level.

eclipse-common3

If the compliance level is anything other than 11, set it to 11 and then save and follow the prompts to recompile your entire workspace. It will take a few seconds.

eclipse-common4

If the compliance level is already correct, then set it to 1.4, and then save and follow the prompts to recompile your entire workspace. Then repeat the process and set it back to 11.

This appears to be a bug in eclipse. Good news is that is it seems to happen at most once with students in this class.

If this did not fix your issue, contact me.

Installation problems? [2/9]

These notes are a bit old. Anywhere the notes mention java 8 or 1.8, you can substitute java 11.

If you have errors after installing eclipse and the code from class, please look throught these notes and watch this:

Open Playlist

If you can't fix it, contact me on the dicussion forum ASAP. Don't waste time trying to fix a broken eclipse install.

What to do if you get errors on the format function [3/9]

You may get a compiler error message like this:

The method format(String, Object[]) in the type StdOut is not applicable for the arguments (String, String)
The method format(String, Object[]) in the type StdOut is not applicable for the arguments (String, String, int, int)

Make sure that you are using Java 11.

install-eclipse-jre2
install-eclipse-jre1

What to do you have lots of red marks in Eclipse [4/9]

Suppose you had eclipse working and then one day, eclipse looks like this:

install-eclipse-red

Try

  "Project" > "Clean..." > "Clean all projects"

If that does not work, try creating a fresh eclipse-workspace.

The above works by copying the good files to a new eclipse-workspace. You can also try the following approach, which removes the problematic files from the exiting eclipse-workspace instead.

If that does not work ensure that you have the correct version of Java installed.

How to add a JRE [5/9]

Eclipse will only include JREs that were present before it started in a given workspace. If you add a JRE later, the easiest thing to do is to recreate the workspace from scratch. See the instructions on the previous slide.

You can also add a JRE after the fact, following these instructions:

add-jre1

add-jre2

add-jre3

add-jre4

What to do if you cannot see package explorer in Eclipse [6/9]

To show the package explorer, do this:

package-explorer1

Once it is showing, you can adjust the view using the buttons:

package-explorer2

Run problems? [7/9]

You may get this Run As box in eclipse, like this:

install-run1

Or this:

install-run2

First, make sure that you are running the code from the correct package in the src folder. Go back to the installation instructions for the code from class and make sure that the package explorer looks correct. If not, re-do the installation of the code from class, and start over.

If the package explorer looks okay, then try selecting the program you want to run in the package explorer and using a right click to bring up a context menu. You can select run from there:

install-run3

The run button is context sensitive in eclipse. It's behavior varies depending upon where the mouse was last clicked and what the last command to be run was. This problem usually sorts itself out. So try the run button again later.

About the code from the textbook [8/9]

The textbook code is written to run from the command line. We will not do this. Instead, we will edit the code in eclipse to provide the following, when necessary:

  1. command line arguments
  2. standard input
  3. standard output

If the text runs the program:

  java Program arg1 arg2 < input.txt > /tmp/output.txt

We will add the following lines to the "main" method of our java program:

  public static void main(String[] args) {
    args = new String[] { "arg1", "agrg2" };
    StdIn.fromFile ("data/input.txt") 
    StdOut.toFile ("/tmp/output.txt")
    ...

Disassemblers and decompilers [9/9]

The java SDK distributes with command-line tool javap. This is a disassembler

Try this from your eclipse-workspace directory:

javap -c -l -s -sysinfo -constants bin/algs11/Hello.class

This will show you java bytecode

Here are the meaning of the options of javap:

  -c           Disassemble the code
  -constants   Show final constants
  -l           Print line number and local variable tables
  -s           Print internal type signatures
  -sysinfo     Show system info (path, size, date, MD5 hash) of class

  -public      Show only public classes and members
  -protected   Show protected/public classes and members
  -package     Show package/protected/public classes and members (default)
  -p  -private Show all classes and members

  -v  -verbose Print additional information

There are also decompilers

procyon and cfr are particularly nice.


Revised: 2008/03/17 13:01