Hi, I am throwing a request to get a token in OAuth VK :
JSONObject parsed_url = parseURL("https://oauth.vk.com/token" + "?grant_type=password" + "&client_id=*********" + "&client_secret=*********" + "&scope=status,messages" + "&username=" + login + "&password=" + password ); and if I enter the correct data (login and password) - it gives me a JSON object with which I work, and if I send non-valid data, then FileNotFoundExpection throws FileNotFoundExpection , I would like to know why and how to get rid of it, it does not allow me to send Toast with a message about incorrectly entered data.
Other codes:
public JSONObject parseURL(String url_string) throws IOException, JSONException{ enableStrictMode(); InputStream is = new URL(url_string).openStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); String jsonText = readAll(rd); JSONObject json = new JSONObject(jsonText); is.close(); return json; } View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View v) { int id = v.getId(); if (id == R.id.login_button) { if (validateData()) { try { login(); } catch (Exception e) { e.printStackTrace(); } } } } }; login_button.setOnClickListener(listener); }
Not a fan of libraries, so I do not use them.
All good, if something is not explained - forgive.
Mistake:
08-28 22:34:53.491 5615-5615/ru.steelskype.app W/System.err: java.io.FileNotFoundException: https://oauth.vk.com/token?grant_type=password&client_id=*****&client_secret=*****&scope=status,messages&username=ususjsjsj&password=hshshshshs 08-28 22:34:53.498 5615-5615/ru.steelskype.app W/System.err: at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:238) 08-28 22:34:53.498 5615-5615/ru.steelskype.app W/System.err: at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210) 08-28 22:34:53.498 5615-5615/ru.steelskype.app W/System.err: at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:25) 08-28 22:34:53.498 5615-5615/ru.steelskype.app W/System.err: at java.net.URL.openStream(URL.java:470) 08-28 22:34:53.498 5615-5615/ru.steelskype.app W/System.err: at ru.steelskype.app.LoginActivity.parseURL(LoginActivity.java:100) 08-28 22:34:53.498 5615-5615/ru.steelskype.app W/System.err: at ru.steelskype.app.LoginActivity.login(LoginActivity.java:80) 08-28 22:34:53.498 5615-5615/ru.steelskype.app W/System.err: at ru.steelskype.app.LoginActivity$1.onClick(LoginActivity.java:40) 08-28 22:34:53.498 5615-5615/ru.steelskype.app W/System.err: at android.view.View.performClick(View.java:5207) 08-28 22:34:53.498 5615-5615/ru.steelskype.app W/System.err: at android.view.View$PerformClick.run(View.java:21177) 08-28 22:34:53.498 5615-5615/ru.steelskype.app W/System.err: at android.os.Handler.handleCallback(Handler.java:739) 08-28 22:34:53.498 5615-5615/ru.steelskype.app W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95) 08-28 22:34:53.498 5615-5615/ru.steelskype.app W/System.err: at android.os.Looper.loop(Looper.java:148) 08-28 22:34:53.498 5615-5615/ru.steelskype.app W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5441) 08-28 22:34:53.498 5615-5615/ru.steelskype.app W/System.err: at java.lang.reflect.Method.invoke(Native Method) 08-28 22:34:53.498 5615-5615/ru.steelskype.app W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738) 08-28 22:34:53.498 5615-5615/ru.steelskype.app W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)