Jump to content

Help! Android java keeps crashing

Go to solution Solved by Sergio45,
package com.ebookfrenzy.secretshoppers;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;

public class SecretShoppers extends AppCompatActivity
{
   // private static final String THE_NAME="THE_NAME";
//    private static final String THE_COMMENTS="THE COMMENTS";
  //  private static final String THE_SCORE="THE_SCORE";

    private double scoreBeforeSubmit;//the score if the user has not
    //pressed the submit button to get the score.
    //private double currentScore;//the score that is currently being counted.

  //  private double finalScore;//the end score


    EditText establishmentName;//name of the place
    EditText commentBoxText;//the comments the user enters
    EditText currentScore;//the current score

    private int [] checklistValues = new int [21];//19 values
    //for the check boxes and , radio, spinner


    CheckBox happyCheckBox;//happy_checkBox
    CheckBox fairCheckbox;//fair_checkBox
    CheckBox annoyedCheckbox;//annoyed_checkBox
    CheckBox veryCheckbox;//very_CheckBox
    CheckBox notveryCheckBox;//not_CheckBox
    CheckBox neededhelpCheckBox;//needed_help_CheckBox

    RadioGroup HelpRadioGroup;//employeeHelpRadioGroup
    RadioButton yesRadioButton;//yes_radioButton
    RadioButton noRadioButton;//no_radioButton
    RadioButton askRadioButtonl;//ask_RadioButton;

    Spinner ratingScaleSpinner;

