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

Thread: Error: The import java.swing cannot be resolved [in drJava]

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Error: The import java.swing cannot be resolved [in drJava]

    Hello, I decided to make an applet in java and wanted to use drJava for it. I installed the program and the JDK. Then, after making a code to start from, I ran into a problem.

    This is the code:

    import java.swing.JApplet;
    import java.awt.*;
     
    public class FirstAppletDrawing extends Applet{
     public void paint (Graphics page){
      setBackground (Color.cyan); //background color
     
      page.setColor (Color.gray); //Robot head color
      page.drawRec (3,4,20,20); //Robot head
     }
    }

    When I try to compile it, the first error I get is: Error: The import java.swing cannot be resolved

    I thought that I may be doing something wrong, so I decided to try and make a simpler program:

    public class Simple{
      public static void main (Strings[] args){
        int future = 5;
        int past = 1;
        int present = future - past;
     
        System.out.println("Our future is " + future + ", our past is " + past +
                           ", and our present is" + present);
      }
    }

    When I tried to compile that, I go this: Error: Strings cannot be resolved to a type

    And that's basically from the book. Am I missing something or doing something wrong?


  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Error: The import java.swing cannot be resolved [in drJava]

    java.swing

    Here's the issue: the swing package isn't in the java package, it's in the javax package. So, you need to import swing from javax, not java.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  3. #3
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Error: The import java.swing cannot be resolved [in drJava]

    java.swing

    Here's the issue: the swing package isn't in the java package, it's in the javax package. So, you need to import swing from javax, not java.

    Strings cannot be resolved to a type
    I don't know what's causing that...



    Edit: Sorry for the double post; don't know why that happened...
    Last edited by snowguy13; January 24th, 2012 at 05:47 PM.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

  4. #4
    Junior Member
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Error: The import java.swing cannot be resolved [in drJava]

    Thanks! I started looking though the two and found the little problems! Your solution was a great hint!

  5. #5
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: Error: The import java.swing cannot be resolved [in drJava]

    That's good! Good luck on your program!
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

Similar Threads

  1. import, .java files, and jsoup-1.6.1
    By dalydir in forum Java Theory & Questions
    Replies: 2
    Last Post: January 20th, 2012, 07:49 PM
  2. how to compile java and import it as package
    By clementnas in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 19th, 2011, 06:53 AM
  3. "The import ___ cannot be resolved" (stupid noob question)
    By RobG in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 18th, 2010, 03:09 PM
  4. how to import my own class in my .java file
    By amr in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 17th, 2010, 09:31 PM
  5. Error msg : 'pageContext' cannot be resolved in tag file....
    By saikrishna436 in forum JavaServer Pages: JSP & JSTL
    Replies: 5
    Last Post: September 8th, 2009, 08:58 AM