Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Error:(56, 28) error: cannot find symbol method clear()

 
John Joe
Ranch Hand
Posts: 143
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day guys. I have a listView, and AllAdapter adapter where the AllAdapter is extending to BaseAdapter

Why I get error on line adapter.clear()?

Error



Code

  
 
Rob Spoor
Sheriff
Posts: 20827
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BaseAdapter doesn't have a clear() method. That means that you will need to declare adapter as AllAdapter and not as BaseAdapter. Can you show us how you declared adapter?
 
John Joe
Ranch Hand
Posts: 143
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:BaseAdapter doesn't have a clear() method. That means that you will need to declare adapter as AllAdapter and not as BaseAdapter. Can you show us how you declared adapter?


This is how I declare adapter



And code after setContentView



And finally AllAdapter Class

 
Norm Radder
Rancher
Posts: 1631
21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cannot find symbol method clear()

Where do you think the method clear() is defined? What class in what package?
 
John Joe
Ranch Hand
Posts: 143
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
cannot find symbol method clear()

Where do you think the method clear() is defined? What class in what package?


I post part of my code here.

 
Norm Radder
Rancher
Posts: 1631
21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That doesn't answer my question:
Where do you think the clear() method is defined?  What class is it in?
If the compiler can not find a definition for a method it will flag that statement as an error.
 
John Joe
Ranch Hand
Posts: 143
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:That doesn't answer my question:
Where do you think the clear() method is defined?  What class is it in?
If the compiler can not find a definition for a method it will flag that statement as an error.


Do you mean that I need to create a clear method in AllAdapter class ? I would like to clear all the listview item first before they added into listview.
 
Norm Radder
Rancher
Posts: 1631
21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean that I need to create a clear method in AllAdapter class ?

You can not call a method that does not exist.  If you want the AllAdapter class to have a clear method, you will have to write it.

Copied to Android section.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!