    Button submitButton;//submitButton
    Button clearButton;//clearButton
    private String Textbox;
    private String TextboxTwo;
    private String colorChangerText;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_secret_shoppers);

        if(savedInstanceState == null)
        {
            //just started
            scoreBeforeSubmit=0;
           // currentScore = 0;

        }
        else
        {
            //app is being restored
           // scoreBeforeSubmit=savedInstanceState.getDouble(THE_SCORE);
            //currentScore=savedInstanceState.getDouble(THE_SCORE);


        }

        //initialize the edit texts
        establishmentName = (EditText) findViewById(R.id.nameEstablishmentEditText);
        commentBoxText = (EditText)findViewById(R.id.commentEditText);
        currentScore = (EditText)findViewById(R.id.currentScoreEditText);

        //initialize the seekbar and add a change listener
        happyCheckBox=(CheckBox)findViewById(R.id.happyCheckBox);//happy_checkBox
        fairCheckbox=(CheckBox)findViewById(R.id.fairCheckBox);//fair_checkBox
        annoyedCheckbox=(CheckBox)findViewById(R.id.annoyedCheckBox);//annoyed_checkBox
        ////////////////////////////////////////
        veryCheckbox=(CheckBox)findViewById(R.id.veryCheckBox);//very_CheckBox
        notveryCheckBox=(CheckBox)findViewById(R.id.notCheckBox);//not_CheckBox
        neededhelpCheckBox=(CheckBox)findViewById(R.id.neededHelpCheckBox);//needed_help_CheckBox

        setUpEmployeeAttiude();
        setupKnowledge();


        yesRadioButton = (RadioButton)findViewById(R.id.yesRadioButton);//yes_radioButton
        noRadioButton= (RadioButton)findViewById(R.id.noRadioButton);//no_radioButton
        askRadioButtonl= (RadioButton)findViewById(R.id.askRadioButton);//ask_RadioButton;


       HelpRadioGroup = (RadioGroup) findViewById(R.id.employeeHelpRadioGroup);

        addChangeListenerToRadios();

        ratingScaleSpinner=(Spinner)findViewById(R.id.ratingScaleSpinner);
        ratingScaleSpinner.setPrompt("First Impression Rating");

       addItemSelectedListenerToSpinner();

        submitButton = (Button)findViewById(R.id.submitButton);
        clearButton = (Button)findViewById(R.id.clearButton);

        setupButtonOnClickListeners();
        setTipFromWaitressChecklist();

    }


    private void setUpEmployeeAttiude()
    {

        happyCheckBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
        {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                checklistValues[0] = (happyCheckBox.isChecked())?60:0;
                setTipFromWaitressChecklist();

            }
        });



        fairCheckbox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
        {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                checklistValues[1]= (fairCheckbox.isChecked())?0:0;
                //updateFinalScore();
                setTipFromWaitressChecklist();
            }
        });


        annoyedCheckbox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
        {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                checklistValues[2]= (annoyedCheckbox.isChecked())?-10:0;
                //updateFinalScore();
                setTipFromWaitressChecklist();
            }
        });



    }


    private void setupKnowledge()
    {
        veryCheckbox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
        {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                checklistValues[3] = (veryCheckbox.isChecked())?20:0;
                //updateFinalScore();
                setTipFromWaitressChecklist();

            }
        });

        notveryCheckBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
        {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                checklistValues[4] = (notveryCheckBox.isChecked())?-10:0;
                //updateFinalScore();
                setTipFromWaitressChecklist();
            }
        });

        neededhelpCheckBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
        {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                checklistValues[5] = (neededhelpCheckBox.isChecked())?-10:0;
                //updateFinalScore();
                setTipFromWaitressChecklist();

            }
        });

    }



    private void setTipFromWaitressChecklist()
    {
        int checklistTotal = 0;
        // Cycle through all the checklist values to calculate
        // a total amount based on waitress performance
        for(int item : checklistValues)
        {
            checklistTotal += item;
        }
        // Set tipAmountET
        currentScore.setText(new String(String.valueOf(checklistTotal)));
    }



    private void addChangeListenerToRadios()//yesRadioButton noRadioButton askRadioButtonl
    {
        HelpRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
        {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId)
            {
                checklistValues[6]=(yesRadioButton.isChecked())?10:0;
                checklistValues[7]=(noRadioButton.isChecked())?-40:0;
                checklistValues[8]=(askRadioButtonl.isChecked())?-50:0;

                setTipFromWaitressChecklist();
            }
        });
    }


    private void  addItemSelectedListenerToSpinner()
    {
        ratingScaleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
        {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
            {
                checklistValues[9]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("10"))?10:0;
                checklistValues[10]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("9"))?9:0;
                checklistValues[11]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("8"))?8:0;
                checklistValues[12]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("7"))?7:0;
                checklistValues[13]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("6"))?6:0;
                checklistValues[14]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("5"))?5:0;
                checklistValues[15]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("4"))?4:0;
                checklistValues[16]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("3"))?3:0;
                checklistValues[17]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("2"))?2:0;
                checklistValues[18]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("1"))?1:0;
                checklistValues[19]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("0"))?-1:0;
                setTipFromWaitressChecklist();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent)
            {

            }
        });
    }



    public void getTheName()
    {
      String name=String.valueOf(establishmentName.getText());
      String addon=" Got the Score of"+" "+currentScore.getText();

        TextboxTwo = establishmentName.getText().toString();

        String empty="Please don't forget to enter a name";

        if (TextboxTwo.matches(""))
        {
            Toast.makeText(this,empty,Toast.LENGTH_LONG).show();
        }
        else
        {
            Toast.makeText(this,name+addon,Toast.LENGTH_LONG).show();
            currentScore.setTextColor(Color.parseColor("#f44242"));

        }



    }

    public void getTheComments()
    {
        Textbox = commentBoxText.getText().toString();
        String empty="Please don't forget to enter some comments.";
        String comments = "Thanks for the comment(s), we will keep them in our records";
        if (Textbox.matches(""))
        {
         Toast.makeText(this,empty,Toast.LENGTH_LONG).show();
        }
        else
        {
            Toast.makeText(this, comments, Toast.LENGTH_LONG).show();

            commentBoxText.setText("");
        }
    }



   private void setupButtonOnClickListeners()
    {
        submitButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
             getTheName();
                getTheComments();


                       //currentScore.setText(new String(String.valueOf(checklistTotal)));
            }
        });


        clearButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                establishmentName.setText("");
                commentBoxText.setText("");
                currentScore.setText("");

            }
        });
    }




}

 

I am just building the methods for the me to work on the project later this week. I started adding EventListeners and now the emulator won't run the code. Its keep crashing. I was wondering if it was something if its possible to see the error if I post the java file code here? 

Thanks in advanced guys and girls. 

package com.ebookfrenzy.secretshopper;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;

public class SecretShopperActivity extends AppCompatActivity {

    //the sume of all radio buttons and check boxes.
    private int[]checklistValues=new int[15];//100 is the max points you can get.




    //Declare the checkboxes.
    CheckBox happyCheckBox;
    CheckBox annoyedCheckBox;
    CheckBox fairCheckBox;




