android - 无法解析构造函数 Intent

标签 android android-intent android-tabhost

  • 我正在尝试向我的应用程序添加 tabhost,但我无法弄清楚为什么显示此错误“无法解析构造函数 Intent ”,这是我的 Activity 代码:

    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);
    
    }
    
    
    
    }
    

    如果您能提供一些帮助,我们将不胜感激,感谢您的宝贵时间。

最佳答案

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

关于android - 无法解析构造函数 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30968233/

相关文章:

android - 我如何使用包含 MapView 并在其下方显示 AdMob View 的 TabHost 包装?

android - 在播放视频和相机预览时在 Android 手机上捕获屏幕截图

java - Android Room - 汇总值并将其放入 TextView

android - 如何修复错误 :No such property: javaOuptuts for class: com. android.build.gradle.internal.scope.VariantScopeImpl

android - 页面正在加载 WebView 时的进度对话框

android - onActivityResult 不在 Fragment 中调用

android - 显示如何将蓝牙数据从计算机发送到 Android 手机的示例项目

android - 如何通过多个 Activity 返回结果

android - 在 onReceive 中找不到随按钮单击发送的 WidgetProvider Intent extras

android - Intent.ACTION_VIEW - 多个文件