错误java.lang.StackOverflowError:堆栈大小为8MB

时间:2017-07-13 15:33:55

标签: java android

我有一个错误的堆栈大小。我不知道这个错误。因为我在另一个android工作室编译这个项目。它工作正常。但现在不再工作,我得到了这个错误。当我在我的电台组中选择一个选项时,将显示此错误。我有2个无线电组和编辑文本,当我从一个无线电组中选择数据时,另一个无线电组中的另一个选项和edittext将被清除。但是我在setOnCheckedChangeListener函数的明确部分中遇到了错误。请帮我。谢谢 ChargeFragment.java

public class ChargeFragment extends Fragment {
CustomerPreference customerPreference;
DiscountPeferences discountPeferences;
CartPreference cartPreference;
SessionManagement sessionManagement;
DatabaseHandler db;
List<CartModel> cart;
List<Discount> dp;

Fragment fragment = null;

Button Charge,Cancel;
RadioButton rb1,rb2,rbEdc,rbOther,rbPay1,rbPay2,rbPay3;
RadioGroup rg,rOther,rgPay;
TextView tvTotal;
EditText edCard,edCash;
public ChargeFragment() {
    // Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootview = inflater.inflate(R.layout.layout_charge, container, false);

    sessionManagement = new SessionManagement(getActivity());
    db = new DatabaseHandler(getActivity());
    cartPreference = new CartPreference();
    customerPreference = new CustomerPreference(getActivity());
    discountPeferences = new DiscountPeferences();
    cart = cartPreference.getFavorites(getActivity());
    dp = discountPeferences.getFavorites(getActivity());

    Bundle bun=this.getArguments();
    final int total=bun.getInt("total");

    tvTotal = (TextView) rootview.findViewById(R.id.tvTotal);
    rg = (RadioGroup) rootview.findViewById(R.id.radioChoose);
    rb1 = (RadioButton) rootview.findViewById(R.id.rd1);
    rb2 = (RadioButton) rootview.findViewById(R.id.rd2);
    rOther = (RadioGroup) rootview.findViewById(R.id.radioOther);
    rgPay = (RadioGroup) rootview.findViewById(R.id.rgPay);
    rbEdc = (RadioButton) rootview.findViewById(R.id.rdEdc);
    rbOther = (RadioButton) rootview.findViewById(R.id.rdOthr);
    rbPay1 = (RadioButton) rootview.findViewById(R.id.rdPay1);
    rbPay2 = (RadioButton) rootview.findViewById(R.id.rdPay2);
    rbPay3 = (RadioButton) rootview.findViewById(R.id.rdPay3);
    Charge = (Button) rootview.findViewById(R.id.buttonCharge);
    Cancel = (Button) rootview.findViewById(R.id.buttonCancel);
    edCard = (EditText) rootview.findViewById(R.id.edCard);
    edCash = (EditText) rootview.findViewById(R.id.edCash);


    int x = Math.round((total + 900)/1000 * 1000);
    int y = Math.round((total + 9000)/10000 * 10000);
    rbPay1.setText(""+total);
    rbPay2.setText(""+x);
    rbPay3.setText(""+y);

    final DecimalFormat kursIndonesia = (DecimalFormat) DecimalFormat.getCurrencyInstance();
    DecimalFormatSymbols formatRp = new DecimalFormatSymbols();
    formatRp.setCurrencySymbol("Rp. ");
    formatRp.setMonetaryDecimalSeparator(',');
    formatRp.setGroupingSeparator('.');
    kursIndonesia.setDecimalFormatSymbols(formatRp);

    tvTotal.setText(""+kursIndonesia.format(total));

    edCard.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            rOther.clearCheck();
            rbEdc.setTextColor(Color.RED);
            rbOther.setTextColor(Color.RED);
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

    edCash.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            rg.clearCheck();
            rb1.setTextColor(Color.RED);
            rb2.setTextColor(Color.RED);

            rOther.clearCheck();
            rbEdc.setTextColor(Color.RED);
            rbOther.setTextColor(Color.RED);

        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

    rgPay.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup radioGroup, int i) {
            if(rbPay1.isChecked())
                edCash.setText(rbPay1.getText().toString());
            if(rbPay2.isChecked())
                edCash.setText(rbPay2.getText().toString());
            if(rbPay3.isChecked())
                edCash.setText(rbPay3.getText().toString());
        }
    });

    rOther.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup radioGroup, int i) {

            rgPay.clearCheck();
            //edCash.setText("");
            if (rbEdc.isChecked()) {
                rbEdc.setTextColor(Color.WHITE);
                rbOther.setTextColor(Color.RED);

            }
            if (rbOther.isChecked()){
                rbEdc.setTextColor(Color.RED);
                rbOther.setTextColor(Color.WHITE);

            }
        }
    });

    rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup radioGroup, int i) {

           // rOther.clearCheck();
            rbEdc.setTextColor(Color.RED);
            rbOther.setTextColor(Color.RED);
            edCash.setText("");
            if (rb1.isChecked()) {
                rb1.setTextColor(Color.WHITE);
                rb2.setTextColor(Color.RED);

            }
            if (rb2.isChecked()){
                rb1.setTextColor(Color.RED);
                rb2.setTextColor(Color.WHITE);

            }
        }
    });

    Cancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            getActivity().onBackPressed();
        }
    });
    Charge.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            int last=1;

            String method = "", pay = "";
            if (!edCash.getText().toString().equals("")) {
                method = "Cash";
                pay = edCash.getText().toString();
            } else if (!edCard.getText().toString().equals("")) {
                method = "Debit/Credit";
                pay = "" + total;
            } else if (edCard.getText().toString().equals("") && edCash.getText().toString().equals("")) {
                if (rbEdc.isChecked()) {
                    method = "EDC";
                } else if (rbOther.isChecked()) {
                    method = "Other";
                }
                pay = "" + total;
            }
            String cardNo = "";
            if (edCard.getText().equals(""))
                cardNo = "";
            else {
                cardNo = edCard.getText().toString();
            }

            if(method.equals(""))
            {
                Toast.makeText(getActivity(),"Choose Payment Method Please !",Toast.LENGTH_SHORT).show();
            }
            else {

                String discID = "";
                String discID2 = "";
                int listDiscCount = db.getDiscCount();
                if (dp != null) {
                    discID = db.getMaxIdListDiscount();
                    if (dp.size() > 0) {
                        if (listDiscCount > 0) {
                            discID2 = generateListDiscId(Integer.parseInt(discID.substring(discID.length() - 3)) + 1);
                        } else {
                            discID2 = generateListDiscId(1);
                        }
                        for (Discount d : dp) {
                            String pkDisc;
                            if (listDiscCount == 0)
                                pkDisc = generateIdListDiscPk(1);
                            else {
                                String lastPkDisc = db.getMaxPkIdListDiscount();
                                pkDisc = generateIdListDiscPk(Integer.parseInt(lastPkDisc.substring(lastPkDisc.length() - 3)) + 1);
                            }
                            list_disc_nota ld = new list_disc_nota(pkDisc, discID2, d.getId());
                            db.addListDiscNota(ld);
                        }
                    }
                }

                insertItemNota();


                int total1 = 0;
                for (CartModel cm : cart) {
                    total1 = total1 + Integer.parseInt(cm.getHarga());
                }
                if (dp != null) {
                    if (dp.size() > 0) {
                        InsertNota(method, discID2, cardNo, "" + total1, "" + total);
                    } else
                        InsertNota(method, "0", cardNo, "" + total1, "" + total);
                } else {
                    InsertNota(method, "0", cardNo, "" + total1, "" + total);
                }


                int change = Integer.parseInt(pay) - total;
                String nota = db.getLastNotaID();
                if(method.equals("Debit/Credit"))
                {
                    method="Card";
                }
                showPrint(nota, total, Integer.parseInt(pay), change,method);
            }
        }
    });
    return rootview;
}

