Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work on Android 2.2 #8

Closed
GoogleCodeExporter opened this issue Mar 12, 2015 · 8 comments
Closed

Does not work on Android 2.2 #8

GoogleCodeExporter opened this issue Mar 12, 2015 · 8 comments

Comments

@GoogleCodeExporter
Copy link

CookieManager is only available from Gingerbread. See pre 2.3 devices throw 
exceptions:

09-21 17:46:51.916: E/AndroidRuntime(3439): Caused by: 
java.lang.NoClassDefFoundError: java.net.CookieManager
09-21 17:46:51.916: E/AndroidRuntime(3439):     at 
com.turbomanage.httpclient.AbstractHttpClient.ensureCookieManager(AbstractHttpCl
ient.java:437)
09-21 17:46:51.916: E/AndroidRuntime(3439):     at 
com.turbomanage.httpclient.AbstractHttpClient.<clinit>(AbstractHttpClient.java:2
7)

Is it possible to workaround it?

Original issue reported on code.google.com by versluyssander on 21 Sep 2012 at 3:56

@GoogleCodeExporter
Copy link
Author

I think you could wrap ensureCookieManager() with a runtime check for API level 
and @Suppress the compiler warning. Patch welcome.

Original comment by turboman...@gmail.com on 21 Sep 2012 at 5:56

  • Changed state: Duplicate
  • Added labels: Priority-Low
  • Removed labels: Priority-Medium

@GoogleCodeExporter
Copy link
Author

Patch with API level check.

Original comment by versluyssander on 12 Nov 2012 at 2:43

Attachments:

@GoogleCodeExporter
Copy link
Author

Thanks, @versluyssander. I modified it to wrap the call to 
ensureCookieManager() in order to make it more clear that there is no 
CookieManager for API<9. Also made note on issue 7 since this was the dup.

Original comment by turboman...@gmail.com on 12 Nov 2012 at 11:22

@GoogleCodeExporter
Copy link
Author

Please release a version with this patch

Original comment by shagan.g...@gmail.com on 26 Jan 2013 at 9:53

@GoogleCodeExporter
Copy link
Author

I moved the fix into AnroidHttpClient as a result of issue 12. It's available 
in basic-http-client-android-0.88.jar in the Downloads section.

Original comment by turboman...@gmail.com on 27 Jan 2013 at 10:19

@GoogleCodeExporter
Copy link
Author

 i use the basic-http-client-android-0.88.jar version, and with android 2.2 work (the output is ok) even if I get the warning
( Could not find method 
com.turbomanage.httpclient.android.AndroidHttpClient.ensureCookieManager, 
referenced from method com.turbomanage.httpclient.android.AndroidHttpClient. 
VFY: unable to resolve static method 3169: 
Lcom/turbomanage/httpclient/android/AndroidHttpClient;.ensureCookieManager 
()V), but with android 2.3+ i have this error:

03-23 11:31:59.344: E/AndroidRuntime(780): FATAL EXCEPTION: main
03-23 11:31:59.344: E/AndroidRuntime(780): java.lang.ExceptionInInitializerError
03-23 11:31:59.344: E/AndroidRuntime(780): at 
com.example.helloworld.MainActivity.onCreate(MainActivity.java:32)
03-23 11:31:59.344: E/AndroidRuntime(780): at 
android.app.Activity.performCreate(Activity.java:5104)
03-23 11:31:59.344: E/AndroidRuntime(780): at 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-23 11:31:59.344: E/AndroidRuntime(780): at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-23 11:31:59.344: E/AndroidRuntime(780): at 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-23 11:31:59.344: E/AndroidRuntime(780): at 
android.app.ActivityThread.access$600(ActivityThread.java:141)
03-23 11:31:59.344: E/AndroidRuntime(780): at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-23 11:31:59.344: E/AndroidRuntime(780): at 
android.os.Handler.dispatchMessage(Handler.java:99)
03-23 11:31:59.344: E/AndroidRuntime(780): at 
android.os.Looper.loop(Looper.java:137)
03-23 11:31:59.344: E/AndroidRuntime(780): at 
android.app.ActivityThread.main(ActivityThread.java:5041)
03-23 11:31:59.344: E/AndroidRuntime(780): at 
java.lang.reflect.Method.invokeNative(Native Method)
03-23 11:31:59.344: E/AndroidRuntime(780): at 
java.lang.reflect.Method.invoke(Method.java:511)
03-23 11:31:59.344: E/AndroidRuntime(780): at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-23 11:31:59.344: E/AndroidRuntime(780): at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-23 11:31:59.344: E/AndroidRuntime(780): at 
dalvik.system.NativeStart.main(Native Method)
03-23 11:31:59.344: E/AndroidRuntime(780): Caused by: 
java.lang.NoSuchMethodError: 
com.turbomanage.httpclient.android.AndroidHttpClient.ensureCookieManager
03-23 11:31:59.344: E/AndroidRuntime(780): at 
com.turbomanage.httpclient.android.AndroidHttpClient.(AndroidHttpClient.java:49)
03-23 11:31:59.344: E/AndroidRuntime(780): … 15 more

java.lang.NoSuchMethodError and not class not found.
AndroidHttpClient.java:49
static {
disableConnectionReuseIfNecessary();
// See http://code.google.com/p/basic-http-client/issues/detail?id=8
if (Build.VERSION.SDK_INT > 8)
ensureCookieManager();
}

I do not understand, it would find the method ensureCookieManager() in 
com.turbomanage.httpclient.android.AndroidHttpClient class?
tnk

Original comment by salvator...@gmail.com on 23 Mar 2013 at 4:23

@GoogleCodeExporter
Copy link
Author

I can't reproduce this. Are you using ProGuard?

Original comment by turboman...@gmail.com on 23 Mar 2013 at 4:46

@GoogleCodeExporter
Copy link
Author

package com.example.helloworld;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

import com.turbomanage.httpclient.AsyncCallback;
import com.turbomanage.httpclient.HttpResponse;
import com.turbomanage.httpclient.ParameterMap;
import com.turbomanage.httpclient.android.AndroidHttpClient;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AndroidHttpClient httpClient = new AndroidHttpClient("http://10.0.2.2/cmp");
        httpClient.setMaxRetries(5);
        ParameterMap params = null;
        httpClient.get("/states", params, new AsyncCallback() {
            @Override
            public void onComplete(HttpResponse httpResponse) {
                System.out.println(httpResponse.getBodyAsString());
            }
            @Override
            public void onError(Exception e) {
                e.printStackTrace();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

i'm newbie with android prog., i tried to use a simple helloworld with your 
httpclient

androidmanifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.helloworld"
    android:versionCode="1"
    android:versionName="1.0" android:installLocation="preferExternal">

    <uses-sdk 
        android:minSdkVersion="8" 
        android:targetSdkVersion="21" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:allowBackup="true"
        android:theme="@style/AppTheme" android:allowClearUserData="true">
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

project.properties:

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this 
(available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project
.txt

# Project target.
target=android-17

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />

</RelativeLayout>

avd android 4.2.2 or 4.1  

Original comment by salvator...@gmail.com on 23 Mar 2013 at 6:54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant