日期:2014-05-20  浏览次数:20806 次

点击imageview关闭dialog就报错?
java代码:
Java code

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

public class MyDialog extends Dialog {

    Context context;
    public MyDialog(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        this.context = context;
    }
    public MyDialog(Context context, int theme){
        super(context, theme);
        this.context = context;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.dialog);
        ImageView imageview = (ImageView)findViewById(R.id.imageviewClose);
        imageview.setOnClickListener(new View.OnClickListener() {
            
            public void onClick(View v) {
                dismiss();
            }
        });
    }
     
    public void dismiss(){
        this.cancel();
    }
}



log:
Java code

08-17 15:32:42.080: E/AndroidRuntime(1326): FATAL EXCEPTION: main
08-17 15:32:42.080: E/AndroidRuntime(1326): java.lang.StackOverflowError
08-17 15:32:42.080: E/AndroidRuntime(1326):     at com.xiuman.mydialog.MyDialog.dismiss(MyDialog.java:37)
08-17 15:32:42.080: E/AndroidRuntime(1326):     at android.app.Dialog.cancel(Dialog.java:951)
08-17 15:32:42.080: E/AndroidRuntime(1326):     at com.xiuman.mydialog.MyDialog.dismiss(MyDialog.java:37)
08-17 15:32:42.080: E/AndroidRuntime(1326):     at android.app.Dialog.cancel(Dialog.java:951)
08-17 15:32:42.080: E/AndroidRuntime(1326):     at com.xiuman.mydialog.MyDialog.dismiss(MyDialog.java:37)
08-17 15:32:42.080: E/AndroidRuntime(1326):     at android.app.Dialog.cancel(Dialog.java:951)
08-17 15:32:42.080: E/AndroidRuntime(1326):     at com.xiuman.mydialog.MyDialog.dismiss(MyDialog.java:37)
08-17 15:32:42.080: E/AndroidRuntime(1326):     at android.app.Dialog.cancel(Dialog.java:951)




------解决方案--------------------
用android 1.6以上试试看。
你用的1.5的??
------解决方案--------------------
这是内存溢出错误,应该是出现死循环或者无限递归了,错误中你的MyDialog.java:37不断的被执行,你看一下是不是哪里出项递归了