错误堆栈

                  Process: com.project.pos.posandroid, PID: 2773
                  java.lang.StackOverflowError: stack size 8MB
                      at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5377)
                      at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
                      at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
                      at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
                      at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
                      at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
                      at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
                      at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
                      at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
                      at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
                      at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
                      at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
                      at android.view.View.getGlobalVisibleRect(View.java:12274)
                      at android.view.View.isVisibleToUser(View.java:6544)
                      at android.view.View.isVisibleToUser(View.java:6502)
                      at android.view.View.onInitializeAccessibilityNodeInfoInternal(View.java:6421)
                      at android.widget.TextView.onInitializeAccessibilityNodeInfoInternal(TextView.java:8978)
                      at android.view.View.onInitializeAccessibilityNodeInfo(View.java:6105)
                      at android.view.View.createAccessibilityNodeInfoInternal(View.java:6064)
                      at android.view.View.createAccessibilityNodeInfo(View.java:6049)
                      at android.view.accessibility.AccessibilityRecord.setSource(AccessibilityRecord.java:145)
                      at android.view.accessibility.AccessibilityRecord.setSource(AccessibilityRecord.java:119)
                      at android.view.View.onInitializeAccessibilityEventInternal(View.java:6001)
                      at android.widget.TextView.onInitializeAccessibilityEventInternal(TextView.java:8963)
                      at android.view.View.onInitializeAccessibilityEvent(View.java:5989)
                      at android.view.View.sendAccessibilityEventUncheckedInternal(View.java:5854)
                      at android.view.View.sendAccessibilityEventUnchecked(View.java:5839)
                      at android.view.View.sendAccessibilityEventInternal(View.java:5816)
                      at android.widget.TextView.sendAccessibilityEventInternal(TextView.java:9163)
                      at android.view.View.sendAccessibilityEvent(View.java:5783)
                      at android.widget.TextView.onSelectionChanged(TextView.java:7943)
                      at android.widget.TextView.spanChange(TextView.java:8160)
                      at android.widget.TextView$ChangeWatcher.onSpanAdded(TextView.java:10252)
                      at android.text.SpannableStringBuilder.sendSpanAdded(SpannableStringBuilder.java:1053)
                      at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:759)
                      at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:658)
                      at android.text.Selection.setSelection(Selection.java:78)
                      at android.text.Selection.setSelection(Selection.java:87)
                      at android.text.method.ArrowKeyMovementMethod.initialize(ArrowKeyMovementMethod.java:325)
                      at android.widget.TextView.setText(TextView.java:4354)
                      at android.widget.TextView.setText(TextView.java:4223)
                      at android.widget.EditText.setText(EditText.java:84)
                      at android.widget.TextView.setText(TextView.java:4198)
                      at com.project.pos.posandroid.Fragment.ChargeFragment$5.onCheckedChanged(ChargeFragment.java:209)
                      at android.widget.RadioGroup.setCheckedId(RadioGroup.java:173)
                      at android.widget.RadioGroup.check(RadioGroup.java:167)
                      at android.widget.RadioGroup.clearCheck(RadioGroup.java:209)
                      at com.project.pos.posandroid.Fragment.ChargeFragment$2.onTextChanged(ChargeFragment.java:155)
                      at android.widget.TextView.sendOnTextChanged(TextView.java:8048)
                      at android.widget.TextView.setText(TextView.java:4369)
                      at android.widget.TextView.setText(TextView.java:4223)
                      at android.widget.EditText.setText(EditText.java:84)
                      at android.widget.TextView.setText(TextView.java:4198)
                      at com.project.pos.posandroid.Fragment.ChargeFragment$5.onCheckedChanged(ChargeFragment.java:209)
                      at android.widget.RadioGroup.setCheckedId(RadioGroup.java:173)
                      at android.widget.RadioGroup.check(RadioGroup.java:167)
                    at android.widget.RadioGroup.clearChec
