Solved

Strange problem with getimage()...

Posted on 1997-06-27
3
312 Views
Last Modified: 2010-04-16
Hi, my name is Peppe from Rome

I have a terrible and strange problem : all my program that use the instruction "getimage" does not function because the function return "null" value. All programs some days ago played perfectly.

This is an example :

import java.applet.*;
import java.awt.*;    
import java.net.*;    
import java.io.*;    
import java.lang.System;      

public class me extends Applet {
Image miaimage1 = null;

public void init() {
miaimage1 = getImage(getDocumentBase(), "quadri.jpg");}

public void paint(Graphics g) {
if(miaimage1 != null)
    g.drawImage(miaimage1, 50,10, this);
    else g.drawString("Error image", 30,50);
  }
}

----------------
Result is always "Error Image" (In Netscape 4.0 and Microsoft Explorer 3.0)
0
Comment
Question by:Peppe
3 Comments
 
LVL 6

Accepted Solution

by:
jpk041897 earned 70 total points
ID: 1222391
The call to get Image is documented as:

getImage(URL)

or

getImage(URL, String)


URL is a class that must be instantiated not a url (universal resouce loacator address).

for your images to load you need to build code that looks like:

URL theURL;
...
try{
   theURL = new URL("http://www.yourdomain.com/quadri.jpg");
catch (MalformedURLException e){
   // whatever error proccesing you desire
}
...
miaimage1 = getImage(theURL);


Hope this explanation helps.


0
 
LVL 2

Expert Comment

by:mgk
ID: 1222392
Hi JPK and Peppe,

Remember that the call to java.applet.Applet.getDocumentBase() returns a URL so there shouldn't be the need to seperately instantiate another URL for loading the image. You've changed which method is used but I still can't see why the original code won't work. The next obvious thing is that "quadri.jpg" is actually there and the filename is spelt right.

The fact that everything was perfect a few days ago makes me think you should flush your browser cache and try again - particularly Netscape 4 because it just wierd stuff to applets.

Cheers,

Mark King (mgk)


0
 

Author Comment

by:Peppe
ID: 1222393
Yes, Java code is certainly good, reasons of error must be on system.  Thank you
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
object oriented programming comparison 5 69
Way to decrease size of apk file 9 65
arguments to jar 5 26
JAVA API design with micro service cloud in mind 1 10
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now