Android :: Every Second HttpsUrlConnection Request Of My Static Method Fails

Nov 24, 2010

I'm having a big issue with a static HTTPS connection method. Every second request fails and HttpsUrlConnection.getResponseCode() returns -1. So every second call works well, returning data as expected.

It's the method of a static class I'm using in different corners of my application. I would guess there is anything I don't clean up correctly when the method returns the first time and that whatever causes a problem might get destroyed through a second call of the method. But I'm having a hard time finding any clues.

I'm currently using this class to talk to hosts with invalid SSL certificates. Not going to use this in the final version of the app, but right now I need to save money. ;)

CODE:.......................

Android :: Every second HttpsUrlConnection request of my static method fails


Android :: HttpsURLConnection Returns -1 Code On Second Request

May 15, 2010

I'm experiencing the same as http://groups.google.com/group/android-developers/msg/9d37d64aad0ee357

This is Android 1.5 SDK. I happen to call several times below code(which is in a method) with the same url and it fails intermitently. When it fails, there is no exception, the stream is empty so the readConnection fails, and getResponseCode returns -1. Global caching is disabled, setDefaultUseCaches(false);

How can I workaround this?

CODE:.........................

View 4 Replies View Related

Android :: Static Method In Java Accept Only Final Or Non Final Variables Within Its Method - But Not Static

Sep 15, 2010

Why should a static method in java accept only final or non final variables within its method, but not static?

For example I have the following method:

CODE:.................

View 6 Replies View Related

Android :: Call Non Static Method In Static SQLiteDatabase Class

Mar 30, 2010

i want to display a msg to the user (msg box or Toast) when exception happend in a static SQLite Database class that i use. the problem is that i cant call a non static method in a static class , how can i handle this. this is the class