    //Declare the RadioButtons
    RadioGroup yesNoRadioGroupBox;
    RadioButton yesRadioButton;
    RadioButton noRadioButton;
    RadioButton askRadioButton;


    //Declare the spinner
    Spinner ratingScaleSpinner;

    //Declare the Buttons
    Button submitButton;
    Button clearButton;
    Button exitButton;

    //EditText for the Results and Name
    EditText FinalscoreEditTextView;
    EditText CurrentscoreEditTextView;
    EditText nameEstablishmentEditTextView;

    //name of the establishment
    private static final String NAME_ESTABLISHMENT="NAME_ESTABLISHMENT";
    private static final String Final_Score="FINAL_SCORES";
    private static final String Current_Score="CURRENT_SCORES";
    private double scoreCurrentRating;//the score before the user adds ratings
    private double scoreFinalRating;//the score for FINAL SCORE.




    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_secret_shopper);


        //check if the app has started, or if its being restored

        if(savedInstanceState == null)
        {
            //just started
            scoreCurrentRating=0;
            scoreFinalRating=0;
        }
        else
        {
            //app is being restored
            scoreCurrentRating=savedInstanceState.getDouble(Current_Score);
            scoreFinalRating=savedInstanceState.getDouble(Final_Score);

        }


        FinalscoreEditTextView = (EditText)findViewById(R.id.finalScoreEditText);
        CurrentscoreEditTextView = (EditText)findViewById(R.id.currentScoreEditText);
        nameEstablishmentEditTextView = (EditText)findViewById(R.id.nameEstablishmentEditTextView);
        //change listener for edit text views


        happyCheckBox = (CheckBox) findViewById(R.id.happyCheckBox);
        annoyedCheckBox= (CheckBox) findViewById(R.id.annoyedCheckBox);
        fairCheckBox= (CheckBox) findViewById(R.id.fairCheckBox);
        //change listener for check boxes
        setUpCheckBoxes();

        yesRadioButton=(RadioButton)findViewById(R.id.yesRadioButton);
        noRadioButton = (RadioButton)findViewById(R.id.noRadioButton);
        askRadioButton = (RadioButton)findViewById(R.id.iAskedRadioButton);
        //change listener for cradio buttons
        addChangeListenerToRadios();


        yesNoRadioGroupBox=(RadioGroup)findViewById(R.id.yesNoRadioGroupBox);


        ratingScaleSpinner = (Spinner)findViewById(R.id.ratingScaleSpinner);
        ratingScaleSpinner.setPrompt("Rateing Scale");


        addItemSelectedListenerToSpinner();


        submitButton = (Button)findViewById(R.id.submitButton);
        clearButton = (Button) findViewById(R.id.clearButton);
        exitButton = (Button) findViewById(R.id.exitButton);

        setButtonOnClickListeners();



    }

    private void setUpCheckBoxes()
    {
        happyCheckBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
        {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                checklistValues[0]= (happyCheckBox.isChecked())?10:0;

                //setup the current score
                //currentScoreCheckList();


            }
        });


        annoyedCheckBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
        {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                checklistValues[1] = (annoyedCheckBox.isChecked())?1:0;

                //setup the current score
                //currentScoreCheckList();
            }
        });




        fairCheckBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
        {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                checklistValues[2]= (fairCheckBox.isChecked())?2:0;

                //setup the current score
                //currentScoreCheckList();
            }
        });


    }//might end wrong here



    private void addChangeListenerToRadios()
    {
        yesNoRadioGroupBox.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
        {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId)
            {
                checklistValues[3]=(yesRadioButton.isChecked())?10:0;
                checklistValues[4]=(noRadioButton.isChecked())?0:0;
                checklistValues[5]=(askRadioButton.isChecked())?-1:0;

                //Setup Current score
                //setup final score
            }
        });
    }


        private void addItemSelectedListenerToSpinner()
    {
        ratingScaleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
        {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
            {
                checklistValues[6]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("10 Best"))?10:0;
                checklistValues[7]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("9"))?9:0;
                checklistValues[8]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("8"))?8:0;
                checklistValues[9]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("7"))?7:0;
                checklistValues[10]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("6"))?6:0;
                checklistValues[11]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("5"))?5:0;
                checklistValues[12]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("4"))?4:0;
                checklistValues[13]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("3"))?3:0;
                checklistValues[14]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("2"))?2:0;
                checklistValues[15]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("1 Horrible"))?-1:0;


                //setup the current score
                //setup the final score



            }

            @Override
            public void onNothingSelected(AdapterView<?> parent)
            {

            }
        });
    }


    private void setButtonOnClickListeners()
    {
        submitButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                //set up the final score here
                //display it to the final score edit text
                //use the current score and change current score text
                //to blank
            }
        });


        clearButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                //erase the edittextviews of Current and Final
                //uncheck the boxes and radio and spinner
                //erase the name
                //focus back on the name
                //set the score back to zero

            }
        });

        exitButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                //finish();
                //System.exit(0);

            }
        });


    }





}

 

