无法解析构造函数Intent

时间:2015-06-21 19:03:15

标签: android android-intent android-tabhost

  • 我试图在我的应用程序中添加一个tabhost,但我无法弄清楚为什么这个错误'无法解析构造函数意图'显示,这是我的活动代码:

    public class SixthFragment extends Fragment {
    public static final String TAG = "sixth";
    
    
    
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,       Bundle   savedInstanceState) {
    
    View view =  inflater.inflate(R.layout.sixthfragment, container, false);
    TabHost tabHost = (TabHost) view.findViewById(R.id.tabHost);
    
    TabHost.TabSpec tab1 = tabHost.newTabSpec("First Tab");
    TabHost.TabSpec tab2 = tabHost.newTabSpec("Second Tab");
    TabHost.TabSpec tab3 = tabHost.newTabSpec("Third tab");
    
    // Set the Tab name and Activity
    // that will be opened when particular Tab will be selected
    tab1.setIndicator("Tab1");
    tab1.setContent(new Intent(this,MainActivity.class));
    
    tab2.setIndicator("Tab2");
    tab2.setContent(new Intent(this,Tab2Activity.class));
    
    tab3.setIndicator("Tab3");
    tab3.setContent(new Intent(this,Tab3Activity.class));
    
    /** Add the tabs  to the TabHost to display. */
    tabHost.addTab(tab1);
    tabHost.addTab(tab2);
    tabHost.addTab(tab3);
    
    
    return view;
    
    
    }
    
    
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    
    }
    
    
    
    }
    

  • 。有些帮助会有所帮助。感谢您的时间。

1 个答案:

答案 0 :(得分:2)

您尝试使用的Intent构造函数的第一个参数为ContextFragment不是Context。使用getActivity()代替this