How to resolve The method addView(View, int, LinearLayout.LayoutParams) of type YourLayout must override or implement a supertype method

StackOverflow https://stackoverflow.com/questions/17239431

سؤال

I've already tried setting the java sdk version to 1.6(It was already set correctly). I've also tried cleaning the project as well as restarting eclipse.

My definition appears correct as I used eclipse's Source > Override/Implement Methods create the methods from subclasses ViewGroup.

@Override
public void addView(View child, int index, LayoutParams params) {
    super.addView(child, index, params);
}
هل كانت مفيدة؟

المحلول

Change it to

addView(View child, int index, ViewGroup.LayoutParams params)

Looks like somehow you imported LinearLayout.LayoutParams instead of ViewGroup.LayoutParams and ViewGroup does not have a method with a signature like that.

ViewGroup.addView()

Make sure your method is using the right kind of LayoutParams

نصائح أخرى

Turns out that eclipse generated code that it didn't like. I suspect when it generated the code it assumed that LayoutParams was LinearLayout.LayoutParams(I was subclassing LinearLayout). Explicitly setting layout params to ViewGroup.Layout params did resolve the problem.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top