android中的noSuchMethod错误

时间:2012-12-29 18:15:27

标签: android runtime-error nosuchmethoderror

我使用片段:

FragmentManager manager = getFragmentManager();

但我在log cat中看到了这个错误:

12-30 21:14:05.500: E/AndroidRuntime(395): 
java.lang.NoSuchMethodError:my.com.daily.Sign_upActivity.getFragmentManager

我的活动是:

public class sign_upActivity extends Activity implements AlertPositiveListener{

public String fonts="BZar.ttf";
private EditText fname,lname,birthdate,worktitle,company,username,pass,confpass,email,phone,phone1;
private Button signup;
private String gender;
private String education ,regiterDate,howIMF,expdate,active,picpath,deleted , expertise;
private RadioGroup radioGenderGroup;
private RadioButton radioGenderButton;
private Drawable error_indicator;
int position = 0;
int position1 = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sign_up);

    OnClickListener listener = new OnClickListener() {          
        @Override
        public void onClick(View v) {

            FragmentManager manager = getFragmentManager();
            AlertDialogRadio alert = new AlertDialogRadio();
            Bundle b  = new Bundle();
            b.putInt("position", position);
            alert.setArguments(b);
            alert.show(manager, "alert_dialog_radio");

        }
    };      

    Button btn = (Button) findViewById(R.id.education_btn);
    btn.setOnClickListener(listener);
}

@Override
public void onPositiveClick(int position) {
    this.position = position;
    TextView tv1 = (TextView) findViewById(R.id.education_tv);
    tv1.setText(Education.code[this.position]); 
    education = Education.code[this.position];
}

}

谁能告诉我是什么原因?

非常感谢。我的问题在模拟器中得到了解决,但它在电话中强行关闭!我使用minSdkVersion =“4”

3 个答案:

答案 0 :(得分:1)

FragmentManager仅来自api 11级。我猜您正在部署在不支持此功能的旧设备上。

查看tutorial

答案 1 :(得分:1)

您正在使用低于版本11的最低API。片段是在API 11中添加的,但它们可通过支持库下载到API 4.但是有一些差异,例如您必须扩展FragmentActivity才能访问FragmentManager:

public class sign_upActivity extends FragmentActivity ... 

另一个区别是您必须在支持库中使用getSupportFragmentManager()

答案 2 :(得分:0)

你使用api小于11.由于这些你得到错误。 FragmentManaget.getFragmentManger();在Api等级11之前不支持该方法。

上也没有添加getFragmentManager()方法

兼容性库