错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, MyFragment)
2014-07-25 10:59
471 查看
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)
妈蛋,找了好久!一直以为子类对象不能赋值给父类引用。这部科学啊!
错误代码:
修改:
1.导入的包
2.extends
3.getSurpport……
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 argum
- 错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the argum
- The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, SettingFragment, String)
- The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the argument
- The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the argument
- The method add(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (i
- The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the
- [真理永垂不朽]The method XXX in the type FragmentTransaction is not applicable for the arguments XXX
- Android Error - The method replace(int, Fragment) in the type FragmentTransaction is not applicable
- The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable...
- The method setBackground(Drawable) in the type View is not applicable for the arguments (int)
- 提示错误:The method replace in the type.. is not applicable for the argument......
- The method add(Fragment) in the type ArrayList<Fragment> is not applicable for the arguments (ImageF
- The method replace(int, Fragment) in the type FragmentTransaction is not app 解决方法
- android学习——The method replace 4000 (int, Fragment) in the type FragmentTransaction is not applicable for t
- The method makeText(Context, int, int) in the type Toast is not applicable for the arguments (new Vi
- The method replace(int, Fragment) in the type FragmentTransaction is not applica
- The method setStatus(int) in the type Goods is not applicable for the arguments (Integer)
- The method replace(int, Fragment) in the type FragmentTransaction is not applica
- .replace(R.id.container, new User()).commit();/The method replace(int, Fragment) in the type FragmentTransaction is not app