2012-07-23 37 views
1

我試圖創建this:試圖建立一個片段類

,他們給你的一個片段類的代碼如下片段類,但我越來越

ExampleFragments.java

package com.example.learn.fragments; 

public static class ExampleFragments extends Fragment { 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     return inflater.inflate(R.layout.blue_pill_frag, container, false); 
    } 
} 

但我得到了第9行的錯誤,我在那裏聲明類的名稱。

Illegal modifier for the class ExampleFragments; only public, abstract & final are permitted 

我敢肯定,這是基本的東西是我不理解,謝謝。

回答

4

您不能擁有static頂級課程。更改

public static class ExampleFragments extends Fragment { 

public class ExampleFragments extends Fragment { 
+0

好吧,所以我需要去了解什麼是靜態類。謝謝。另一個問題,但。爲什麼谷歌給一個'靜態類'作爲例子?我應該使用片段作爲靜態還是無關緊要? – EGHDK 2012-07-23 14:03:27

+0

這可能是因爲它是* inner *類。 – aioobe 2012-07-23 14:09:24

1

在您關注的例子中,使用static修飾符,因爲這個片段嵌套類。

要擺脫錯誤,您可以將該片段包含到現有類中,或者刪除靜態修飾符。

+0

嗯...嵌套類的任何好例子?這個詞對我來說是新的。我一直認爲只有班級。謝謝,我感謝幫助。 – EGHDK 2012-07-23 15:37:54

相關問題