Link to comment
https://linustechtips.com/topic/684911-help-android-java-keeps-crashing/
Share on other sites

Link to post
Share on other sites

I might have to do this one slow. I the logcat can not catch anything because it dosen't even run. I did find this :

 

FATAL EXCEPTION: main
                                                                             Process: com.ebookfrenzy.secretshopper, PID: 9298
                                                                             java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ebookfrenzy.secretshopper/com.ebookfrenzy.secretshopper.SecretShopperActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.RadioGroup.setOnCheckedChangeListener(android.widget.RadioGroup$OnCheckedChangeListener)' on a null object reference
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
                                                                                 at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                 at android.os.Looper.loop(Looper.java:135)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                                 at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
                                                                              Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.RadioGroup.setOnCheckedChangeListener(android.widget.RadioGroup$OnCheckedChangeListener)' on a null object reference
                                                                                 at com.ebookfrenzy.secretshopper.SecretShopperActivity.addChangeListenerToRadios(SecretShopperActivity.java:178)
                                                                                 at com.ebookfrenzy.secretshopper.SecretShopperActivity.onCreate(SecretShopperActivity.java:101)
                                                                                 at android.app.Activity.performCreate(Activity.java:5990)
                                                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
                                                                                 at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                 at android.os.Looper.loop(Looper.java:135) 
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5254) 
                                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                                 at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
11-02 17:13:08.091 1497-2225/system_process W/ActivityManager:   Force finishing activity 1 com.ebookfrenzy.secretshopper/.SecretShopperActivity
11-02 17:13:08.303 1123-1123/? E/EGL_emulation: tid 1123: eglCreateSyncKHR(1299): error 0x3004 (EGL_BAD_ATTRIBUTE)

______________________________________

I will go into this and start fixing the cause by errors. 

 

I did change the array to 14. 

Edited by Sergio45
FAT FINGERS
Link to post
Share on other sites

Your yesNoRadioGroupBox inside addChangeListenerToRadios() seems to be null, and it is because you first call addChangeListenerToRadios and then you assign radiogroup do variable here:

 

        addChangeListenerToRadios();


        yesNoRadioGroupBox=(RadioGroup)findViewById(R.id.yesNoRadioGroupBox);

 

Link to post
Share on other sites

Ok. So what was causing the error was the array for the checklistValues under the method. I have commented them out and let you guys know what I find with the log cat.

41 minutes ago, Sergio45 said:

private void addItemSelectedListenerToSpinner() { ratingScaleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { checklistValues[6]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("10 Best"))?10:0; checklistValues[7]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("9"))?9:0; checklistValues[8]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("8"))?8:0; checklistValues[9]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("7"))?7:0; checklistValues[10]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("6"))?6:0; checklistValues[11]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("5"))?5:0; checklistValues[12]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("4"))?4:0; checklistValues[13]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("3"))?3:0; checklistValues[14]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("2"))?2:0; checklistValues[15]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("1 Horrible"))?-1:0; //setup the current score //setup the final score } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }

 

Link to post
Share on other sites

2 minutes ago, Mr_KoKa said:

Your yesNoRadioGroupBox inside addChangeListenerToRadios() seems to be null, and it is because you first call addChangeListenerToRadios and then you assign radiogroup do variable here:

 


        addChangeListenerToRadios();


        yesNoRadioGroupBox=(RadioGroup)findViewById(R.id.yesNoRadioGroupBox);

 

I see and when I did comment that back in also it did crash the application. hmmmm. let me see if I can change that . 

Link to post
Share on other sites