I/art: Background partial concurrent mark sweep GC freed 5237(654KB) AllocSpace objects, 5(45MB) LOS objects, 22% free, 55MB/71MB, paused 689us total 130.901ms
I/art: Background partial concurrent mark sweep GC freed 71632(8MB) AllocSpace objects, 4(27MB) LOS objects, 23% free, 52MB/68MB, paused 906us total 126.400ms
D/Error: ERR: exClass=java.lang.StackOverflowError
D/Error: ERR: exMsg=stack size 8MB
D/Error: ERR: file=ViewGroup.java
D/Error: ERR: class=android.view.ViewGroup
D/Error: ERR: method=getChildVisibleRect line=5377
I/art: Background sticky concurrent mark sweep GC freed 65308(8MB) AllocSpace objects, 0(0B) LOS objects, 0% free, 85MB/85MB, paused 8.070ms total 84.901ms
D/Error: ERR: stack=java.lang.StackOverflowError: stack size 8MB
             at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5377)
             at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
             at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
             at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
             at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
             at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
             at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
             at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
             at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
             at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
             at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
             at android.view.ViewGroup.getChildVisibleRect(ViewGroup.java:5424)
             at android.view.View.getGlobalVisibleRect(View.java:12274)
             at android.view.View.isVisibleToUser(View.java:6544)
             at android.view.View.isVisibleToUser(View.java:6502)
             at android.view.View.onInitializeAccessibilityNodeInfoInternal(View.java:6421)
             at android.widget.TextView.onInitializeAccessibilityNodeInfoInternal(TextView.java:8978)
             at android.view.View.onInitializeAccessibilityNodeInfo(View.java:6105)
             at android.view.View.createAccessibilityNodeInfoInternal(View.java:6064)
             at android.view.View.createAccessibilityNodeInfo(View.java:6049)
             at android.view.accessibility.AccessibilityRecord.setSource(AccessibilityRecord.java:145)
             at android.view.accessibility.AccessibilityRecord.setSource(AccessibilityRecord.java:119)
             at android.view.View.onInitializeAccessibilityEventInternal(View.java:6001)
             at android.widget.TextView.onInitializeAccessibilityEventInternal(TextView.java:8963)
             at android.view.View.onInitializeAccessibilityEvent(View.java:5989)
             at android.view.View.sendAccessibilityEventUncheckedInternal(View.java:5854)
             at android.view.View.sendAccessibilityEventUnchecked(View.java:5839)
             at android.view.View.sendAccessibilityEventInternal(View.java:5816)
             at android.widget.TextView.sendAccessibilityEventInternal(TextView.java:9163)
             at android.view.View.sendAccessibilityEvent(View.java:5783)
             at android.widget.TextView.onSelectionChanged(TextView.java:7943)
             at android.widget.TextView.spanChange(TextView.java:8160)
             at android.widget.TextView$ChangeWatcher.onSpanAdded(TextView.java:10252)
             at android.text.SpannableStringBuilder.sendSpanAdded(SpannableStringBuilder.java:1053)
             at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:759)
             at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:658)
             at android.text.Selection.setSelection(Selection.java:78)
             at android.text.Selection.setSelection(Selection.java:87)
             at android.text.method.ArrowKeyMovementMethod.initialize(ArrowKeyMovementMethod.java:325)
             at android.widget.TextView.setText(TextView.java:4354)
             at android.widget.TextView.setText(TextView.java:4223)
             at android.widget.EditText.setText(EditText.java:84)
             at android.widget.TextView.setText(TextView.java:4198)
             at com.project.pos.posandroid.Fragment.ChargeFragment$5.onCheckedChanged(ChargeFragment.java:209)
             at android.widget.RadioGroup.setCheckedId(RadioGroup.java:173)
             at android.widget.RadioGroup.check(RadioGroup.java:167)
             at android.widget.RadioGroup.clearCheck(RadioGroup.java:209)
             at com.project.pos.posandroid.Fragment.ChargeFragment$2.onTextChanged(ChargeFragment.java:155)
             at android.widget.TextView.sendOnTextChanged(TextView.java:8048)
             at android.widget.TextView.setText(TextView.java:4369)
             at android.widget.TextView.setText(TextView.java:4223)
             at android.widget.EditText.setText(EditText.java:84)
             at android.widget.TextView.setText(TextView.java:4198)
             at com.project.pos.posandroid.Fragment.ChargeFragment$5.onCheckedChanged(ChargeFragment.java:209)
             at android.widget.RadioGroup.setCheckedId(RadioGroup.java:173)
             at android.widget.RadioGroup.check(RadioGroup.java:167)
             at android.widget.RadioGroup.clearCheck(RadioGroup.java:209)
            at com.project.pos.posandroid.Fragment.Char
