错误: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 ...
随机推荐
- NB-IoT的相关资料整理(基本概念,技术优势,典型案例和当前的进展)
人与人之间的通讯规模已近天花板,物与物的则刚刚进入增长快车道.随着可穿戴.车联网.智能抄表等新兴市场的开启,工业4.0.智慧城市.智慧农业等理念照进现实,万物互联的时代正加速到来. 一 ...
- .net Core学习笔记:Windows环境搭建
1.安装 VS2015 Update3.如果已经安装了VS2015,但不是Update3版本,请在VS的工具 --> 扩展与更新 中执行update3的升级(大约需要2小时). 2..net C ...
- 【BZOJ-2325】道馆之战 树链剖分 + 线段树
2325: [ZJOI2011]道馆之战 Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 1153 Solved: 421[Submit][Statu ...
- SpringBoot源码解析:tomcat启动分析
>> spring与tomcat的启动分析:war包形式 tomcat:xml加载规范 1.contex-param: 初始化参数 2.listener-class: contextloa ...
- Samba服务配置简明笔记
内部服务器之间拷贝数据,用root账号访问,没有做更复杂的设置. 1.用YUM安装samba服务器端及客户端: [root@tenjs05 init.d]# yum install samba sam ...
- android md5加密与rsa加解密实现代码
import java.io.UnsupportedEncodingException;import java.security.MessageDigest;import java.security. ...
- String类的功能
String类 标红的为较少出现的 1.判断功能 boolean equals(Object obj) :比较字符串内容是否相同,区分大小写 boolean equalsIg ...
- JAVA教师:给JAVA初学者的忠告
我带过不少JAVA,C++班的课,来学习的同学很多都是初学者,一部分是急着找工作的,一部分是很感兴趣的.他们都想在短短一两个星期内掌握Java,这是不切实际的.而且这样做很容易让自己心浮气燥,难以静下 ...
- Google 地图 API V3 之 叠加层
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
- Yii2中如何将Jquery放在head中的方法
原文地址: https://my.oschina.net/kenblog/blog/547602 方法一(推荐):针对jquery进行components配置,指定Yii2自带jquery自带资源出现 ...