The method xxx of type new xxxx must override 的问题

The method isViewFromObject(View, Object) of type new PagerAdapter(){} must override or implement a supertype method

网上说的方法: 一、

因为你的Compiler 是jdk1.5,只要把它改为 1.6
方法:
1. window ->preferences... -> java -> Compiler
2. Compiler compliance level : 6.0
二、 把项目的JRE变成6.0的
项目右键->build path->configure build path->java Compiler(左边那排中) ->在右边的Compiler compliance level 修改版本为6.0

试过了没有作用。

import java.awt.Window;
import java.util.ArrayList;
import java.util.List;

import javax.swing.text.View;

import com.csst.videotalk.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;

import android.view.ViewGroup;

public class ViewPaper_activity extends Activity
{
ViewPager mViewPager;

private int[] mImgIds = new int[] { /*R.drawable.guide_image1,

R.drawable.guide_image2, R.drawable.guide_image3 */};

private List mImageViews = new ArrayList();

@Override  
protected void onCreate(Bundle savedInstanceState)  
{  
    super.onCreate(savedInstanceState);  

    //requestWindowFeature(Window.FEATURE_NO_TITLE);  
    setContentView(R.layout.view_paper);  

    initData();  

    mViewPager = (ViewPager) findViewById(R.id.id_viewpager);  

    mViewPager.setAdapter(new PagerAdapter()  
    {  
        @Override  
        public Object instantiateItem(ViewGroup container, int position)  
        {  

            container.addView(mImageViews.get(position));  
            return mImageViews.get(position);  
        }  

        @Override  
        public void destroyItem(ViewGroup container, int position,  
                Object object)  
        {  

            container.removeView(mImageViews.get(position));  
        }  

        @Override  
                    //就是这里一直报错
        public boolean isViewFromObject(View view, Object object)  
        {  

            return view == object;  
        }  

        @Override  
        public int getCount()  
        {  
            return mImgIds.length;  
        }  
    });  

}  

private void initData()  
{  
    for (int imgId : mImgIds)  
    {  
        ImageView imageView = new ImageView(getApplicationContext());  
        imageView.setScaleType(ScaleType.CENTER_CROP);  
        imageView.setImageResource(imgId);  
        mImageViews.add(imageView);  
    }  
}  

}

3个回答

竟然自己解决了,虽然不知道原因,哈哈哈!!谁能给解释下;
public boolean isViewFromObject(View view, Object object)

{

        return view == object;  
    }  

            改成 
                public boolean isViewFromObject(android.view.View view, Object object)  
    {  

        return view == object;  
    }  

就可以了,我是先删除原来的override,按提示自动添加未重写的方法,系统自动写出来的。

制定是jdk版本的问题,要不就是工具的问题,实在不行就把注解删了呗。

奇怪的是其他几个函数也是override,怎么就不报错,就isViewFromObject这个函数报错,删掉不行,父类的抽象函数必须要重写,删掉一样会报错的。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