Well, first of all Java is not PHP. You should start from learning
basic Java(Just a few results from google, the book is quite good):
http://www.amazon.com/Head-First-Java-Kathy-Sierra/dp/0596009208/
http://www.javabeginner.com/
http://download.oracle.com/javase/tutorial/

And your code that does things has to go into a thing called method.
No operations are allowed in the class body, all operations must be in
a method. Sorry to dumb it down so much, but I don’t know how
proficient you are with Java.

public class http_client extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    // <<<<<<<<<<<<<<<<<<<<<<<<<<< Removed the curly bracket here
    HttpPost httppost;

    HttpClient httpclient;

    // List with arameters and their values
    List<NameValuePair> nameValuePairs;

    String serverResponsePhrase;
    int serverStatusCode;
    String bytesSent;

    httppost = new HttpPost(serverURL);
    httpclient = new DefaultHttpClient();
    nameValuePairs = new ArrayList<NameValuePair>(2);

    // Adding parameters to send to the HTTP server.
    nameValuePairs.add(new BasicNameValuePair(parameterName1,
value1));
    nameValuePairs.add(new BasicNameValuePair(parameterName2,
value2));

    // Send POST message  with given parameters to the HTTP server.
    try {
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    HttpResponse response = httpclient.execute(httppost);

    InputStream is = response.getEntity().getContent();
    BufferedInputStream bis = new BufferedInputStream(is);
    ByteArrayBuffer baf = new ByteArrayBuffer(20);

    int current = 0;
    while((current = bis.read()) != -1)
    {
    baf.append((byte)current);
    }

    bytesSent = new String(baf.toByteArray());

    // Response from the server
    serverResponsePhrase = response.getStatusLine().getReasonPhrase();
    serverStatusCode = response.getStatusLine().getStatusCode();
    // for receiving response from the server
    Toast.makeText(getBaseContext(),
     bytesSent,
     Toast.LENGTH_SHORT).show();

    }
    catch (Exception e) {
    // Exception handling
    }
 } //<<<<<<<<<<<<<<<<<<<<< Added this curly bracket to identify the
end on onCreate method
}



On 18 янв, 21:13, Atif Musaddaq <[email protected]> wrote:
> Hi, Guys
>
> Facing a small problem, I want to know two things, Either i am going in the
> right direction ? Second why i have these two syntax error, See below the
> exact line.
> 1. *Syntax error on token ";", { expected after this token*
> *2. **Error: Syntax error, insert "}" to complete ClassBody*
> *
> *
> *Note I am beginner plz donot mind if i am doing some foolish mistake :-)
> Thanks in advance*
>
> here is my simple PHP code.
> ******************************************************
> <?php
> echo "param1 value: ".$_POST['parameterName1']."\n";
> echo "param2 value: ".$_POST['parameterName2']."\n";
> echo "Your post was successfully sent";
> ?>
> **********************************************************
> Now here come my Java code
>
> //all Required imports and package
>
> public class http_client extends Activity {
>     /** Called when the activity is first created. */
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>
>     }
>     HttpPost httppost;
>
>     HttpClient httpclient;
>
>     // List with arameters and their values
>     List<NameValuePair> nameValuePairs;
>
>     String serverResponsePhrase;
>     int serverStatusCode;
>     String bytesSent; *<<<<<<< Syntax error on token ";", { expected after
> this token*
>
>     httppost = new HttpPost(serverURL);
>     httpclient = new DefaultHttpClient();
>     nameValuePairs = new ArrayList<NameValuePair>(2);
>
>     // Adding parameters to send to the HTTP server.
>     nameValuePairs.add(new BasicNameValuePair(parameterName1, value1));
>     nameValuePairs.add(new BasicNameValuePair(parameterName2, value2));
>
>     // Send POST message  with given parameters to the HTTP server.
>     try {
>     httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
>
>     HttpResponse response = httpclient.execute(httppost);
>
>     InputStream is = response.getEntity().getContent();
>     BufferedInputStream bis = new BufferedInputStream(is);
>     ByteArrayBuffer baf = new ByteArrayBuffer(20);
>
>     int current = 0;
>     while((current = bis.read()) != -1)
>     {
>     baf.append((byte)current);
>     }
>
>     bytesSent = new String(baf.toByteArray());
>
>     // Response from the server
>     serverResponsePhrase = response.getStatusLine().getReasonPhrase();
>     serverStatusCode = response.getStatusLine().getStatusCode();
>     // for receiving response from the server
>     Toast.makeText(getBaseContext(),
>      bytesSent,
>      Toast.LENGTH_SHORT).show();
>
>     }
>     catch (Exception e) {
>     // Exception handling
>     }
>
> } *<<<<<<<  Error: Syntax error, insert "}" to complete ClassBody*
>
> --
> Atif

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to