Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

java.lang.NullPointerException error

Posted on 1997-03-23
1
Medium Priority
?
391 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 50 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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

704 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