2012-01-12 61 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/項目。