BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 05-28-2008, 10:46 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: May 2008
Model: 7100
PIN: N/A
Carrier: Sprint
Posts: 31
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default uncaught exception java.lang.nullpointer exception

Please Login to Remove!

hi all,

i am getting a uncaught exception java.lang.nullpointer exception as soon as i try to launch my application.

Following is my code for the reference

import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.InputConnection;
import javax.microedition.io.file.FileConnection;
import javax.microedition.lcdui.Display;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.PlayerListener;
import javax.microedition.media.control.VideoControl;
import javax.microedition.media.control.VolumeControl;
import javax.microedition.midlet.MIDlet;


public class GSMmidlet extends MIDlet implements PlayerListener,Runnable {

Display display;
GSMCanvas canvas;
private Player player;
private VideoControl vc;
private VolumeControl volume;
public void destroyApp(boolean unconditional) {
destroyApp(true);
notifyDestroyed();
}

public void pauseApp() {


}

public void startApp() {
display=Display.getDisplay(this);
canvas=new GSMCanvas();
display.setCurrent(canvas) ;
}
public void start()
{


Thread t = new Thread(this);
t.start();
}


public void run()
{
if(canvas.index==0)
play1();
else
play2();
}
public void play1()
{
try
{
InputStream is=getClass().getResourceAsStream("/clip_5.3gp");
player=Manager.createPlayer(is,"video/3gpp");
player.addPlayerListener(this);
player.realize();
volume = (VolumeControl) player.getControl("VolumeControl");
volume.setLevel(18);
vc = (VideoControl) player.getControl("VideoControl");
if (vc != null) {
vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, canvas);
vc.setDisplayLocation(0,0);
vc.setVisible(true);
player.start();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
protected static String STORAGE_DIRECTORY="file:///c:/";

public void play2() {
try
{
InputConnection file = (FileConnection)Connector.open(STORAGE_DIRECTORY+" clip_5.3gp");
InputStream is = file.openInputStream();
player = Manager.createPlayer(is,"video/3gpp");
player.addPlayerListener(this);
player.realize();
volume = (VolumeControl) player.getControl("VolumeControl");
volume.setLevel(18);
vc = (VideoControl) player.getControl("VideoControl");
if (vc != null) {
vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, canvas);
vc.setDisplayLocation(0,0);
vc.setVisible(true);
player.start();
}
}
catch(Exception e)
{
e.printStackTrace();
}

}


public void playerUpdate(Player player,
String event, Object data) {
}



}

import java.io.IOException;
import javax.microedition.lcdui.*;
public class GSMCanvas extends Canvas{

String menus[]={"Video from Resource","Video from File System"};
Image background;
Image header;
Image footer;
Image selected;
Image unselected;
Font menuFont;
Font headerFont;
Font textFont;
int index=0;
int YAXIS=60;
GSMmidlet midlet;
public GSMCanvas()
{

menuFont = Font.getFont(Font.FACE_SYSTEM,Font.STYLE_BOLD,Font .SIZE_MEDIUM);
headerFont = Font.getFont(Font.FACE_SYSTEM,Font.STYLE_BOLD,Font .SIZE_LARGE);
textFont = Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Fon t.SIZE_MEDIUM);
try
{

background=Image.createImage("/BACKGROUND.png");
header=Image.createImage("/header.png");
footer=Image.createImage("/footer.png");
selected=Image.createImage("/selected.png");
unselected=Image.createImage("/unselected.png");

}
catch(IOException e)
{
e.printStackTrace();
}


}
protected void paint(Graphics g) {
g.drawImage(background, 0, 0, 0);
g.drawImage(header, 0, 0, 0);
g.drawImage(footer, 5, getHeight()-30, 0);
g.drawImage(unselected, 0, 80, 0);
g.drawImage(unselected, 0, 130, 0);
g.setColor(255,255,255);
g.drawString(menus[0], 20, 85, 0);
g.drawString(menus[1], 20, 135, 0);
g.drawImage(selected, 0, YAXIS, 0);
g.setFont(menuFont);
g.drawString(menus[index], 20, YAXIS+10, 0);

}

public void keyPressed(int key)
{

System.out.println("Key"+key);
if(key==-2)
{
index++;
YAXIS=60;
System.out.println("index:"+index);
if(index==1)
{
//index=0;
YAXIS=130;
System.out.println("Index in if:"+index);
}
else if(index>1)
{
index=0;
YAXIS=60;
}
}

if(key==-1)
{
index--;
YAXIS=130;
if(index==0)
{
YAXIS=60;
}
else if(index<0)
{
index=1;
YAXIS=130;
}
}

if(key==-5)
{
System.out.println("Index in -5"+index);
midlet.start();
}


repaint();
}
}

thanks in advance
ajj
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.