The constructor Intent is undefined error

android, android-activity, android-fragments, android-intent

Solution

Start new Activity as :

Intent ii = new Intent(getActivity(),TeamHomeActivity.class);
 startActivity(ii); 

because Context is not super class of SherlockFragment class and you will need to use getActivity() which return Activity to current fragment is associated.

Problem

I am using fragments. I have a spinner in the fragment. I want to lauch a new activity when spinner item is selected. I am getting this error Error The constructor Intent(UserHomeActivity, Class) is undefined UserHomeActivity.java /SwipeyTabs/src/com/recscores/android line 28 Java Problem ``` public class UserHomeActivity extends SherlockFragment{ Spinner spinnerTeam; Spinner spinnerLeague; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ View view =inflater.inflate(R.layout.user_home, container, false); // Team Spinner spinnerTeam = (Spinner)view.findViewById(R.id.spinner_team); spinnerTeam.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { **Intent ii = new Intent(UserHomeActivity.this,TeamHomeActivity.class); startActivity(ii); ** } public void onNothingSelected(AdapterView<?> adapterView) { return; } }); ```

Original source

Related problems