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

Thread: error in code?

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default error in code?

    import java.awt.*;
    import java.applet.Applet;

    public class displayImage extends Applet {
    Image img;

    public void init(){
    img=getImage(getCodeBase(),"runningman.jpg" );
    }

    public void paint(Graphics g){
    g.drawImage(img,0,0,this);
    g.drawImage(img, 90, 0, 300, 62, this);
    }
    }

    hello everyone, the above code aims to get the image of, say, runningman picture downloaded from google image(and I have put it in the directory of the java file) to be displayed in an appletviewer, but when I run the code, it seems that the picture of running man is not coming out. Can someone help me to run the code in their IDE and see what's wrong with the code. Greatly appreciate any help/ guidelines that can be provided.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: error in code?

    The image needs to go in the getCodeBase() folder. Add a println statement to print out what getCodeBase() returns so you see where the program is looking for the image.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    bryanOnInternet (January 2nd, 2013)

  4. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    9
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: error in code?

    Quote Originally Posted by Norm View Post
    The image needs to go in the getCodeBase() folder. Add a println statement to print out what getCodeBase() returns so you see where the program is looking for the image.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    really sorry for the really late reply. Thanks for the guideline provided on both the question and code quote(just knew about the code quote).

Similar Threads

  1. Error in IF-Else Code
    By jonathon6017 in forum Loops & Control Statements
    Replies: 25
    Last Post: January 18th, 2012, 03:57 AM
  2. Code is giving an error in console, but there are no errors apparent in the code!
    By JamEngulfer221 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 15th, 2011, 09:30 PM
  3. Error in code
    By JCTexas in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 21st, 2011, 05:53 PM
  4. [SOLVED] Help with an error in code
    By cis170 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 6th, 2010, 10:21 AM
  5. Error with code
    By JJTierney in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 4th, 2010, 05:23 PM