UrlConnection does not support output

by Hershiv Haria » Mon, 07 Dec 2009 13:55:58 GMT


Sponsored Links
 Hi all,

I'm currently trying to get an Android application to connect and send
a protocol buffer to a servlet on App Engine.
However, when I get to the line "OutputStream out =
urlc.getOutputStream()" I get the exception that it "does not support
output."

I've not found many people with this issue, and no posted fixes apart
from using newer SDKs. However, this is for a university project and
I'm sticking to 1.5, so any help would be appreciated.

The only other relevant information I can think of is I have added the
uses internet permission, again I'm on SDK1.5 and I'm running in
Eclipse.

The code is as follows:

package my.transferclient;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;

import my.tft.protos.RandomMessageProtos.Note;
import my.tft.protos.RandomMessageProtos.RandomMessage;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class TransferClient extends Activity {

        private final static String TAG = "TransferClient";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        try {
        URL url = new URL(" http://10.0.2.2 :8080/testfileupload");
        URLConnection urlc = url.openConnection();

        OutputStream out = urlc.getOutputStream();

        RandomMessage.Builder rm = RandomMessage.newBuilder();
        Note.Builder note = Note.newBuilder();

        note.setName("Blargy McBlarg");
        note.setMessage("This is a random message");

        rm.addNote(note);

        rm.build().writeTo(out);
        out.close();

        BufferedReader rd = new BufferedReader(new InputStreamReader
(urlc
                                .getInputStream()));
                String line;
                System.out.println("Respose is:");
                while ((line = rd.readLine()) != null) {
                        System.out.println(line);
                }
                rd.close();

        } catch (Exception e) {
                Log.v(TAG, e.getMessage());
        } // catch
    }
}

--



Other Threads

1. How to prevent GLSurfaceView destruction

Hi list,

I am currently porting a 3D app on Android. This app consists of a 3D view
(embedded in a GLSurfaceView) and of menu screens (for settings, search ,
etc.).

My main activity is the one containing the GLSurfaceView. It's always the
root of it's task. The problem is that my GLSurface gets destroyed whenever
I launch another activity and all the GL objects (VBOs, textures) that I
created in the GL context get deleted/invalidated along. So whenever my
users go in the menu, the 3D scene has to be fully reloaded. Wouldn't there
be a way to prevent the surface's destruction ?

Thanks for any help.

Florent.

-- 

2. What is <protected-broadcast> in android manifest file?

Hey i am seeing in android built-in phone application's manifest a tag
named <protected-broadcast>

like
<protected-broadcast
android:name="android.intent.action.SERVICE_STATE" />

I goggled but cant managed to understand actually what it means?/

-- 

3. Stopped unexpectedly on a real phone but not on the simulator

4. Tool to synchronize String properties betweens differents languages

5. EditText uncontrollable/unpredicatable soft keyboards

6. Activity restart crash after OS kills it

7. Runtime Language change support.