错误: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,newfragment ).commit();
提示错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, MyFragment)
妈蛋,找了好久!一直以为子类对象不能赋值给父类引用。这部科学啊!
错误代码:
package com.example.testforfragment; import android.os.Bundle;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v4.app.Fragment;
import android.support.v4.app.Fragment.*;
import android.view.Menu; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Fragment newfragment =new MyFragment();
fragmentTransaction.replace(R.layout.activity_main,newfragment ).commit();
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }
修改:
package com.example.testforfragment; import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu; public class MainActivity extends FragmentActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Fragment newfragment =new MyFragment();
fragmentTransaction.replace(R.layout.activity_main,newfragment ).commit();
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }
1.导入的包
2.extends
3.getSurpport……
错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, MyFragment)的更多相关文章
- The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, SettingFragment, String)
The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the ...
- .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 ...
- 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 ...
- The method format(String, Object[]) in the type String is not applicable for the arguments
今天,我弟遇到一个有意思的错误~ 程序: package com.mq.ceshi1; public class StringFormat { public static void main(Stri ...
- The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments (GameV
在当前短信内容的activity中写 Bundle bun = new Bundle(); bun.putString("message", ...
- The method setOnClickListener(View.OnClickListener) in the type View is not applicable
开始学习 android 了,学习的是高明鑫老师的android视频教程(android视频教学). 学到第八讲时, 在写动态设置时报错: The method setOnClickListener( ...
- 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 ...
- 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 ...
- [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 ...
随机推荐
- JS处理四舍五入函数 toFixed(n)(可取小数点后n位)
在JS中四舍五入的函数 toFixed(n) , n为要保留的小数位数. n为0~20,当n超过20的时候,JS会出错. 如果小数点前和要截取的前一位都是0时,不会按常理截取. var h ...
- dubbo zk 分布式服务项目搭建与配置
1. 项目 jar -----提供接口 2. 项目 jar -----接口实现 provider启动zk main方法启动 start applicationContext.xml <b ...
- MVC架构模式分析与设计(一)---简单的mvc架构
首先 我要感谢慕课网的老师提供视频资料 http://www.imooc.com/learn/69 下面我来进行笔记 我们制作一个简单的mvc架构 制作第一个控制器 testController.cl ...
- java类的初始化块/执行顺序,实例化对象数据赋值
java里初始化一个类的对象,通过初始化快或者构造方法进行数据赋值.与其相关的执行代码有这么几种: 静态初始化块 初始化块 构造方法 静态初始化块 静态初始化块只在类加载时执行一次,同时静态初始化块只 ...
- JavaMail简单版实验测试
前言: 最近由于实现web商城的自动发送邮件功能的需求,故涉猎的邮箱协议的内部原理.现将简单版的Java Mail实例做个代码展示,并附上其中可能出现的bug贴出,方便感兴趣的读者进行测试! 1.载入 ...
- 数据结构图文解析之:二叉堆详解及C++模板实现
0. 数据结构图文解析系列 数据结构系列文章 数据结构图文解析之:数组.单链表.双链表介绍及C++模板实现 数据结构图文解析之:栈的简介及C++模板实现 数据结构图文解析之:队列详解与C++模板实现 ...
- EL表达式怎么获取Map的动态key?
缘由 El表达式在调用Map的时候,后台传过来的Map的key不一定是一个固定的值,需要根据另外一个对象的id作为key来put,或者更加复杂的组合id+"string"作为一个k ...
- 【poj2065】 SETI
http://poj.org/problem?id=2065 (题目链接) 题意 题意半天看不懂..给你一个素数P(P<=30000)和一串长为n的字符串str[].字母'*'代表0,字母a-z ...
- Architectural Model - SNMP Tutorial
30.3 Architectural Model Despite the potential disadvantages, having TCP/IP management software oper ...
- WinForm窗体代码结构优化
选择系统新建WinForm程序,会生成FormMain.cs/ FormMain.Designer.cs/ FormMain.resx 当我们发现系统生成的FormMain.cs里面代码太多的时候,不 ...