.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
.
Last edited by jt183; October 5th, 2014 at 10:36 PM.
Can you add a call to the printStackTrace() method in the catch block for more info?
If you don't understand my answer, don't ignore it, ask a question.
Hi. I did and got this (I used aapl as the ticker) :
java.net.MalformedURLException: no protocol: aapl at java.net.URL.<init>(URL.java:586) at java.net.URL.<init>(URL.java:483) at java.net.URL.<init>(URL.java:432) at financecalc.Finance.getStock(Finance.java:25) at financecalc.Window$1.actionPerformed(Window.java:57) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6525) at javax.swing.JComponent.processMouseEvent(JComponent.java:3321) at java.awt.Component.processEvent(Component.java:6290) at java.awt.Container.processEvent(Container.java:2234) at java.awt.Component.dispatchEventImpl(Component.java:4881) at java.awt.Container.dispatchEventImpl(Container.java:2292) at java.awt.Component.dispatchEvent(Component.java:4703) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462) at java.awt.Container.dispatchEventImpl(Container.java:2278) at java.awt.Window.dispatchEventImpl(Window.java:2739) at java.awt.Component.dispatchEvent(Component.java:4703) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746) at java.awt.EventQueue.access$400(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:697) at java.awt.EventQueue$3.run(EventQueue.java:691) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86) at java.awt.EventQueue$4.run(EventQueue.java:719) at java.awt.EventQueue$4.run(EventQueue.java:717) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.awt.EventQueue.dispatchEvent(EventQueue.java:716) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
I'm reading more about the no protocol error and it seems to be something with my URL. Thank you for your reply
Is this the same as what is being executed?
That URL does not have a valid protocol.URL url = new URL("aapl");
You said: The URL I am using is ...MalformedURLException: no protocol: aapl
and posted what looks like a valid URL.
Please explain.
If you don't understand my answer, don't ignore it, ask a question.
To use "aapl" as an example, the URL I am passing into my method (which I should have included in the original post, my apologies) is:
public static String getURL(String ticker) { URL url = new URL("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22" + ticker + "%22)&env=store://datatables.org/alltableswithkeys")
where ticker (the String being passed in) is aapl so the complete URL being passed as a parameter would be:
URL url = new URL("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22aapl%22)&env=store://datatables.org/alltableswithkeys")
I can see the confusion. I named the parameter and the String both as ticker, but they are not the same. I have since changed the name of the parameter to something else.
What happens when you use that code instead what I posted in post#4?
The error message says something like the code in post#4 was used. Not the URL you are showing in post#5
If you don't understand my answer, don't ignore it, ask a question.
Argh, I see what you mean now. I edited it and used the code in post #4:
URL url = new URL("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22" + yApi+ "%22)&env=store://datatables.org/alltableswithkeys")
and changed the parameter name to "yApi" avoid confusion. Now when I call the method using getStock(ticker) , I no longer get the error message. And it works! Thank you very much for your help, I appreciate it. I don't know why I was trying to pass that entire URL as a parameter when I could just assign it to URL url ... and pass only the actual ticker as a parameter (aapl for ex.).
edit: I actually had to revert back to 'ticker' as the parameter name but still works
Last edited by jt183; October 5th, 2014 at 08:45 PM.