Solved

java.lang.NullPointerException error

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Message handling in Service Layer 3 55
eclipse compiler vs Installed JREs option 3 73
Java and GPO 11 66
Apps blocked by Java 9 55
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
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 …
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…

932 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

11 Experts available now in Live!

Get 1:1 Help Now