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

时光总嘲笑我的痴心妄想 提交于 2019-12-10 13:11:54

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/21140156/eclipse-inserting-arg0-arg1-etc-instead-of-proper-parameter-names-when-overrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!