码迷,mamicode.com
首页 > 其他好文 > 详细

问题:实现继承的抽象方法

时间:2015-05-06 01:22:32      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:

  今早在学习过程中,在实现继承的抽象方法时,明明已经实现了,但还是会报错。

  代码如下:

package com.example.listview;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;


public class MainActivity extends Activity {

	private List<Picture> pictureList = new ArrayList<Picture>();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initPicture();
		PictureAdapter adapter = new PictureAdapter(MainActivity.this, 
				R.layout.picture_item, pictureList);
		ListView listView = (ListView) findViewById(R.id.list_view);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				// TODO Auto-generated method stub
				Picture picture = pictureList.get(position);
				Log.d("MainActivity","您点击了 : "+picture.getName());
				Toast.makeText(MainActivity.this, "您点击了 : "+picture.getName(), 
						Toast.LENGTH_SHORT).show();
			}
			
		});
	}

	private void initPicture() {
		// TODO Auto-generated method stub
		Picture android = new Picture("Android", R.drawable.android);
		pictureList.add(android);
		
		Picture apple = new Picture("Apple", R.drawable.apple);
		pictureList.add(apple);
		
		Picture safeMgr = new Picture("SafeMgr", R.drawable.guanjia);
		pictureList.add(safeMgr);
		
		Picture linux = new Picture("Linux", R.drawable.linux);
		pictureList.add(linux);
		
		Picture vcr = new Picture("VCR", R.drawable.shexingji);
		pictureList.add(vcr);
		
		Picture set = new Picture("Set", R.drawable.shezhi);
		pictureList.add(set);
		
		Picture windows = new Picture("Windows", R.drawable.windows);
		pictureList.add(windows);
		
		Picture music = new Picture("Music", R.drawable.yinyue);
		pictureList.add(music);
		
		Picture game = new Picture("Game", R.drawable.youxi);
		pictureList.add(game);
		
		Picture camera = new Picture("Camera", R.drawable.zhaoxiangji);
		pictureList.add(camera);
	}
}

  报错:

技术分享

  抽象方法实现:

技术分享

  报错提示:

技术分享

  

  实在找不到错误,然后到QQ群里询问,才知道抽象方法的实现需要自动添加,不能复制或手打。当我删掉自己手打的代码,才用自动添加实现时,就没有报错误了。询问这是为什么,就没有人回答我了。。是这个问题太弱智了吗?

  求解。谢谢

  

 

问题:实现继承的抽象方法

标签:

原文地址:http://www.cnblogs.com/LGMing/p/4480692.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!