Results 1 to 8 of 8
  1. #1
    Ya2
    Ya2 is offline Member
    Join Date
    Jun 2011
    Posts
    8
    Rep Power
    0

    Default Get Request Problem In Android

    I use Eclipse and when I try to connect to my servlet using 'normal' Java, it works fine.

    But when I paste the same code in my Android project, I get an empty String as a response.

    Why ?

    Code: (BASE_URL = url before (including) the '?' , inputURL is the rest of the URL)

    private static String accessURL(String inputURL) throws IOException{
    String inputLine = "";
    try {
    URL oracle = new URL(BASE_URL + inputURL);
    URLConnection yc = oracle.openConnection();
    BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
    inputLine = in.readLine();
    in.close();
    } catch (MalformedURLException e) {
    e.printStackTrace();
    } finally{
    return inputLine;
    }
    }

    And calling the function:

    accessURL("type=1");

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    What says the logcat ? Do you get an exception? Granted the right uses-permission in the AndroidManifest? <uses-permission> | Android Developers

  3. #3
    Ya2
    Ya2 is offline Member
    Join Date
    Jun 2011
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by eRaaaa View Post
    What says the logcat ? Do you get an exception? Granted the right uses-permission in the AndroidManifest? <uses-permission> | Android Developers
    logcat = console window ? No error there,

    No exception.

    When I debug the servlet, it acts as if ... no one is accessing it, therefore the problem is totally in Android..

    I pasted - <uses-permission android:name="string" /> - in my AndroidManifest, nothing changes..

    How do I set permission to the web , and use the returned String ?

  4. #4
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    Quote Originally Posted by Ya2 View Post
    logcat = console window ? No error there,

    No exception.
    No -> logcat | Android Developers (in eclipse ddms perspective)

    I pasted - <uses-permission android:name="string" /> - in my AndroidManifest, nothing changes..
    - no you have to replace "string" with the right permission :D --> <uses-permission android:name="android.permission.INTERNET"></uses-permission>

  5. #5
    Ya2
    Ya2 is offline Member
    Join Date
    Jun 2011
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by eRaaaa View Post
    No -> logcat | Android Developers (in eclipse ddms perspective)



    - no you have to replace "string" with the right permission :D --> <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    Thanks for your answer,.. but

    I did add the permission.INTERNET:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="comm.androidmonopoly"
    android:versionCode="1"
    android:versionName="1.0">
    <uses-sdk android:minSdkVersion="12" />

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

    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".AndroidMonopolyActivity"
    android:label="@string/app_name">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
    </application>
    </manifest>

    And used this code: (And it throws an exception at line ** )
    private static String accessURL(String inputURL) throws IOException{

    String inputLine = "";
    try {
    URL oracle = new URL(BASE_URL + inputURL);
    URLConnection yc = oracle.openConnection();
    BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); **
    inputLine = in.readLine();
    in.close();
    } catch (MalformedURLException e) {
    e.printStackTrace();
    } finally{
    return inputLine;
    }
    }

  6. #6
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    And used this code: (And it throws an exception at line ** )
    and which exception.....??

  7. #7
    Ya2
    Ya2 is offline Member
    Join Date
    Jun 2011
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by eRaaaa View Post
    and which exception.....??
    URL oracle = new URL(BASE_URL + inputURL);
    URLConnection yc = oracle.openConnection();
    InputStream iS = yc.getInputStream(); <--- Here it throws the exception
    InputStreamReader iSR = new InputStreamReader(iS);
    BufferedReader in = new BufferedReader(iSR);
    inputLine = in.readLine();

  8. #8
    Ya2
    Ya2 is offline Member
    Join Date
    Jun 2011
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by eRaaaa View Post
    and which exception.....??
    I'm sorry, I just setup the LogCat,..
    When I debugged my program, LogCat didn't show any exception, even when I tried to use a function which throws me to the Catch{} ..

    So I can't even be sure it's an exception.. ?

Similar Threads

  1. Replies: 0
    Last Post: 07-06-2011, 01:12 PM
  2. Android Help
    By fresh83 in forum Android
    Replies: 1
    Last Post: 05-19-2011, 08:44 PM
  3. Replies: 1
    Last Post: 05-10-2011, 08:10 AM
  4. Replies: 2
    Last Post: 02-27-2011, 10:50 AM
  5. android sdk
    By aizen92 in forum Android
    Replies: 2
    Last Post: 02-21-2011, 10:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •