Solved

java.lang.NullPointerException error

Posted on 1997-03-23
1
381 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
1 Comment
 

Accepted Solution

by:
jrsp earned 25 total points
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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 “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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 …

743 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

17 Experts available now in Live!

Get 1:1 Help Now