[送信] ボタンをクリックするたびに、「残念ながら、アプリケーションは動作を停止しました」というエラーが表示されます。助けてください。
コード-
public void onClick(View v) {
TextView t = (TextView) findViewById(R.id.textView4);
if(from == to)
{
Toast.makeText(getApplicationContext(), "Invalid", 4000).show();
}
else
{
try {
s = getJson("URL");
JSONObject jObj;
jObj = new JSONObject(s);
String exResult = jObj.getJSONObject("query").getJSONObject("results").getJSONObject("rate").getString("Rate");
t.setText(exResult);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
}
LogCat -
03-15 12:06:17.508: E/AndroidRuntime(877): 致命的な例外: メイン 03-15 12:06:17.508: E/AndroidRuntime(877): android.os.NetworkOnMainThreadException 03-15 12:06:17.508: E/AndroidRuntime(877): android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117) 03-15 12:06:17.508: E/AndroidRuntime(877): java.net.InetAddress.lookupHostByName(InetAddress) .java:385) 03-15 12:06:17.508: E/AndroidRuntime(877): java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) 03-15 12:06:17.508: E/AndroidRuntime(877) ): java.net.InetAddress.getAllByName(InetAddress.java:214) 03-15 12:06:17.508: E/AndroidRuntime(877): org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator. java:137) 03-15 12:06:17.508: E/AndroidRuntime(877): org.apache.http.impl.conn.AbstractPoolEntry で。開く (AbstractPoolEntry.java:164) 03-15 12:06:17.508: E/AndroidRuntime (877): org.apache.http.impl.conn.AbstractPooledConnAdapter.open (AbstractPooledConnAdapter.java:119) 03-15 12: 06:17.508: E/AndroidRuntime(877): org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) 03-15 12:06:17.508: E/AndroidRuntime(877): org .apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 03-15 12:06:17.508: E/AndroidRuntime(877): org.apache.http.impl.client.AbstractHttpClient.execute( AbstractHttpClient.java:487) 03-15 12:06:17.508: E/AndroidRuntime(877): org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 03-15 12:06: 17.508: E/AndroidRuntime(877): myandroid.myfirstmodule.sconverter.getJson(sconverter.java:163) 03-15 12:06:17.508: E/AndroidRuntime(877):myandroid.myfirstmodule.sconverter$1.onClick(sconverter.java:96) 03-15 12:06:17.508: E/AndroidRuntime(877): android.view.View.performClick(View.java:4084) 03-15 12:06:17.508: E/AndroidRuntime(877): android.view.View$PerformClick.run(View.java:16966) 03-15 12:06:17.508: E/AndroidRuntime(877): android.os で.Handler.handleCallback(Handler.java:615) 03-15 12:06:17.508: E/AndroidRuntime(877): android.os.Handler.dispatchMessage(Handler.java:92) 03-15 12:06:17.508 : E/AndroidRuntime(877): android.os.Looper.loop(Looper.java:137) 03-15 12:06:17.508: E/AndroidRuntime(877): android.app.ActivityThread.main(ActivityThread. java:4745) 03-15 12:06:17.508: E/AndroidRuntime(877): java.lang.reflect.Method.invokeNative(ネイティブ メソッド) 03-15 12:06:17.508: E/AndroidRuntime(877): java.lang.reflect.Method.invoke(Method.java:511) 03-15 12:06:17.508: E/AndroidRuntime(877): com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 03-15 12:06:17.508: E/AndroidRuntime(877): com .android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 03-15 12:06:17.508: E/AndroidRuntime(877): dalvik.system.NativeStart.main(ネイティブ メソッド) で