Solved

Strange problem with getimage()...

Posted on 1997-06-27
3
313 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Should localization be done inside spring controller 5 37
Error in @AspectJ Based AOP with Spring 2 24
Convert from a json string array to a Java object 3 65
hashmap order 17 43
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

730 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