6

I have a string. i.e.

String urlString = "http://m.nasdaq.com/symbol/"+stock_symbol.getText();

I need to keep it a string because I'm asking the user for the stock symbol then performing the search. I then need to parse the information that is in the html code. So I need to convert my urlString into an URL. I looked on the android developer and saw this:

URL(String spec) 
  Creates a URL object from the String representation.

but this isn't working. Need help I also need help parsing the actual html. You don't need to give me everything, just a very short example would be great.

William He
  • 63
  • 1
  • 1
  • 3
  • 2
    `but this isn't working` Why? Please, show us a complete example that demonstrate the issue, and tell us what doesn't work, why, what is the expected behaviour and what's happening instead. If there is any error, post the full stack trace in the question. – BackSlash Dec 06 '16 at 20:29

2 Answers2

13

URL is a class. Simply use new to create a new instance of the class and pass the string as a parameter to the constructor.

String urlString = "http://m.nasdaq.com/symbol/"+stock_symbol.getText();
URL myURL = new URL(urlString);
NineBerry
  • 26,306
  • 3
  • 62
  • 93
1

you most create a new Url and input your string in C URL url=new URL(urlString);

Shahbazi
  • 11
  • 2