D/Error: ERR: TOTAL BYTES WRITTEN: 10556588
E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!  (parcel size = 10556680)
E/AndroidRuntime: Error reporting crash
                  android.os.TransactionTooLargeException: data parcel size 10556680 bytes
                      at android.os.BinderProxy.transactNative(Native Method)
                      at android.os.BinderProxy.transact(Binder.java:503)
                      at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:4463)
                      at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:90)
                      at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
                      at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
I/Process: Sending signal. PID: 2773 SIG: 9

1 个答案:

答案 0 :(得分:0)

有效的代码就像没有中断条件的while循环一样工作。 在edCash检查的更改侦听器中,您调用rg.clearCheck(),其中inturn将调用rg的oncheckchange lsitener。在已检查的更改侦听器的rg中,您正在为edCach设置设置文本,而edCach又将在文本更改列表器上调用edCash。对于程序化的更改,传递null和&之间的切换。这些小部件的列表器,以避免循环

例如:

@Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            rg.setOnCheckedChangeListner(null);
            rg.clearCheck();
            rg.setOnCheckedChangeListner(yourCheckBoxListner);
            rbEdc.setTextColor(Color.RED);
            rbOther.setTextColor(Color.RED);
        }
And for rg
  @Override
        public void onCheckedChanged(RadioGroup radioGroup, int i) {

        rbEdc.setTextColor(Color.RED);
        rbOther.setTextColor(Color.RED);
        edCash.setonTextChangeListener(null);
        edCash.setText("");
        edCash.setOnTextChangeListner(youTextChangeListner);

rg.setoncheckChangeListner(yourCheckBoxListner);

WHERE yourCheckBoxListner would be like.-->
    RadioGroup.OnCheckChangeListner yourCheckBoxListner = new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) { 
       //yourlogic  like below. 
     rbEdc.setTextColor(Color.RED);
                rbOther.setTextColor(Color.RED);
                edCash.setonTextChangeListener(null);
                edCash.setText("");
                edCash.setOnTextChangeListner(youTextChangeListner);
    }

同样为edCash做同样的事。