11-10-2011 10:08 AM
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...
11-10-2011 11:14 AM
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.
11-10-2011 11:19 AM
11-10-2011 11:30 AM - edited 11-10-2011 11:31 AM
Welcome to the forum.
Your SplashScreen seems to be copied directly from this KB article:
http://supportforums.blackberry.com/t5/Java-Develo
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?
11-10-2011 12:10 PM
11-10-2011 12:43 PM
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.
11-11-2011 02:58 AM
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.
05-25-2012 02:07 AM