I move the addChange and addItem call methods to the submit button. From there I am going to see if I can get LogCat going.

 private void setButtonOnClickListeners() {
        submitButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //set up the final score here
                //display it to the final score edit text
                //use the current score and change current score text
                //to blank


                addChangeListenerToRadios();
                addItemSelectedListenerToSpinner();
            }
        });

 

Link to post
Share on other sites

I got the code working, I had a method that was expecting a Edit-text  to be initialize with something in the beginning. I found the error by re-building the application and adding on to it. I was actually pretty glad that it crashed because it gave me the opportunity to re-think my approach on the code. I will post the java portion of the code when I get home.it's almost done just have to clean it up a bit. I just added more check boxes .

Link to post
Share on other sites

package com.ebookfrenzy.secretshoppers;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;

public class SecretShoppers extends AppCompatActivity
{
   // private static final String THE_NAME="THE_NAME";
//    private static final String THE_COMMENTS="THE COMMENTS";
  //  private static final String THE_SCORE="THE_SCORE";

    private double scoreBeforeSubmit;//the score if the user has not
    //pressed the submit button to get the score.
    //private double currentScore;//the score that is currently being counted.

  //  private double finalScore;//the end score


    EditText establishmentName;//name of the place
    EditText commentBoxText;//the comments the user enters
    EditText currentScore;//the current score

    private int [] checklistValues = new int [21];//19 values
    //for the check boxes and , radio, spinner


    CheckBox happyCheckBox;//happy_checkBox
    CheckBox fairCheckbox;//fair_checkBox
    CheckBox annoyedCheckbox;//annoyed_checkBox
    CheckBox veryCheckbox;//very_CheckBox
    CheckBox notveryCheckBox;//not_CheckBox
    CheckBox neededhelpCheckBox;//needed_help_CheckBox

    RadioGroup HelpRadioGroup;//employeeHelpRadioGroup
    RadioButton yesRadioButton;//yes_radioButton
    RadioButton noRadioButton;//no_radioButton
    RadioButton askRadioButtonl;//ask_RadioButton;

    Spinner ratingScaleSpinner;

