43

I am creating an application that will post a link onto Twitter. The following code refuses to package up for me, throwing the following error:

Error: Cannot run program "jar": CreateProcess error=2, The system cannot find the file specified

Here is the code:

public class ShowAuthBrowser extends MainScreen implements OAuthDialogListener
{
    private final String CONSUMER_KEY = "<Consumer>";   
    private final String CONSUMER_SECRET = "<Secret>";
    private LabelField _labelStutus;
    private OAuthDialogWrapper pageWrapper = null;
    public StoreToken _tokenValue;
    public BrowserField b = new BrowserField();
    Manager _authManager;
    Manager _pinManager;
    ButtonField authButton;
    TextField authPin;

    public ShowAuthBrowser()    
    {   
        _authManager = new VerticalFieldManager(NO_VERTICAL_SCROLL |
                                                NO_VERTICAL_SCROLLBAR);
        _pinManager = new HorizontalFieldManager(NO_VERTICAL_SCROLL |
                                                 NO_VERTICAL_SCROLLBAR);
        authButton = new ButtonField("OK");
        authPin = new TextField(Field.EDITABLE);
        _authManager.add(_labelStutus );
        _authManager.add(b);

        _pinManager.add(authButton);
        _pinManager.add(authPin);


        pageWrapper = new BrowserFieldOAuthDialogWrapper(b,CONSUMER_KEY,
                            CONSUMER_SECRET,null,this);
        pageWrapper.setOAuthListener(this);     

        add(_pinManager);
        add(_authManager);

        authButton.setChangeListener( new FieldChangeListener( ) {
            public void fieldChanged( Field field, int context ) {
                if( field == authButton ) {
                       doAuth(authPin.getText());
                }
            }
        } );

    }

    public void doAuth( String pin )
    {
        try
        {
            if ( pin == null )
            {
                pageWrapper.login();
            }
            else
            {
                this.deleteAll();
                add(b);
                pageWrapper.login( pin );
            } 

        }
        catch ( Exception e )
        {
            final String message = "Error logging into Twitter: " + 
                                                e.getMessage();
            Dialog.alert( message );
        }           
    }

    public void onAccessDenied(String response ) {

        updateScreenLog( "Access denied! -> " + response );

    }

    public void onAuthorize(final Token token) {

        final Token myToken = token;
        _tokenValue = StoreToken.fetch();
        _tokenValue.token = myToken.getToken();
        _tokenValue.secret = myToken.getSecret();
        _tokenValue.userId = myToken.getUserId();
        _tokenValue.username = myToken.getUsername();
        _tokenValue.save();

        UiApplication.getUiApplication().invokeLater( new Runnable() {

            public void run() {
                deleteAll();
                Credential c = new Credential(CONSUMER_KEY, 
                                              CONSUMER_SECRET, 
                                              myToken);
                PostTweet tw = new PostTweet();
                String message="Testing BB App";
                boolean done=false;
                done=tw.doTweet(message, c);
                if(done == true)
                {
                    Dialog.alert( "Tweet succusfully..." );
                    close();    
                }
            }
        });

    }

    public void onFail(String arg0, String arg1) {
        updateScreenLog("Error authenticating user! -> " + arg0 + ", " + arg1);
    }

    private void updateScreenLog( final String message )
    {
        UiApplication.getUiApplication().invokeLater( new Runnable() {

            public void run() {
                _labelStutus.setText( message );                
            }
        });
    }
}

The odd thing is, if I remove the following lines, it packages just fine:

authButton.setChangeListener( new FieldChangeListener( ) {
        public void fieldChanged( Field field, int context ) {
            if( field == authButton ) {
                   doAuth(authPin.getText());
            }
        }
    } );

Any help would be appreciated as I really need the field listener attached to this screen.

With code like authButton.setChangeListener(null), it does package successfully however I do need code with FieldChangeListener to do something.

Rajesh Rajaram
  • 3,211
  • 4
  • 26
  • 48
Scott Boettger
  • 3,607
  • 2
  • 30
  • 43
  • try packaging with code like `authButton.setChangeListener(null)` - just to make sure that it's not the reference to FieldChangeListener that is causing trouble – gnat May 11 '12 at 15:31
  • That does package successfully however I do need it to do something. – Scott Boettger May 11 '12 at 15:34
  • check your build settings; from what you describe it rather looks like at the packaging stage, jar utility can not find jar file or directory containing `FieldChangeListener.class` file. Especially check if you package against proper version of Blackberry API – gnat May 11 '12 at 15:36
  • 4
    I have field change listeners elsewhere in other classes and they build and package fine. – Scott Boettger May 11 '12 at 15:43
  • 1
    there have been couple similar questions asked in the past: http://stackoverflow.com/questions/7804602/import-existing-blackberry-project-in-eclipse and http://stackoverflow.com/questions/7291442/error-cannot-run-program-jar-createprocess-error-2-the-system-cannot-find-t - all mentioning _Cannot run program "jar": CreateProcess error=2_ – gnat May 11 '12 at 16:15
  • 2
    I have already looked at both of those, but thanks. Is there a size max for a Blackberry project? – Scott Boettger May 11 '12 at 16:41
  • 1
    @ScottBoettger, I think there is. The toolchain tries to break it up in several COD files and I have had problems which went away when I made the program smaller. – Prof. Falken Nov 15 '12 at 13:45

1 Answers1

2

Make sure your java bin path is set in environment variable.

http://docs.oracle.com/javase/tutorial/essential/environment/paths.html

and take a look at the last 3 posts in the following website:

http://supportforums.blackberry.com/t5/Java-Development/I-O-Error-Cannot-run-program-quot-jar-quot-CreateProcess-error-2/td-p/522638

Also make sure The Java® software development kit (Java SDK/JDK) is installed on the computer, and a correct version of the Java SDK is used.

http://supportforums.blackberry.com/t5/Java-Development/I-O-Error-CreateProcess/ta-p/445949

As mentioned in Scott Boettger comment below, this post could be helpful as well: http://supportforums.blackberry.com/t5/Java-Development/why-cause-more-then-100-compiled-classes-packaging-I-O-error/m-p/520282

Mehdi Karamosly
  • 4,996
  • 1
  • 25
  • 46
  • 3
    I definitely have the SDK installed. But your on post lead me to this post: http://supportforums.blackberry.com/t5/Java-Development/why-cause-more-then-100-compiled-classes-packaging-I-O-error/m-p/520282. I do have a fairly large project with lots of compiled classes. – Scott Boettger Dec 13 '12 at 12:56