private static SQLiteDatabase getDatabase(Context aContext) {

and i want to add something like this in the class when exception happen but context generates the problem of reference to non static in static class.

Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();

View 1 Replies View Related

Android :: Cannot Make Static Reference To Anon-static Method

Feb 7, 2010

I'm having some issues with the old "Cannot make a static reference to a non-static method" error in my Android program. I am creating a sand falling game (similar to the Powder Game) and I created a class called Control to create a Control Bar at the bottom of the screen with a slider for brush size (that works fine) and a button to pop up a Dialog to allow users to pick the selected element. However, when I call DemoActivity.showDialog(2) from my code, it gives the static reference to non-static error (DemoActivity is the main activity of my application). I also tried changing it to just Activity.showDialog(2), but I got exactly the same error!

Here's my code:

CODE:................

I fixed it by adding the following to my Control.java code:

CODE:..........

And then calling control.setActivity(this); from my onResume section of DemoActivity.java!

View 2 Replies View Related

Android :: Non-static Method Cannot Be Referenced From A Static Context

May 26, 2010

I am modifying the source code here: http://thinkandroid.wordpress.com/2009/12/30/getting-response-body-of-httpresponse/

I get this error:

code:.............

This error is line 13 on the second box.

View 5 Replies View Related

Android :: Use Static CreateBitmap Method?

Jun 23, 2009

My application crashes after I try to use the static Bitmap createBitmap method to get a mutable bitmap in order to fill it later with data.

If I only create one 1024x1024 the application works just fine, but when I try to load the same image more than once (first making my object null in each round) my application crashes on my third or fourth try.

CODE:..........................

View 4 Replies View Related

Android :: Get An Application Context Into A Static Method

May 7, 2010

I'm working on an Android application that has several Activities. In it I have a class with several static methods. I would like to be able to call these methods from the different Activities. I'm using the static methods to load data from an xml file via a XmlResourceParser. To create a XmlResourceParser requires a call on the Application Context. So my question is, what is the best way to get a reference to the Application Context into the static methods? Have each Activity get it and pass it in? Store it somehow in a global variable?

View 2 Replies View Related

Android :: How To Access Preferences In Static Method

Aug 21, 2010

I have a broadcast receiver that needs to notify a service that it has received a text message. The only way to do this (as far as I know) is a static method. But the method that is notified need access to the application's preferences.

Every method I have tried says that it cannot be accessed from a static method. So how do I access preferences from a static method?

View 2 Replies View Related

Android :: Calling A Non-static Java Method From C

Dec 22, 2009

In my Android app, I need to call a non static java method from C/C++. But i get a blunt crash when i do it using GetMethodID/CallVoidMethod()1 methods.

I have done like this:

1. Register the method using GetMethodID() as follows (mine is a cpp file): jmethodID xyz = (env)->GetMethodID( cls, "showxyz", "()V");

2. And I call this method as follows: env->CallVoidMethod(cls, xyz);

3. In java, my showxyz() is defined this way(this basically enables a button which was disabled) void showxyz() {findViewById(R.id.btnPass).setEnabled(true);}

And this crashes.

But I have been using this method of calling Java funcs from C using a set of GetStaticMethodID/CallStaticVoidMethod()(for nonstatic methods) and that works always.

But in this case, I have to call a non-static method and i get a crash.

View 2 Replies View Related

Android :: GetString(R.string In Static Method

Sep 29, 2010

When programming for Android sometimes you have to use static methods. But when you try to acces you resources in a static method with getString(R.string.text) you'll get an error. Making it static doesn't works. Does anyone knows a good way around this because the resource files in Android are very helpfull for creating things in different languages or making changes to a text.

View 2 Replies View Related

Android :: Make Request From An App That Can Enter Spring Security Secured Webservice Method?

Feb 13, 2010

I have a Spring Security (form based authentication) web app running CXF JAX-RS webservices and I am trying to connect to this webservice from an Android app that can be authenticated on a per user basis. Currently, when I add an @Secured annotation to my webservice method all requests to this method are denied. I have tried to pass in credentials of a valid user/password (that currently exists in the Spring Security based web app and can log in to the web app successfully) from the android call but the request still fails to enter this method when the @Secured annotation is present. The SecurityContext parameter returns null when calling getUserPrincipal().

How can I make a request from an android app that can enter a Spring Security secured webservice method?

Here is the code I am working with at the moment:

Android call:

CODE:...............................

View 3 Replies View Related

Android :: Call Non Static Method (Located In Main Class) From Different One

Oct 18, 2010

I've been trying to call a non-static method, located in my main application Class, from the Preferences Class. Because the method I call is not static, I instantiate the main class and then try to call the specific method I want but it's force closing.

Preferences.class (from where I call the method):
Preference sorted = (Preference) findPreference("sortPref");
sorted.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
Object d = new Dmarks();
((Dmarks) d).queryBookmarks();
return true;
}});
the Dmarks.class method I call:
public void queryBookmarks() {
Toast.makeText(context, Toast.LENGTH_LONG).show();
//context is not null and the Toast is working if I call it from Dmarks.class }

The Logcat:
E/AndroidRuntime(11718): FATAL EXCEPTION: main
E/AndroidRuntime(11718): java.lang.NullPointerException
E/AndroidRuntime(11718):
at android.content.ContextWrapper.getContentReso
lver(ContextWrapper.java:90)
E/AndroidRuntime(11718):
at android.app.Activity.managedQuery(Activity.ja
va:1520)
E/AndroidRuntime(11718):
at com.droidil.droidmarks.Dmarks.queryBookmarks(
Dmarks.java:101)
E/AndroidRuntime(11718):
at com.droidil.droidmarks.Preferences$2.onPrefer
enceChange(Preferences.java:47)
E/AndroidRuntime(11718):
at android.preference.Preference.callChangeListe
ner(Preference.java:756)
E/AndroidRuntime(11718):
at android.preference.ListPreference.onDialogClo
sed(ListPreference.java:219)
E/AndroidRuntime(11718):
at android.preference.DialogPreference.onDismiss
(DialogPreference.java:384)
E/AndroidRuntime(11718):
at android.app.Dialog$ListenersHandler.handleMes
sage(Dialog.java:1047)
E/AndroidRuntime(11718):
at android.os.Handler.dispatchMessage(Handler.ja
va:99)
E/AndroidRuntime(11718):
at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(11718):
at android.app.ActivityThread.main(ActivityThrea
d.java:4627)
E/AndroidRuntime(11718):
at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime(11718):
at java.lang.reflect.Method.invoke(Method.java:5
21)
E/AndroidRuntime(11718):
at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(11718):
at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:626)
E/AndroidRuntime(11718):
at dalvik.system.NativeStart.main(Native Method)
D/dalvikvm(11718): GC_FOR_MALLOC freed 4248 objects / 282248 bytes in 40ms
W/ActivityManager( 244): Force finishing activity com.droidil.droidmarks/.Preferences

