Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse inserting arg0, arg1 etc. instead of proper parameter names when overriding Android methods

When I override methods from the Android classes in Eclipse, I get useless parameter names like "arg0", "arg1" etc. For example when overriding methods from SQLiteOpenHelper I get:

@Override
public void onCreate(SQLiteDatabase arg0) {
    // TODO Auto-generated method stub
}

@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
    // TODO Auto-generated method stub
}

I've found various posts about this but none of the accepted solutions seem to work for me. It is also strange because it only seems to happen some of the time. For example the constructors in the above test had correctly named parameters.

I have got "Documentation for Android SDK" installed in the Android SDK Manager for Android 4.4.2. Do I still need to manually attach the docs (or even source?) somehow for this to work reliably, and if so how do I go about this?

Thanks!

like image 938
Matt Wilson Avatar asked Jan 15 '14 14:01

Matt Wilson


1 Answers

As @greg-449 mentioned in the comments, the Android source needs to be attached for this to work.

Following the steps in this link seems to fix this.

In case the link is broken in future, the steps are:

  1. Download "Sources for Android SDK" using the SDK Manager

  2. Right click android.jar in the Eclipse Package Explorer (under the Android {version} node), and click properties

  3. Under "Java Source Attachment", enter the path to the downloaded source directory which is along the lines of {sdk}/sources/android-{version}

I then get this:

@Override
public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub
}

UPDATE: For reference, a similar problem occurs in Android Studio (v0.4.2 at the time of writing). Sources can be attached via File -> Other Settings -> Default Project Structure, select SDKs, android platform and add the source in the "Sourcepath" tab.

like image 97
Matt Wilson Avatar answered Oct 08 '22 02:10

Matt Wilson