Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
zapragartiast
Posts: 3
Registered: ‎11-10-2011
My Device: Blackberry Bold 9900

Error When Creating a Splash Screen

Hello for all Blackberry Developer..

But I need some advice about my code when I building a splash screen for my blackberry apps.

 

I was create 2 files, namely splash.java and splashscreen.java but they tell me an error when I will compile them.

this is my code

 

// this is on splash.java

package splash;

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
/**
 * This class extends the UiApplication class, providing a
 * graphical user interface.
 */
public class Splash extends UiApplication
{
	/**
     * Entry point for application
     * @param args Command line arguments (not used)
     */ 
    public static void main(String[] args)
    {
        // Create a new instance of the application and make the currently
        // running thread the application's event dispatch thread.
        Splash theApp = new Splash();       
        theApp.enterEventDispatcher();
    }
    

    /**
     * Creates a new Splash object
     */
    public Splash()
    {        
        // Push a screen onto the UI stack for rendering.
        pushScreen(SplashScreen);
    }    
}

 

this is on splashscreen.java

package splash;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import java.util.*;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class SplashScreen extends MainScreen
{
	private MainScreen next;
	private UiApplication application;
	private Timer timer = new Timer();
	private static final Bitmap _bitmap = Bitmap.getBitmapResource("image.png");
	
    public SplashScreen(UiApplication ui, MainScreen next)
    {        
        super(Field.USE_ALL_HEIGHT | Field.FIELD_LEFT);
        this.application = ui;
        this.next = next;
        this.add(new BitmapField(_bitmap));
        SplashScreenListener listener = new SplashScreenListener(this);
        this.addKeyListener(listener);
        timer.schedule(new CountDown(), 5000);
        application.pushScreen(this);
    }
    
    public void dismiss() {
    	timer.cancel();
    	application.popScreen(this);
    	application.popScreen(next);
    }
    
    private class CountDown extends TimerTask {
    	public void run(){
    		DismissThread dThread = new DismissThread();
    		application.invokeLater(dThread);
    	}
    }
    
    private class DismissThread implements Runnable {
    	public void run(){
    		dismiss();
    	}
    }
    
    protected boolean navigationClick(int status, int time){
    	dismiss();
    	return true;
    }
    
    protected boolean navigationUnclick(int status, int time){
    	return false;
    }
    
    protected boolean navigationMovement(int dx, int dy, int status, int time){
    	return false;
    }
    
    public static class SplashScreenListener implements KeyListener{
    	private SplashScreen screen;
    	public boolean keyChar(char key, int status, int time){
    		boolean retval = false;
    		switch(key){
    		case Characters.CONTROL_MENU:
    		case Characters.ESCAPE:
    		screen.dismiss();
    		retval = true;
    		break;
    		}
    		return retval;
    	}
    public boolean keyDown(int keycode, int time){
    	return false;
    }
    
    public boolean keyRepeat(int keycode, int time){
    	return false;
    }
    
    public boolean keyStatus(int keycode, int time){
    	return false;
    }
    
    public boolean keyUp (int keycode, int time){
    	return false;
    }
    
    public SplashScreenListener(SplashScreen splash){
    	screen = splash;
    }
    }
    
}

I got the error there.. Please give me some advice to fix them. thank you...

Developer
Shraddha
Posts: 34
Registered: ‎07-25-2008
My Device: Not Specified

Re: Error When Creating a Splash Screen

why are you pushing screen in the constructor?

Another thing, i dont see a new SplashScreen created, that is new operator is not used.

 

What is the compiler error that you get? Please elaborate the error and we can help.

New Contributor
zapragartiast
Posts: 3
Registered: ‎11-10-2011
My Device: Blackberry Bold 9900

Re: Error When Creating a Splash Screen

First I got error on the KeyListener. KeyListener cannot be resolved to a type.
Second, SplashScreen cannot be resolved to a variable.
Third, The method addKeyListener(KeyListener) in the type Screen is not applicable for the arguments (SplashScreen.SplashScreenListener)

that's the error I've got.
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Error When Creating a Splash Screen

[ Edited ]

Welcome to the forum.

 

