12

I'm not sure is this is a problem with my installation of Eclipse (Helios) and Android SDK or something else but Eclipse Content Assist doesn't propose Object Methods for Android classes.

For example, if I create a simple program and add a Button btn, when I go to use the btn method setBackgroundResource(int) with Content Assist (Ctrl + Space) or Word Completion (Alt + /) neither of them have any proposals. If I type btn.(Ctrl + Space), Content Assist lists; equals(), getClass(), hasCode(), Notify()...wait(), shows none of the Button methods! Can anyone help?

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;

public class HelloWorld extends Activity {

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    setContentView(R.layout.main);

    Button btn = Button(this);
    btn.(Ctrl + Space)

    }
}
EraserheadIRL
  • 1,061
  • 2
  • 12
  • 20

5 Answers5

74

Had this same problem after moving to Juno 4.2.0. Here's what worked for me: Preferences>Java>Editor>Content Assist>Advanced. Make sure “Java Proposals” is ticked.

Not sure why it wasn't checked by default.

Tony D
  • 1,531
  • 17
  • 29
8

Ah, found the problem, it's down to something going wrong with the workspace, created a new workspace and copied over my projects, all working again!

EraserheadIRL
  • 1,061
  • 2
  • 12
  • 20
  • Thanks! The same problem occurred to me when I switched to Eclipse 4.2 (Juno) from 3.7 (Indigo). After copying them in, all I needed to do was import them as existing projects. – Björn Kechel Aug 17 '12 at 06:56
1

You need to delete

   Button btn = Button(this);
   btn.(Ctrl + Space)

instead have

Button btn = (Button) findViewById(R.id.yourbuttonid);

(where yourbuttonid is whatever id you gave it in the XML, the assist will come to help you once you've typed the '.')

then when you type

you should get the assist as soon as you've typed the '.'

NickT
  • 23,844
  • 11
  • 78
  • 121
  • Or `Button btn = new Button(this);` – Falmarri Nov 05 '10 at 20:24
  • Thanks NickT for your help, I've given that a go but no joy, so if you see the Button methods and I don't then there must be something wrong with my Eclipse install, I switched to Eclipse 3.5 and still had the same problem! – EraserheadIRL Nov 08 '10 at 10:03
1

Quote from http://d.android.com/sdk/eclipse-adt.html:

Caution: There are known issues with the ADT plugin running with Eclipse 3.6. Please stay on 3.5 until further notice.

Felix
  • 88,392
  • 43
  • 149
  • 167
  • Thanks Felix, I've switched to Eclipse 3.5 and re-installed Android SDK, but again when I type btn.(Ctrl + Space) content assist doesn't list any Button methods. Also if I create the Button btn by linking it to an XML Button using Button btn = (Button) findViewById(R.id.Button01) content assist still doesn't show any Button Methods after typing "btn" + "." + (Ctrl + Space) it just lists a number of basic object methods. Does it work for anyone else? – EraserheadIRL Nov 08 '10 at 10:00
0

Follow following step :

  1. Click on Preferences
  2. Select Java
  3. Click on Editor
  4. Content Assist and paste "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz." (note the dot after z) into the "Auto activation triggers for Java:" field.
Dharmesh
  • 221
  • 2
  • 3