Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8238179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:43:23+00:00 2026-06-07T19:43:23+00:00

I am getting a couple errors I cannot seem to fix… This is example

  • 0

I am getting a couple errors I cannot seem to fix… This is example code, so I’m confused what’s going on. The error’s are commented to the side of the lines where they show up.

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;


public class Connect {
    URL url;
    URLConnection urlConnection;
    DataOutputStream outStream;
    DataInputStream inStream;

    // Build request body
    String body = "fname=" + URLEncoder.encode("Atli", "UTF-8"); //Syntax error on token ";", { expected after this token


    // Create connection
    url = new URL("http://192.168.1.68/test/POST/post.php");
    urlConnection = url.openConnection();
    ((HttpURLConnection)urlConnection).setRequestMethod("POST");
    urlConnection.setDoInput(true);
    urlConnection.setDoOutput(true);
    urlConnection.setUseCaches(false);
    urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    urlConnection.setRequestProperty("Content-Length", ""+ body.length());

    // Create I/O streams
    outStream = new DataOutputStream(urlConnection.getOutputStream());
    inStream = new DataInputStream(urlConnection.getInputStream());

    // Send request
    outStream.writeBytes(body);
    outStream.flush();
    outStream.close();

    // Get Response
    // - For debugging purposes only!
    String buffer;
    while((buffer = inStream.readLine()) != null) {
        System.out.println(buffer);
    }

    // Close I/O streams
    inStream.close();
    outStream.close();

}

giving an error of:

Syntax error, insert "}" to complete ClassBody

Anybody see something obvious that I don’t?

On a side note, if the php echoes back html code, upon running this class, is java capable of understanding the html code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:43:24+00:00Added an answer on June 7, 2026 at 7:43 pm

    You can’t put code directly in the class body – you have to wrap it inside a member function.

    If this is intended to be a standalone program that member function should be:

    public static void main(String[] args) {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a couple of errors with the code below. The errors are 'use
I am getting a couple of weird compilation errors. This is for a homework
Getting the above error in following code. How to rectify it. Thanks. Please look
Getting this error: 2009-09-03 12:44:02.307 xcodebuild[307:10b] warning: compiler 'com.apple.compilers.llvm.clang.1_0.analyzer' is based on missing compiler
Getting a rendering error for this form: 'NoneType' object has no attribute 'widget' http://dpaste.com/88585/
Getting this error with jquery & jquery.form. Site has been live for awhile..upgraded to
I'm getting a couple of sql errors but I'm not too sure what to
These are my questions: I'm getting a couple of errors on the line public
This is kind of two questions in one :-D. I am getting a couple
I'm using this script which i used a couple years ago to fix the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.