2014-09-04 23 views
0

這是我在主要活動中的代碼不知道爲什麼findViewById中的錯誤發生在 ..這只是我第一次在JSON paarsing。findViewById中的JSONPARSING錯誤

public class HomeFragment extends Fragment{ 

     public HomeFragment(){} 
     View rootView; 
     ListView list; 
     ActorsAdapter adapt; 
     ArrayList<Actors> actorslist; 

     @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, 
       Bundle savedInstanceState) { 

      View rootView = inflater.inflate(R.layout.home_fragment, container, false); 

      list = (ListView)findViewById(R.id.listFeeds); 
      actorslist = new ArrayList<Actors>(); 
      return rootView; 

      new ActorsAsynTask().execute("http://jcasim.5gbfree.com/Project/login.php"); 
     } 

回答

0

listFeeds這是我敢肯定一個組件是住在你的片段組成部分。由於您還沒有返回根視圖,findViewById不會找到它。你必須等到它在屏幕上使用findViewById(在onStart()方法中)詢問它,或者在它返回之前請求它形成根視圖。

它會是list = (ListView)rootView.findViewById(R.id.listFeeds);

0

FragmentViewonCreateView()返回之前未設置。因此,findViewById()嘗試從null參考中找到指定的R.id.listFeeds

試試這個list = (ListView)rootView.findViewById(R.id.listFeeds);