The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, SettingFragment, String)

引发错误的原因是因为import包的时候Fragment是引用的V4的,而activity继承Activity。
而getFragmentManager()是activity中的方法
但是getSupportFragmentManager是FragmentActivity中的方法
使用要统一

最后

package com.example.fragment;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity; public class MainActivity extends FragmentActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
}
package com.example.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup; /**
* A placeholder fragment containing a simple view.
*/
public class PlaceholderFragment extends Fragment { public PlaceholderFragment() {
} @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
rootView.findViewById(R.id.btnshow).setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
getFragmentManager().beginTransaction().replace(R.id.container, new AnotherFragment()).commit();
}
});
return rootView;
}
}

The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, SettingFragment, String)的更多相关文章

  1. 错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, MyFragment)

    Fragment newfragment =new MyFragment();fragmentTransaction.replace(R.layout.activity_main,newfragmen ...

  2. The method setItems(String) in the type ForTokensTag is not applicable for the arguments (Object)

    1. 问题 看到这个错误以为是貌似jsp页面有误,c:forTokens标签用错了?? An error occurred at line: in the jsp file: /WEB-INF/pag ...

  3. [log4j]Error:The method getLogger(String) in the type Logger is not applicable for the arguments

    原因:本该导入import org.apache.log4j.Logger; 结果成了import java.util.logging.Logger; 如果硬把private static Logge ...

  4. The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (new View.OnClickListener(){}, String, int)

    package comxunfang.button; import android.support.v7.app.ActionBarActivity; import android.os.Bundle ...

  5. The method load(Class, Serializable) in the type HibernateTemplate is not applicable for the arguments (Class, int)

    引入别人的项目发现利用HibernateTemplate的load的方法报错了.错误提示为: The method load(Class, Serializable) in the type Hibe ...

  6. The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments (GameV

    在当前短信内容的activity中写            Bundle bun = new Bundle();         bun.putString("message",  ...

  7. .replace(R.id.container, new User()).commit();/The method replace(int, Fragment) in the type FragmentTransaction is not app

    提示错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arg ...

  8. The method setOnClickListener(View.OnClickListener) in the type View is not applicable

    开始学习 android 了,学习的是高明鑫老师的android视频教程(android视频教学). 学到第八讲时, 在写动态设置时报错: The method setOnClickListener( ...

  9. The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder is not applicable for the arguments

    The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder i ...

随机推荐

  1. Angular初级入门

    1:jquery :库 -一般是封装了一些方法 -我们去调用他的这些方法分 2:angular:框架 -框架是提供了一些规则或者模式 -我们是根据这一种规则或者模式去写代码 -然后接下来就由angul ...

  2. 《think in python》学习-10

    think in python 10 列表 和字符串相似,列表是值得序列.在列表中,它可以是任何类型,列表中的值成为元素,有时也称为列表项 s = [10,20,30,40] print s #列表也 ...

  3. ASP.NET中的路径(path) 详解

    一 ASP.NET常用路径(path)获取方法与格式对照表 假设我们的网址为http://localhost:1897/ News/Press/Content.aspx?id=1019 跟 Brows ...

  4. 02Android用户界面优化之(一)Android Fragment

    一.使用Fragment 1.AndroidManifest.xml文件 <?xml version="1.0" encoding="utf-8"?> ...

  5. 第三方浏览器内核嵌入一、Crosswalk

    本篇分为三部分: 介绍Crosswalk背景 介绍Crosswalk集成步骤 为了减小体积,仅集成兼容ARM的Crosswalk(针对X86同理) PART_A Crosswalk背景介绍 Web技术 ...

  6. *++p和*p++的区别

    *p++:先是用*p这个值,然后再使p的地址加1. #include<iostream>using namespace std;int main(){    char s[81]=&quo ...

  7. jcSQL词法分析器对字符串token的解析

    上星期写完词法分析器的时候,曾遇上一个无关紧要却X疼的问题.毕竟是第一次完整地写整个语言的编译器(暂且这么叫着吧,解释器更靠谱),由于经验不足,在字符串解析这一块驻足了两天才解决掉,这里记录下来供以后 ...

  8. rabbitmq问题之HTTP access denied: user 'guest' - User can only log in via localhost

    问题: 昨天安装rabbitmq(3.3.4版本)服务,并启用rabbitmq_management插件去管理rabbitmq服务,但是在访问管理界面使用guest用户登录时出现login faile ...

  9. linux配置jdk环境详解

    环境:Redhat Server 5.1(虚拟机) 工具:Xftp4  jdk-7-linux-i586.rpm文件 步骤1:把jdk-7-linux-i586.rpm文件拷贝到/usr/local目 ...

  10. 手工制作OTG连接线 让小白实现OTG功能

    说到OTG功能,很重要的一点是,现在不少网上的720P高清视频体积已经超过4GB,我的小白也支持exFat及NTFS磁盘格式,可存储播放大于4GB的高清影音文件,也能通过OTG读取播放NTFS格式U盘 ...