yo update: im getting this error: (pls dont judge bro im new to integrating apis in java) Exception in thread "main" org.json.JSONException: JSONObject["rates"] not found. at org.json.JSONObject.get(JSONObject.java:570) at org.json.JSONObject.getJSONObject(JSONObject.java:780) at bsitCurrencyConverter.CurrencyConverter.main(CurrencyConverter.java:40)
Don't worry 😅 it looks like jsonObject created from response doesn't contain rates object. You can check how jsonObject looks like through System.out.println(). If it looks non standard maybe returned response from external API is not proper.
From the description I assume that you have 2 modules in the project with the same package name. Modules identify classes inside src directory. In this case they don't know which package class is reffered to. Try to rename package.
In the line: JSONObject jsonObject = new JSONObject(stringResponse); you finally get json object. If you want to generate json file you could try this: FileWriter fileWriter = new FileWriter("D:/fileName.json"); //use your custom path fileWriter.write(jsonObject.toJSONString()); fileWriter.close();
It looks like jsonObject created from response doesn't contain rates object. You can check how jsonObject looks like through System.out.println(). If it looks non standard maybe returned response from external API is not proper.
I see that API has changed since I created this program. I think you need to get free API token to make a request. Also json response structure looks different. Please see exchangerate.host/documentation.
@@codeedge Hello, I just subscribed and I like this video. Please can you provide the correct JSON structure? (How we'll add the code or can you update the code on your github?)
this is by far the most legit java currency converter in terms of using api tutorial ive seen on youtube, thnx my guy mad underrated +1
yo update: im getting this error: (pls dont judge bro im new to integrating apis in java)
Exception in thread "main" org.json.JSONException: JSONObject["rates"] not found.
at org.json.JSONObject.get(JSONObject.java:570)
at org.json.JSONObject.getJSONObject(JSONObject.java:780)
at bsitCurrencyConverter.CurrencyConverter.main(CurrencyConverter.java:40)
Don't worry 😅 it looks like jsonObject created from response doesn't contain rates object. You can check how jsonObject looks like through System.out.println(). If it looks non standard maybe returned response from external API is not proper.
Thanks so much, please do a few more!
Thanks, I will make more videos like this.
excellent!! Very helpful 👍
Thanks, I'm glad!
I think they changed the key words in the API... to quotes and source... in query string
Thanks, probably yes. I will add a comment to description that API could be changed.
When I create the class I get an error saying that the package come is already in another module
From the description I assume that you have 2 modules in the project with the same package name. Modules identify classes inside src directory. In this case they don't know which package class is reffered to. Try to rename package.
Which framework dod you use??
I just used 2 libraries: OkHttp and Json. Links in the description.
On which platform you wrote this code
If you are asking about which IDE I used, it was Intellij IDEA.
How to get Object.json file
In the line:
JSONObject jsonObject = new JSONObject(stringResponse);
you finally get json object. If you want to generate json file you could try this:
FileWriter fileWriter = new FileWriter("D:/fileName.json"); //use your custom path
fileWriter.write(jsonObject.toJSONString());
fileWriter.close();
Are you from Poland? You sound like you are from Poland ;)
Tak jest, pozdrawiam :) It's hard to avoid Polish accent.
Can I get source code pls
I added source code in the video description.
I did everything as you did
But it shows:
Exception in the thread "main" org.json.JSONExecption:JSONObject["rates"] not found.
It looks like jsonObject created from response doesn't contain rates object. You can check how jsonObject looks like through System.out.println(). If it looks non standard maybe returned response from external API is not proper.
@@codeedge I can't use the api ,which you used
I see that API has changed since I created this program. I think you need to get free API token to make a request. Also json response structure looks different. Please see exchangerate.host/documentation.
@@codeedge Hello, I just subscribed and I like this video. Please can you provide the correct JSON structure? (How we'll add the code or can you update the code on your github?)
I will try to find some time to upgrade the github repo. I will let you know when it's ready.