1

There is a mysterious error at the line ee.add(new BasicNameValuePair("uid","demo"));

Eclipse says:

Multiple markers at this line
- Syntax error on token "add", = expected after this token
- Syntax error on token(s), misplaced construct(s)

package com.test;
import java.util.*;
import org.apache.http.*;
import android.app.Activity;
import android.os.Bundle;

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

    ArrayList<NameValuePair> ee = new ArrayList<NameValuePair>();
    ee.add(new BasicNameValuePair("uid","demo"));//error occurs here
}

I don't know what the problem is, because ArrayList do have the method add(), and I saw many people (e.g. Link a tutorial of Connecting to MySQL database) code like this. That's why it is mysterious.

Can anybody tell me why did Eclipse throw the error and how to fix it?

1 Answer 1

13

You're trying to call a method in the main class body. All you can have there is declarations. Put the ee.add() call inside the onCreate (or another method) and it will work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.