2014-06-11 73 views
0

我正在寫一個Android應用程序,模擬http://www.rottentomatoes.com/mobile/網站 我有一個listView中的電影列表,當我點擊一個單一的電影我想要一個評論列表(如果你點擊在網站上,你會看到他們),但是我的應用程序停止當我點擊孩子ListView不工作

MainActivity

public void onItemClick(AdapterView<?> parent, View view, int position, 
      long id) { 
     System.out.println ("clicked"); 
     Movie data = (Movie) adapter.getItem(position); 
     String url = data.getLinks().getReviews(); 
     System.out.println (url); 
     Intent intent = new Intent(); 
     intent.setClass(getActivity(), MovieDetailsActivity.class); 
     intent.setData(Uri.parse(url)); 
     startActivity(intent); 

    } 

次活動的工作 - 即假設啓動列表

package charnetskaya.rottentomatoes; 


public class MovieDetailsActivity extends Activity { 

static String url; 

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.movie_details); 

    if (savedInstanceState == null) { 
     getFragmentManager().beginTransaction() 
       .add(R.id.container, new PlaceholderFragment()).commit(); 
    } 

    System.out.println("CREATED"); 
    Intent intent = getIntent(); 
    Uri uri = intent.getData(); 
    url = uri.toString(); 
} 

public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 
    if (id == R.id.action_settings) { 
     return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 

public static class PlaceholderFragment extends Fragment implements 
     OnItemClickListener { 

    private ReviewsAdapter adapter; 

    public PlaceholderFragment() { 

    } 

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

     View rootView = inflater.inflate(R.layout.movie_details, container, 
       false); 
     ListView list = (ListView) rootView.findViewById(R.id.reviewsList); 
     adapter = new ReviewsAdapter(inflater); 
     list.setAdapter(adapter); 
     System.out.println("HERE"); 
     DownloadReviews task = new DownloadReviews(url); 
     task.execute(new Void[0]); 
     System.out.println("THERE"); 
     return list; 

    } 

    @Override 
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 
      long arg3) { 
     // TODO Auto-generated method stub 

    } 

} 

}

錯誤消息 enter image description here

+0

佈局文件出現問題。 'R.layout.movi​​e_details'似乎沒有連接到它的佈局。 –

回答

1

在你PlaceholderFragmentonCreateView試圖返回rootView不是list

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

     View rootView = inflater.inflate(R.layout.movie_details, container, 
       false); 
     ListView list = (ListView) rootView.findViewById(R.id.reviewsList); 
     adapter = new ReviewsAdapter(inflater); 
     list.setAdapter(adapter); 
     System.out.println("HERE"); 
     DownloadReviews task = new DownloadReviews(url); 
     task.execute(new Void[0]); 
     System.out.println("THERE"); 
     return rootView; 

    }