BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/index.php)
-   Developer Forum (http://www.blackberryforums.com/forumdisplay.php?f=15)
-   -   cannot find symbol error (http://www.blackberryforums.com/showthread.php?t=191941)

polys 05-31-2009 03:58 PM

cannot find symbol error
 
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.

Dougsg38p 05-31-2009 10:38 PM

Add this to your imports:

import net.rim.device.api.io.FileInputStream;

polys 06-01-2009 07:45 AM

Quote:

Originally Posted by Dougsg38p (Post 1395872)
Add this to your imports:

import net.rim.device.api.io.FileInputStream;

So i cannot use the Java libraries directly?

i.e. import java.io.*;

When i add

import net.rim.device.api.io.FileInputStream;

i still get the following errors:

Code:

C:\Java Programming\Application\code\MobileApplication.java:61: cannot find symbol
symbol  : constructor FileInputStream(java.lang.String)
location: class net.rim.device.api.io.FileInputStream
            FileInputStream fstream = new FileInputStream("IMG_0001.doc");
                                      ^
C:\Java Programming\Application\code\MobileApplication.java:64: cannot find symbol
symbol  : class BufferedReader
location: class code.MobileApplication
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            ^
C:\Java Programming\Application\code\MobileApplication.java:64: cannot find symbol
symbol  : class BufferedReader
location: class code.MobileApplication
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
                                    ^
3 errors


bemshaswing 06-01-2009 09:54 AM

I note that the api defines only one constructor, FileInputStream(int fs, String fileName) which is not how you're instantiating it. api link

for all bb development, you'll have to conform your code specifically to the RIM API specification

polys 06-01-2009 11:36 AM

Quote:

Originally Posted by bemshaswing (Post 1396169)
for all bb development, you'll have to conform your code specifically to the RIM API specification

so i cannot use java classes as i would normally do if i was creating a normal java application?

For example, i cannot read a file like this

PHP Code:

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);
            } 

because BufferedReader is not included in the BB apis?

Dougsg38p 06-01-2009 01:02 PM

The BlackBerry API's are built on Java ME, not Java SE. You definitely need to refer to the BlackBerry API docs as you develop the program.


All times are GMT -5. The time now is 06:12 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.