?
Solved

Strange problem with getimage()...

Posted on 1997-06-27
3
Medium Priority
?
319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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…
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:
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

764 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