获取SuperNotCalledException按回键

时间:2013-06-10 06:35:37

标签: android

我的android应用程序中有这个类:

public class Academic extends Activity {
String reg, regi, name, course, branch, sem, subjects, present, total,
        batch, success;
GetHttp student;
JSONObject returned;
private ProgressDialog pDialog;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.academic);
    SharedPreferences app_preferences = PreferenceManager
            .getDefaultSharedPreferences(this);
    reg = app_preferences.getString("Registration", null);
    student = new GetHttp();
    new studentDetails().execute();
}

public void onPause() {
    this.finish();
}

class studentDetails extends AsyncTask<String, String, String> {
       //get JSON data and display
}
}

当我回击时,我得到了这个例外:

  

android.app.SuperNotCalledException:Activity {com.erp.centurion / com.erp.centurion.Academic}没有调用super.onPause()

请帮忙查找我收到此错误的原因。提前谢谢。

5 个答案:

答案 0 :(得分:1)

更改为:

public void onPause() {

    **super.onPause()**
    this.finish();
}

只是,在onPause中完成活动很奇怪。你为什么这样做?

答案 1 :(得分:1)

一旦你的onPause开始呼叫super.onPause()。这可能会为您解决问题。

答案 2 :(得分:1)

onPause方法中,您必须致电super.onPause()

public void onPause() {
    super.onPause();
    this.finish();
}

当覆盖某些功能(如Activity pausing)时,需要允许超类实现进行处理。你得到的SuperNotCalledException有你需要的所有提示,以确定哪种方法是罪魁祸首。

答案 3 :(得分:1)

更改onPause()方法
public void onPause() {
    this.finish();
}

public void onPause() {
  super.onPause();
    this.finish();
}

答案 4 :(得分:1)

使用这种方式

public void onPause() {
  super.onPause();
    finish();
}