|
getLineStyle NullPointerException |
Jellybean
|
Post subject: getLineStyle NullPointerException |
Post rating: 0
|
Posted: Mon 02 Mar, 2015, 01:47
|
|
User rating: 0
Joined: Fri 10 Oct, 2014, 00:35 Posts: 58 Location: New Zealand, Auckland
|
Hi
I am trying to get the line style of ChartObjects. If I have not set the stroke manually, I get a null pointer exception. However, after I set the stroke, my code works fine.
I attach a sample strategy that exhibits the problem. Simply draw a rectangle; do not change any settings; run the strategy. Gives NullPointerException. Next, change the stroke; run the strategy. Gives no error.
What am I doing wrong or is this a bug?
Cheers Tony
Attachments: |
File comment: Exhibits NullPointerException
LineStyleTest.java [1.55 KiB]
Downloaded 402 times
|
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on
this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control
on their content. Anyone accessing this webpage and downloading or otherwise making use of any document,
data or information found on this webpage shall do it on his/her own risks without any recourse against
Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from
the use and/or reliance on any document, data or information found on this webpage.
|
|
|
|
|
 |
nicejack
|
Post subject: Re: getLineStyle NullPointerException |
Post rating: 0
|
Posted: Mon 02 Mar, 2015, 12:01
|
|
User rating: 2
Joined: Wed 03 Sep, 2014, 09:11 Posts: 32 Location: GermanyGermany
|
Hi JellyBean, there is a bug in yout code: private void printDebug(String toPrint) { if (printDebug) { console.getOut().println( toPrint ); } }
please remove the free space in line: console.getOut().println( toPrint ); private void printDebug(String toPrint) { if (printDebug) { console.getOut().println(toPrint); } }

|
|
|
|
 |
nicejack
|
Post subject: Re: getLineStyle NullPointerException |
Post rating: 0
|
Posted: Mon 02 Mar, 2015, 12:15
|
|
User rating: 2
Joined: Wed 03 Sep, 2014, 09:11 Posts: 32 Location: GermanyGermany
|
sorry that was not the reason!
it seems that the line style is indeterminate if you never set the stroke.
maybe a bug!?
|
|
|
|
 |
nicejack
|
Post subject: Re: getLineStyle NullPointerException |
Post rating: 0
|
Posted: Mon 02 Mar, 2015, 12:26
|
|
User rating: 2
Joined: Wed 03 Sep, 2014, 09:11 Posts: 32 Location: GermanyGermany
|
try this... // get active chart IChart chart = context.getLastActiveChart(); List<IChartObject> objects = chart.getAll(); for (IChartObject obj : objects) { if (obj.getType() == IChart.Type.RECTANGLE) { try { obj.getLineStyle(); } catch (NullPointerException e) { printDebug("unknow linestyle -> set to 0"); obj.setLineStyle(0); } printDebug("Rectangle linestyle is " + obj.getLineStyle()); } }
|
|
|
|
 |
API Support
|
Post subject: Re: getLineStyle NullPointerException |
Post rating: 0
|
Posted: Mon 02 Mar, 2015, 14:40
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
There was a bug that will be fixed with the next demo release.
|
|
|
|
 |
Jellybean
|
Post subject: Re: getLineStyle NullPointerException |
Post rating: 0
|
Posted: Mon 02 Mar, 2015, 20:36
|
|
User rating: 0
Joined: Fri 10 Oct, 2014, 00:35 Posts: 58 Location: New Zealand, Auckland
|
nicejack wrote: try this... // get active chart IChart chart = context.getLastActiveChart(); List<IChartObject> objects = chart.getAll(); for (IChartObject obj : objects) { if (obj.getType() == IChart.Type.RECTANGLE) { try { obj.getLineStyle(); } catch (NullPointerException e) { printDebug("unknow linestyle -> set to 0"); obj.setLineStyle(0); } printDebug("Rectangle linestyle is " + obj.getLineStyle()); } }
Thanks Jack. This works and I'm using it to proceed. Cheers Tony
|
|
|
|
 |
Jellybean
|
Post subject: Re: getLineStyle NullPointerException |
Post rating: 0
|
Posted: Mon 02 Mar, 2015, 20:41
|
|
User rating: 0
Joined: Fri 10 Oct, 2014, 00:35 Posts: 58 Location: New Zealand, Auckland
|
API Support wrote: There was a bug that will be fixed with the next demo release. Thank you. Cheers Tony
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|