Hello. I am new to java developing. I am using BB JDE to create an application. I started from a sample HelloWorld application i found online that consists of two files.
MobileApplication.java
Code:
package code;
import code.MyScreen;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.system.Characters;
/**
* Main application class.
*/
public class MobileApplication extends UiApplication {
/**
* Application entry point.
* @param args application arguments.
*/
public static void main(String[] args) {
// creating application instance
MobileApplication app = new MobileApplication();
// entering event dispatcher
app.enterEventDispatcher();
}
/**
* "MobileApplication" class default constructor.
*/
public MobileApplication() {
// creating screen instance
MyScreen screen = new MyScreen();
// displaying screen
pushScreen(screen);
}
/**
* Invoked when a key pressed.
* @param key key pressed.
* @param status status of key pressed.
* @param time time in ms since last reset.
* @return true if event consumed.
*/
public boolean keyChar(char key, int status, int time) {
boolean eventConsumed = false;
//intercept the ESC key - exit the app if escape pressed
if (key==Characters.ESCAPE) {
System.exit(0);
eventConsumed = true;
}
return eventConsumed;
}
}
and MyScreen.java
Code:
package code;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.MainScreen;
/**
* Screen class.
*/
public class MyScreen extends MainScreen {
/**
* "Close" menu item.
*/
private MenuItem menuItemClose = new MenuItem("Close", 20, 400) {
public void run() {
// exiting from the application.
System.exit(0);
}
};
/**
* "Run" menu item.
*/
private MenuItem menuItemRun = new MenuItem("Run", 20, 400) {
public void run() {
// displaying dialog box
Dialog.alert("Hello :)");
}
};
/**
* Default constructor.
*/
public MyScreen() {
super(); // calling parent's constructor
addScreenItems(); // adding visual elements to the screen
}
/**
* Adds visual elements to the screen.
*/
public void addScreenItems() {
setTitle("HelloWorld from Tbilisoft :)");
this.add(new LabelField("Open menu and select \"Run\""));
this.add(new SeparatorField());
this.add(new LabelField("To close application - Open menu and select \"Close\" or click \"Escape\" key."));
}
/**
* Processes trackwheel click.
* @param status State of the modifier keys.
* @param time Number of milliseconds since the device was turned on.
* @return true if event consumed, otherwise returns false.
*/
public final boolean trackwheelClick(int status, int time) {
// displaying menu.
Menu menu = new Menu();
makeMenu(menu, 0);
menu.show();
// event consumed
return true;
}
/**
* Called to populate the menu.
*
* @param menu Menu to which items should be added.
* @param instance The instance of the desired menu. If your screen supports
* only one menu, this may be ignored. By default, it is 0.
*/
protected void makeMenu(Menu menu, int instance) {
menu.add(menuItemRun);
menu.add(menuItemClose);
}
}
I added a new file to the project called FileRead
Code:
package code;
import java.io.*;
public class FileRead {
public FileRead() {
}
public void read () {
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("IMG_0001.doc");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
} catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
and when i build the project i get the following errors
Code:
C:\Java Programming\Application\code\FileRead.java:14: cannot find symbol
symbol : class FileInputStream
location: class code.FileRead
FileInputStream fstream = new FileInputStream("IMG_0001.doc");
^
C:\Java Programming\Application\code\FileRead.java:14: cannot find symbol
symbol : class FileInputStream
location: class code.FileRead
FileInputStream fstream = new FileInputStream("IMG_0001.doc");
^
C:\Java Programming\Application\code\FileRead.java:17: cannot find symbol
symbol : class BufferedReader
location: class code.FileRead
BufferedReader br = new BufferedReader(new InputStreamReader(in));
^
C:\Java Programming\Application\code\FileRead.java:17: cannot find symbol
symbol : class BufferedReader
location: class code.FileRead
BufferedReader br = new BufferedReader(new InputStreamReader(in));
^
4 errors
I 've searched everywhere and i don't understand where the problem is. The projects builds fine without the FileRead file.