View 5 Replies View Related

Android :: Why Should A Variable In Static Method Be Declared As Final In Java

Sep 15, 2010

I am having a static method .In the method when I decalare a variable , it was showing an error in eclipse saying that the variable should be decalared as final.

Can I know the reason for this , y should a variable in a static method be declared as final? I am writng an Android application where I should pass as an argument current Context of that application. So, when I pass the current context to the method and trying to copy it in a local variable , I am getting this error saying that the variable should be declared as final.

My method is like this:

CODE:.............

Error is showing at line where Context myctx=ctx; is declared and asking me to declare it as final.

View 4 Replies View Related

Android :: Static Method Calls To Derived Types Over Virtual Implementations?

Jul 8, 2010

I have class A, with methods foo and bar, that are implemented by A1 and A2. The functionality in both A1 and A2 is the same. In other words:
public class A {
public int foo() { return 0; };
public int bar() { return 1; };
} class A1 extends A {
public int AnotherFooFunction() { return foo();
} public int AnotherBarFunction() { return bar();
} } class A2 extends A {
public int AnotherFooFunction() { return foo();
} public int AnotherBarFunction() { return bar();
} }

Is it better to keep the code in this fashion, or to swap out those virtual methods as static methods? (In Java, everything non-final/non-private is considered virtual, right?) According to the Designing for Performance section in the Android Developer Docs, I should swap out these virtual methods for static ones. So the above becomes:
public class A {
public int foo() { return 0; };
public int bar() { return 1; };
} class A1 extends A {
public int AnotherFooFunction() { return A.foo();
} public int AnotherBarFunction() { return A.bar();
} class A2 extends A {
public int AnotherFooFunction() { return A.foo();
} public int AnotherBarFunction() { return A.bar();
} }

Is this how it "ought" to be? I fully realize that I may be misinterpreting this paragraph in the docs.

View 2 Replies View Related

Android :: Android - Safe To Create Static Method To Return Application Instance?

Sep 3, 2010

I am thinking to create a static method to return a reference to the application instance. I am not sure if it is safe to assume there is only one instance of the Application in one application. Apparently, the Application class in Android SDK doesn't provide such method to return the instance reference. So I suspect there must be a reason?

View 1 Replies View Related

Android :: Google Reader API Request Token - Get 400:Bad Request

Jul 8, 2010

this Android code worked fine before, but i'm having problems for some reason. here is the request i'm trying to make: https://www.google.com/reader/api/0/token. i'm getting 400:Bad Request as a response, and i'm not sure why. isn't this the correct URL for requesting a token? the auth token is being passed as a header in all requests now, and i can request feed list, and it works just fine, so there's nothing wrong with the auth code. what gives? in addition, i can request a token in a normal browser, like Chrome, and get a token as a response body. so the request itself is not the problem. i just can't figure out what is wrong with my requests in code...

View 1 Replies View Related

Bad Request While Trying To Send Cookie With HttpGet Request

Aug 17, 2012

I am developing an Android app for a website. I'm trying to get some information from the website by sending a cookie using a HttpGet request. I don't know where I am going wrong with the request. I am using AsyncTask to send the request to the server. The request also uses a token which I receive when I login to the webpage. All this is clear in the code below. This is part of the process in the doInBackground() function of the Asynctask:

BufferedReader in = null;
JSONObject token = Login.getToken(); // Token received after login, used in the cookie
try {
r = token.get("session_token").toString();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
[code]...

View 1 Replies View Related

General :: What Is (DIAL Request Modified To SS Request)

Aug 21, 2013

I own a Xiaomi MI2S, running MIUI-3.8.16 @ Android version 4.1.1.JRO03L with Baseband version CEFWMAZM-2.0.128 017.

From my phone provider (Tele2) i have to dial a 1 (one) before my PIN-code when traveling abroad.

The code is accepted, I can be called and i can send and receive SMS messages.

However i cannot make phone-calls...

The error (?) is "DIAL request modified to SS request" and (very short) "not connected"

View 2 Replies View Related

Replace Single Row View In Custom STATIC ListView - STATIC Data

Mar 18, 2013

I have Eclipse Juno and I'm working on an app with that.

The main activity will have a scrollable menu that takes you to all the other activities.

So the general structure/outline right now:[HIGH]Relative Layout ImageView (header logo type thing) ListView (the actual scrollable menu)[/HIGH]Here's the problem though... I can't find any simple list tutorials. I can easily make a single line list work but I need to make a two line list and one that is static, not dynamic and no examples are out there for that. It's like if you want to make a 2 line list, you can only learn how to do it in the most code-heavy ridiculous way possible.

Essentially what I am looking for with the list is this: Item one: Centred, bold, non selectable title (Resources)

- Item two-??: two line list items, click-able to a new activity, title of the section on first line, description on the second line.

- Item ??: Centred, bold, non selectable title (Tools)

- Item ??-??: two line list items, click-able to a new activity, title of the section on first line, description on the second line.

Nothing dynamic that is ever going to change, no super complex wonkey calculations, just to simply have the data set in stone (preferably via XML) and to call it into the list.

I experimented with some of the other list views and no matter what I did, I could get, via editing the resources and NOT using Java, more that one item on a single line but it wouldn't format it properly according to the layout I guess because I haven't got the ID correct or whatever I don't know.

I mean, all the examples I've seen for a 2 line list are extraordinarily over-coded and just bloated. I mean I have a website I am still working on in C#/ASP.net that has far more complex things in it with half the code that I've seen for the examples of the two line lists.

I tried on my own to figure it out (I am decent with C# and vaguely familiar with Java, self taught, and programming for some other systems like Python, again all self-taught), but like ALL coding references, they're organised by the actual code you implement (that you don't know) instead of by what you want it to do (so you have to search the whole code base to find something that you don't know what it's called but know what it does). >:C

View 10 Replies View Related

Android :: Static Vs Non-static Inner Classes

Mar 9, 2009

I have been finding it convenient to extend Handler in many of my activities to handle messages specific to the activity. The handler sublass is an inner class of the activity and needs to access its state. I am wondering if there is any performance difference between making the handler subclass static and passing in the activity explicitly in its constructor or making the subclass an "instance class" and letting the vm worry about my accessing members of the containing activity.

The static approach:

CODE:.............................

View 4 Replies View Related

Android :: HttpsUrlConnection Problem

May 20, 2009

I have been working with the HttpsUrlConnection class and have found an interesting issue, it seems to fail on every other connection. The first request connects to the server successfully but the second one always fails. Any ideas on what i may be doing wrong.

Here is my code.

code:.................

View 3 Replies View Related

Android :: Problem With HttpsURLConnection

Sep 17, 2010

I use the following code snippet to connect to a server and retrieve some data:

HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection(); InputStream ins = con.getInputStream();

The code mostly works fine. If I leave the app for a few minutes, and return to it and make another request, I receive an IOException: Broken Pipe.

Once it has failed one time, it immediately works again, and will continue to do so until I leave it for a while once more.

I don't know if this is an Android specific thing, or general Java, but it doesn't happen on my desktop test version.

View 7 Replies View Related

Android :: ClassCastException With HttpsURLConnection

Aug 30, 2010

I try to establisch a HttpsURLConnection with:

CODE:.................

But I get an Exception:

CODE:......................

But I can't find out, why. The same example is everywhere across the web.

View 2 Replies View Related

Android :: Query About The Usage Of HttpsURLConnection

Mar 9, 2010

I am using HttpsURLConnection to post data to a web server.

Here is the function I wrote to get the result. (see the code below)

Very strangely, when the function be first called in my program it would very likely return -1; and then I re-call the function after the first call, it would always work ok.

So I wonder if there is anything I am missing in the code that when the function be firstly called, the missing party is be "initialized", in that the followed call goes OK.

Here is my code of the function:

CODE:....................

View 3 Replies View Related

Android :: HttpsURLConnection And Intermittent Connections

Jan 31, 2010

I'm hoping someone could help me out with intermittent connections I'm getting using code with HttpsURLConnection.

The code I'm using is below:

CODE:...............

The connection works the first time everytime when I use it to pull a json file. However, when I use the connection again to send a command, it always fails the first time. It then typically works if I send the
command quickly ( within 5 seconds), but fails if I wait a while. I don't think its a SSL issue because it connects the first time correctly, but I could be wrong here. I also tried many different
variations such as adding:

CODE:.............

However, I had no luck. Any help would be greatly appreciated.

View 2 Replies View Related

Android :: HttpsURLConnection Failing Intermittently To Same URL

May 15, 2010

I think I'm experiencing the same as http://groups.google.com/group/android-developers/msg/9d37d64aad0ee357

This is Android 1.5 SDK. I happen to call several times below code(which is in a method) with
the same url and it fails intermittently. When it fails, there is no exception, the stream is empty so the
readConnection fails, and getResponseCode returns -1. Global caching is disabled, setDefaultUseCaches(false);

I suppose there must be some kind of url connection object pool somewhere.

How can I workaround this?

CODE:............................

View 2 Replies View Related

Android :: HttpsURLConnection.getInputStream Hangs

Aug 16, 2010

I try to build an https client for android and i need do get some request of an Servlet but when i use the getInputStream method the applicaion hangs.

There is no error only hanging when i call the method.

CODE:..................

This is only to check the call, but it didtn work.

the subscribe method works, when i comment out the line with the inputstream, the server show me all is correct. I can try the same with the Firefox and it works and i can see the request. i also put the keystore into the TrustManager.

View 2 Replies View Related

Android :: HttpsURLConnection Connection Problems

Sep 27, 2010

I'm a problem with a HttpsURLConnection that I can't seem to solve. Basically, I'm sending up some info to a server and if some of that data is wrong, the server sends me a 500 response code. However, it also sends a message in the response telling me which bit of data was wrong. The problem is that the message is always empty when I read it in. I think this is because a filenotfound exception always gets thrown before the stream can be read. Am I right? I tried reading the errorstream as well but this is always empty.

Here's a snippet:

CODE:........................

View 3 Replies View Related

Android :: Sending Huge Files With HttpsUrlConnection

Mar 12, 2010

I have some Android code that can send files to my webserver using an HttpsUrlConnection, but when it tries to send larger files I get an OutOfMemory exception when opening the OutputStream. Can anyone offer some assistance?

It looks something like this:

code:..............

This is where I try different things. The closes solution has been: httpConn.setChunkedStreamingMode(1024); In this case, I don't get the OutOfMemory immediately when opening the OutputStream, but I see the heap growing as I os.write() and it eventually runs out.

code:..............

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved