2012-01-12 68 views
0

的EndlessAdapter在使用EndlessAdapter,我碰到这个错误传来:错误而使用的Android

在这下面的语句无法实例类型EndlessAdapter:

EndlessAdapter adapter = new EndlessAdapter(this); 

我在EndlessAdapter定义的适配器类.java并导入它。

这是我的全部代码:

package com.example.litest; 

import java.util.HashMap; 
import java.util.LinkedList; 
import java.util.List; 
import java.util.Map; 

import com.example.utilities.TestListAdapter; 
import com.example.utilities.EndlessAdapter; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 
import android.widget.SimpleAdapter; 



public class ListActivity extends Activity{ 
    public final static String ITEM_TITLE = "title"; 
    public final static String ITEM_CAPTION = "caption"; 

    public Map<String,?> createItem(String title, String caption) { 
     Map<String,String> item = new HashMap<String,String>(); 
     item.put(ITEM_TITLE, title); 
     item.put(ITEM_CAPTION, caption); 
     return item; 
    } 

    @Override 
    public void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 

     List<Map<String,?>> security = new LinkedList<Map<String,?>>(); 
     security.add(createItem("Remember passwords", "Save usernames and passwords for Web sites")); 
     security.add(createItem("Clear passwords", "Save usernames aznd passwords for Web sites")); 
     security.add(createItem("Show security warnings", "Show warning if there is a problem with a site's security")); 
     for(int n=10; n>0; n--) 
      security.add(createItem("Clear passwords", "Save usernames and passwords for Web sites")); 

     // create our list and custom adapter 
     EndlessAdapter adapter = new EndlessAdapter(this) 


     //adapter.addSection("Security", new EndlessAdapter(this, security, R.layout.list_complex,new String[] { ITEM_TITLE, ITEM_CAPTION }, new int[] { R.id.list_complex_title, R.id.list_complex_caption })); 

     ListView list = new ListView(this); 
     list.setAdapter(adapter); 
     this.setContentView(list); 

    } 

} 

的logcat:http://pastebin.com/2WnnJ9KA

回答

0

后实际logcat的错误。很有可能,你试图在“this”没有引用正确的Context的地方实例化它。你可能会需要添加Activity类的名称,如new EndlessAdapter(MyActivity.this);

+0

发表了日志猫。检查! – Hick 2012-01-12 07:37:25

3

Cannot instantiate the type EndlessAdapter at this following statement:

EndlessAdapter adapter = new EndlessAdapter(this); 

当然。没有这样的构造函数。文档没有引用这样的构造函数。 demo/应用程序不使用这样的构造函数。代码EndlessAdapter不包含这样的构造函数。请使用其中一个定义的构造函数。引用文档:

EndlessAdapter has two constructors. The original one takes a ListAdapter as a parameter, representing the existing adapter to be made endless. Your EndlessAdapter subclass will need to override this constructor and chain upwards. For example, the DemoAdapter inside the demo project takes an ArrayList<String> as a constructor parameter and wraps it in a ListAdapter to supply to EndlessAdapter .

The second constructor takes a Context and resource ID along with the ListAdapter . These will be used to create the placeholder (see below).


Posted the log cat.

不,你没有。

I can tell you the problem, that is in manifest.xml I've to add the com.commonsware.cwac.adapter package. The problem here is, my main package is com.litest.main, which is what I've put in manifest.xml

您的清单中的任何地方都不需要有com.commonsware.cwac.adapter。请参阅GitHub存储库中的demo/项目。