Solved

java.lang.NullPointerException error

Posted on 1997-03-23
1
388 Views
Last Modified: 2008-03-17
I am currently working on putting simple *.gif images on my java applet and
cannot get the picture to show up on the html document's applet frame.  The
same holds true with playing sounds  The luketest.html opens fine, the
applet compiles, but no sound is played.  The applets compile and the paths
are correct relative to both the html document and class file which are in
the same folder.  I will post both codes and note that the misc file in the
getCodeBase() instruction is in the same level of the same folder as the
html and class files.  I will paste the source for the html page and the
applet it contains for the playing sounds.  All that I get is the applet
frame with the words "playing sounds...".  Any help would be greatly
appreciated.  When using appletviewer to read luketest.html, as oppossed to
IE, I get the following message on the MS DOS screen:


java.lang.NullPointerException:
      at htmltest.run(htmltest.java:28)
     at java.lang.Thread.run(Thread.java:481)



<HTML>
<HEAD>
<TITLE>testjava</TITLE>
</HEAD>
<BODY>
<A NAME = "TOP"> </A>
<p>Below lies my java applet to be tested</p>
<Applet code="htmltest.class" width=250 height=180>
</Applet>
</BODY>
</HTML>




import java.awt.Graphics;
import java.applet.AudioClip;


public class htmltest extends java.applet.Applet
  implements Runnable {

  AudioClip sound;
     Thread runner;

  public void start() {
    if (runner == null) {
      runner = new Thread(this);
      runner.start();
    }
  }

  public void stop() {
    if (runner != null) {
      if (sound != null) sound.stop();
      runner.stop();
      runner = null;
    }
  }

  public void run() {
   
    sound.loop();
     
  }
   


  public void intit(){
    sound = getAudioClip(getCodeBase(), "misc/nilesong.au");
   
  }


  public void paint(Graphics g){
    g.drawString("Playing Sounds....", 10, 10);

  }

}



Thank You

Luke Danielson
0
Comment
Question by:luke032397
[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
1 Comment
 

Accepted Solution

by:
jrsp earned 25 total points
ID: 1219177
1.  If you cut-and-pasted this code in, change your intit() method to the proper "init()" or it will never be called.

2.  Make sure your audio clip lives in the misc directory directly below the HTML page this applet lives on.  If it doesn't your attempt to load it will fail and sound will be null.

3.  In your run() method, put in a check to see if sound is null.  If it is, don't try and reference it but rather show some kind of error msg or whatever else makes sense.


0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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:

630 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