2014-03-31 46 views
1

我目前正在研究一個應用程序,以允許用戶從GridView庫中選擇一個ImageView並將其顯示在其自己和它的所有美麗之中。ImageAdapter沒有包含錯誤

GridView位於片段上,然後將數據傳遞給活動以顯示選定的圖像。我的整個項目正在進行,直到初始化ImageAdapter。我收到一個錯誤,指出沒有類型GalleryView的封閉實例。我已經嘗試過,然後嘗試了一些,不願發佈這個問題,但我仍然沒有接近解決這個問題。

public class SingleImageGallery extends Activity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.single_image_view); 

    Intent i = getIntent(); 
    int position = i.getExtras().getInt("id"); 
    ImageAdapter imageAdapter = new ImageAdapter(this); 

    ImageView imageView = (ImageView) findViewById(R.id.SingleView); 
    imageView.setImageResource(imageAdapter.pics[position]); 
    } 
} 
+0

@laalto ImageAdapter確實是GalleryView中的一個嵌套類,我已經將它從GalleryView類中移除,並且一切都完美運行。非常感謝! –

回答

1

錯誤消息表明您試圖實例化一個非靜態的內部類,而不引用包含的外部類。

我猜你的ImageAdapterGalleryView中的一個非靜態內部類。您應該製作ImageAdapterstatic,因爲它不需要參考GalleryView