-1

I am new to android, i am trying to solve a runtimeException error, why is this happening? wat is wrong? this is the doInBackgroundLogin method

 public void doInBackgroundLogin()
{   
                String link = "http://www.quinoid.com/project/AndroidXml/Login.php?username="
                               + txtUserName.getText().toString() + "&password=" + txtPassword.getText().toString();
                try {                       
                        JSONObject json = jParser.getJSONFromUrl(link);                             
                } 
                catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                Intent myIntent = new Intent(MainActivity.this, secondpage.class);
                startActivity(myIntent);
}

This is the json parser method

 public JSONObject getJSONFromUrl(String url) throws JSONException {
 try 
 {
 DefaultHttpClient httpClient = new DefaultHttpClient();
 HttpPost httpPost = new HttpPost(url);//error occurs here
 HttpResponse httpResponse = httpClient.execute(httpPost);
 HttpEntity httpEntity = httpResponse.getEntity();
 is = httpEntity.getContent();          
 }

this isthe stack trace

02-11 05:20:40.077: E/AndroidRuntime(1754): FATAL EXCEPTION: AsyncTask #2
02-11 05:20:40.077: E/AndroidRuntime(1754): Process: com.example.qwedd, PID: 1754
02-11 05:20:40.077: E/AndroidRuntime(1754): java.lang.RuntimeException: An error occured while executing doInBackground()
02-11 05:20:40.077: E/AndroidRuntime(1754):     at android.os.AsyncTask$3.done(AsyncTask.java:300)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at java.lang.Thread.run(Thread.java:841)
02-11 05:20:40.077: E/AndroidRuntime(1754): Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at java.net.InetAddress.getAllByName(InetAddress.java:214)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at com.example.connection.JSONParser.getJSONFromUrl(JSONParser.java:38)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at com.example.qwedd.MainActivity.doInBackgroundLogin(MainActivity.java:57)
02-11 05:20:40.077: E/AndroidRuntime(1754):     at com.example.qwedd.MainActivity$Connection.doInBackground(MainActivity.java:75)
Alvin
  • 416
  • 1
  • 8
  • 18
  • post the mnaifest have you added internet permission in manifest>? – Raghunandan Feb 11 '14 at 10:40
  • 1
    `SecurityException: Permission denied (missing INTERNET permission?` have you added INTERNET permission? – vokilam Feb 11 '14 at 10:40
  • 1
    add this permission `` into your `manifest.xml` – M D Feb 11 '14 at 10:40
  • Even the logcat is telling you what to fix. Have you at least bothered to read the error before posting here? – STT LCU Feb 11 '14 at 10:42
  • possible duplicate of [Granting Android application the android.permission.INTERNET permission while debugging on device](http://stackoverflow.com/questions/5279076/granting-android-application-the-android-permission-internet-permission-while-de) or this http://stackoverflow.com/questions/2169294/how-to-add-manifest-permission-to-android-application – Raghunandan Feb 11 '14 at 10:45
  • vokilam,M D,STT LCU, Raghunandan, Thanks all.. I didnt know.. i did say i was new to android... – Alvin Feb 11 '14 at 10:55

2 Answers2

1

Try this..

java.lang.SecurityException: Permission denied (missing INTERNET permission?)

add Permission in manifest..

<uses-permission android:name="android.permission.INTERNET" />

After </application> Or Before <application> and also check out this Doc

Hariharan
  • 24,741
  • 6
  • 50
  • 54
0

just add this permission into your manifest.xml file:

<uses-permission android:name="android.permission.INTERNET" />
M D
  • 47,665
  • 9
  • 93
  • 114