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
Developer
mnpaslay
Posts: 105
Registered: ‎03-09-2009
My Device: Not Specified

Why does this fail...

why does this fail?

 

RichTextField myTextField = new RichTextField("Hello").setBorder(myBorder);

 

when this is ok? 

 

RichTextField myTextField = new RichTextField("Hello");

myTextField.setBorder(myBorder);

 

also, this is ok as well...

String dateString = new SimpleDateFormat("MM yyyy").format(myDate);

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Why does this fail...

The code doesn't look OK to me. 

 

Can you repost using the "insert code" button? The smiley faces don't help when trying to identify your syntax issue.

 

 

 

 

Please use plain text.
Developer
mreed
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Why does this fail...

@Rex: you can disable the smiley faces under user preferences.
Please use plain text.
Developer
mnpaslay
Posts: 105
Registered: ‎03-09-2009
My Device: Not Specified

Re: Why does this fail...

Here you go...my guess is that the method (.setBorder)  is not part of the subclass (RichTextField) - it is part of the superclass, so it has to be created first?...or because it is a void method...actually, i think it is the void part...but you guys tell me...

 

 

//The below fails... RichTextField myTextField = new RichTextField("Hello").setBorder(myBorder);

 

//I also tried which fails

 

RichTextField myTextField = (new RichTextField("Hello")).setBorder(myBorder); //The below works fine RichTextField myTextField = new RichTextField("Hello"); myTextField.setBorder(myBorder); //The below also works fine...using a method, I do realize it is different then above example in that the method returns something...

String dateString = new SimpleDateFormat("MM yyyy".format(myDate);

 

Please use plain text.
Developer
acowart
Posts: 163
Registered: ‎07-16-2008
My Device: Not Specified
My Carrier: Sprint

Re: Why does this fail...

The problem is in your assignment. The first example attempts to set the variable myTextField equal to the result returned by setBorder - which is void.

 

The second example is how this should be programmed.

 

The third example will compile because it returns an object - but it's actually assigning the String object dateString to be the result of format(myDate) - which is a StringBuffer.

Andrew Cowart | Metova
www.metova.com
Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Why does this fail...

Can you post the actual compiler error?

 

I'm guessing it is some type of assignment incompatibility error?

 

 

Please use plain text.
Developer
mnpaslay
Posts: 105
Registered: ‎03-09-2009
My Device: Not Specified

Re: Why does this fail...

'void' type not allowed here is the compiler error..

 

i just surprized since putting it on the next line corrects it...

Please use plain text.
Developer
mreed
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Why does this fail...

[ Edited ]

setBorder() returns (or doesn't) void. So its basically like trying to do:

 

RichTextField richTextField = new RichTextField("Hello");

RichTextField myTextField = richTextField.setBorder(myBorder);

 

... which is invalid;

 

If you do the same with the last one, you will see why it works:

 

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM yyyy");

StringBuffer stringBuffer = simpleDateFormat.format(myDate);

String dateString = stringBuffer.toString();

 

Thats what trying to fit multiple calls on the same line is more confusing than splitting it up.

Message Edited by mreed on 04-20-2009 08:10 PM
Please use plain text.
New Developer
lborsato
Posts: 18
Registered: ‎08-27-2010
My Device: Torch
My Carrier: Rogers

Re: Why does this fail...

This is what I see when I try to use setBorder on a TextField:

 

 

C:\Program Files\Research In Motion\BlackBerry JDE 6.0.0\samples\com\alchemii\igotihav\ImageListManager.java:92: cannot find symbol
symbol  : method setBorder(int)
location: class net.rim.device.api.ui.component.TextField
            searchText.setBorder(Border.STYLE_SOLID);
                      ^
1 error
Error!: Error: java compiler failed: javac -source 1.3 -target 1.3 -g -O -d C:\DOCUME~1\LARRYB~1\LOCALS~1\Temp\rapc_4751bec0.dir -bootcl ...
Error while building project

 

C:\Program Files\Research In Motion\BlackBerry JDE 6.0.0\samples\com\alchemii\igotihav\ImageListManager.java:92: cannot find symbolsymbol  : method setBorder(int)location: class net.rim.device.api.ui.component.TextField            searchText.setBorder(Border.STYLE_SOLID);                      ^1 errorError!: Error: java compiler failed: javac -source 1.3 -target 1.3 -g -O -d C:\DOCUME~1\LARRYB~1\LOCALS~1\Temp\rapc_4751bec0.dir -bootcl ...Error while building project

 

My code looks like this:

 

 

           private TextField   searchText;

           searchText = new TextField();

            searchText.setLabel("Find: ");

            searchText.setBorder(Border.STYLE_SOLID);

 

Please use plain text.
Developer
acowart
Posts: 163
Registered: ‎07-16-2008
My Device: Not Specified
My Carrier: Sprint

Re: Why does this fail...

setBorder takes a Border object - you are passing in an int (Border.STYLE_SOLID). Use the BorderFactory class to make a Border object first.
Andrew Cowart | Metova
www.metova.com
Please use plain text.