Your SplashScreen seems to be copied directly from this KB article:

 

http://supportforums.blackberry.com/t5/Java-Development/Create-a-splash-screen/ta-p/444959

 

If you are having compile errors with that code then we need to get someone from RIM to have a look.  So can you cut and paste the actual errors you see into the forum for us.

 

But as noted, this is wrong

 

pushScreen(SplashScreen);

 

You need to have created a new instance of the class SplashScreen and to do that you need to have created the screen to be displayed after it.

 

How new to Java coding are you? 

 

New Contributor
zapragartiast
Posts: 3
Registered: ‎11-10-2011
My Device: Blackberry Bold 9900

Re: Error When Creating a Splash Screen

Yes, I've got the code from the URL.
I'm new on blackberry developer, and I want to learn and making some application on Blackberry.
Maybe you can provide me some code to run splash screen on blackberry, cause I want to know that...
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Error When Creating a Splash Screen

I strongly suspect the problems you are having with Splash Screen are a result of you not knowing Java.  So learn java first.  Don't learn it in Blackberry, it is hard to test BlackBerry.  Get a simple book and learn java on your Desktop.  Then when you feel like you can code a program in java come back to BlackBerry. 

Developer
Shraddha
Posts: 34
Registered: ‎07-25-2008
My Device: Not Specified

Re: Error When Creating a Splash Screen

Your compiler is complaining because:

First I got error on the KeyListener. KeyListener cannot be resolved to a type.

- net.rim.device.api.system package is not imported
Second, SplashScreen cannot be resolved to a variable.

- SplashScreen is a class... not a variable. Create a new instance .. "new SplashScreen()"
Third, The method addKeyListener(KeyListener) in the type Screen is not applicable for the arguments (SplashScreen.SplashScreenListener)

- that's because keylistener is not recognised so "SplashscreenListener implements KeyLIstener" is not working for you.

 

So basically, it all boils down to (as peter_strange said) .. java fundamentals

It'll be difficult to get on BB directly without sufficient knowledge of java... even the replies will be difficult to understand.

 

New Member
girishnair12345
Posts: 2
Registered: ‎05-25-2012
My Device: BB Bold

Re: Error When Creating a Splash Screen

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import java.util.*;

public class SplashScreen extends MainScreen {
private MainScreen next;
private UiApplication application;
private Timer timer = new Timer();
private static final Bitmap _bitmap = Bitmap.getBitmapResource("image.png");
public SplashScreen(UiApplication ui, MainScreen next) {
super(Field.USE_ALL_HEIGHT | Field.FIELD_LEFT);
this.application = ui;
this.next = next;
this.add(new BitmapField(_bitmap));
SplashScreenListener listener = new SplashScreenListener(this);
this.addKeyListener(listener);
timer.schedule(new CountDown(), 5000);
application.pushScreen(this);
}
public void dismiss() {
timer.cancel();
application.popScreen(this);
application.pushScreen(next);
}
private class CountDown extends TimerTask {
public void run() {
DismissThread dThread = new DismissThread();
application.invokeLater(dThread);
}
}
private class DismissThread implements Runnable {
public void run() {
dismiss();
}
}
protected boolean navigationClick(int status, int time) {
dismiss();
return true;
}
protected boolean navigationUnclick(int status, int time) {
return false;
}
protected boolean navigationMovement(int dx, int dy, int status, int time) {
return false;
}
public static class SplashScreenListener implements
KeyListener {
private SplashScreen screen;
public boolean keyChar(char key, int status, int time) {
//intercept the ESC and MENU key - exit the splash screen
boolean retval = false;
switch (key) {
case Characters.CONTROL_MENU:
case Characters.ESCAPE:
screen.dismiss();
retval = true;
break;
}
return retval;
}
public boolean keyDown(int keycode, int time) {
return false;
}
public boolean keyRepeat(int keycode, int time) {
return false;
}
public boolean keyStatus(int keycode, int time) {
return false;
}
public boolean keyUp(int keycode, int time) {
return false;
}
public SplashScreenListener(SplashScreen splash) {
screen = splash;
}
}
}