Solved

Strange problem with getimage()...

Posted on 1997-06-27
3
310 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
Comment Utility
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
Comment Utility
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
Comment Utility
Yes, Java code is certainly good, reasons of error must be on system.  Thank you
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

763 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

8 Experts available now in Live!

Get 1:1 Help Now