    Button submitButton;//submitButton
    Button clearButton;//clearButton
    private String Textbox;
    private String TextboxTwo;
    private String colorChangerText;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_secret_shoppers);

        if(savedInstanceState == null)
        {
            //just started
            scoreBeforeSubmit=0;
           // currentScore = 0;

        }
        else
        {
            //app is being restored
           // scoreBeforeSubmit=savedInstanceState.getDouble(THE_SCORE);
            //currentScore=savedInstanceState.getDouble(THE_SCORE);


        }

        //initialize the edit texts
        establishmentName = (EditText) findViewById(R.id.nameEstablishmentEditText);
        commentBoxText = (EditText)findViewById(R.id.commentEditText);
        currentScore = (EditText)findViewById(R.id.currentScoreEditText);

        //initialize the seekbar and add a change listener
        happyCheckBox=(CheckBox)findViewById(R.id.happyCheckBox);//happy_checkBox
        fairCheckbox=(CheckBox)findViewById(R.id.fairCheckBox);//fair_checkBox
        annoyedCheckbox=(CheckBox)findViewById(R.id.annoyedCheckBox);//annoyed_checkBox
        ////////////////////////////////////////
        veryCheckbox=(CheckBox)findViewById(R.id.veryCheckBox);//very_CheckBox
        notveryCheckBox=(CheckBox)findViewById(R.id.notCheckBox);//not_CheckBox
        neededhelpCheckBox=(CheckBox)findViewById(R.id.neededHelpCheckBox);//needed_help_CheckBox

        setUpEmployeeAttiude();
        setupKnowledge();


        yesRadioButton = (RadioButton)findViewById(R.id.yesRadioButton);//yes_radioButton
        noRadioButton= (RadioButton)findViewById(R.id.noRadioButton);//no_radioButton
        askRadioButtonl= (RadioButton)findViewById(R.id.askRadioButton);//ask_RadioButton;


       HelpRadioGroup = (RadioGroup) findViewById(R.id.employeeHelpRadioGroup);

        addChangeListenerToRadios();

        ratingScaleSpinner=(Spinner)findViewById(R.id.ratingScaleSpinner);
        ratingScaleSpinner.setPrompt("First Impression Rating");

       addItemSelectedListenerToSpinner();

        submitButton = (Button)findViewById(R.id.submitButton);
        clearButton = (Button)findViewById(R.id.clearButton);

        setupButtonOnClickListeners();
        setTipFromWaitressChecklist();

    }


    private void setUpEmployeeAttiude()
    {

        happyCheckBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
        {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                checklistValues[0] = (happyCheckBox.isChecked())?60:0;
                setTipFromWaitressChecklist();

            }
        });



        fairCheckbox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
        {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                checklistValues[1]= (fairCheckbox.isChecked())?0:0;
                //updateFinalScore();
                setTipFromWaitressChecklist();
            }
        });


        annoyedCheckbox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
        {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                checklistValues[2]= (annoyedCheckbox.isChecked())?-10:0;
                //updateFinalScore();
                setTipFromWaitressChecklist();
            }
        });



    }


    private void setupKnowledge()
    {
        veryCheckbox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
        {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                checklistValues[3] = (veryCheckbox.isChecked())?20:0;
                //updateFinalScore();
                setTipFromWaitressChecklist();

            }
        });

        notveryCheckBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
        {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                checklistValues[4] = (notveryCheckBox.isChecked())?-10:0;
                //updateFinalScore();
                setTipFromWaitressChecklist();
            }
        });

        neededhelpCheckBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
        {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                checklistValues[5] = (neededhelpCheckBox.isChecked())?-10:0;
                //updateFinalScore();
                setTipFromWaitressChecklist();

            }
        });

    }



    private void setTipFromWaitressChecklist()
    {
        int checklistTotal = 0;
        // Cycle through all the checklist values to calculate
        // a total amount based on waitress performance
        for(int item : checklistValues)
        {
            checklistTotal += item;
        }
        // Set tipAmountET
        currentScore.setText(new String(String.valueOf(checklistTotal)));
    }



    private void addChangeListenerToRadios()//yesRadioButton noRadioButton askRadioButtonl
    {
        HelpRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
        {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId)
            {
                checklistValues[6]=(yesRadioButton.isChecked())?10:0;
                checklistValues[7]=(noRadioButton.isChecked())?-40:0;
                checklistValues[8]=(askRadioButtonl.isChecked())?-50:0;

                setTipFromWaitressChecklist();
            }
        });
    }


    private void  addItemSelectedListenerToSpinner()
    {
        ratingScaleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
        {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
            {
                checklistValues[9]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("10"))?10:0;
                checklistValues[10]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("9"))?9:0;
                checklistValues[11]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("8"))?8:0;
                checklistValues[12]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("7"))?7:0;
                checklistValues[13]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("6"))?6:0;
                checklistValues[14]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("5"))?5:0;
                checklistValues[15]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("4"))?4:0;
                checklistValues[16]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("3"))?3:0;
                checklistValues[17]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("2"))?2:0;
                checklistValues[18]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("1"))?1:0;
                checklistValues[19]=(String.valueOf(ratingScaleSpinner.getSelectedItem()).equals("0"))?-1:0;
                setTipFromWaitressChecklist();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent)
            {

            }
        });
    }



    public void getTheName()
    {
      String name=String.valueOf(establishmentName.getText());
      String addon=" Got the Score of"+" "+currentScore.getText();

        TextboxTwo = establishmentName.getText().toString();

        String empty="Please don't forget to enter a name";

        if (TextboxTwo.matches(""))
        {
            Toast.makeText(this,empty,Toast.LENGTH_LONG).show();
        }
        else
        {
            Toast.makeText(this,name+addon,Toast.LENGTH_LONG).show();
            currentScore.setTextColor(Color.parseColor("#f44242"));

        }



    }

    public void getTheComments()
    {
        Textbox = commentBoxText.getText().toString();
        String empty="Please don't forget to enter some comments.";
        String comments = "Thanks for the comment(s), we will keep them in our records";
        if (Textbox.matches(""))
        {
         Toast.makeText(this,empty,Toast.LENGTH_LONG).show();
        }
        else
        {
            Toast.makeText(this, comments, Toast.LENGTH_LONG).show();

            commentBoxText.setText("");
        }
    }



   private void setupButtonOnClickListeners()
    {
        submitButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
             getTheName();
                getTheComments();


                       //currentScore.setText(new String(String.valueOf(checklistTotal)));
            }
        });


        clearButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                establishmentName.setText("");
                commentBoxText.setText("");
                currentScore.setText("");

            }
        });
    }




}

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×