1. Are you ready for the Galaxy S20? Here is everything we know so far!

Activity crashing but I don't know why

Discussion in 'Android Development' started by iliji, Mar 24, 2021.

  1. iliji

    iliji Lurker
    Thread Starter

    Hello guys, as I said the activity is crashing. So I'm passing some values from an activity to another using multiple intent.putExtra() to another screen. I can't find why I does work. All helps are welcome.

    Bellow is the code where I recover the putExtra()

    Code (Java):
    1. public class StatusActivity extends AppCompatActivity {
    2.  
    3.  
    4.     @Override
    5.     protected void onCreate(Bundle savedInstanceState) {
    6.         super.onCreate(savedInstanceState);
    7.         setContentView(R.layout.activity_status);
    8.  
    9.         TextView pHLevel = (TextView)findViewById(R.id.phLevel);
    10.         TextView organicCLevel = (TextView)findViewById(R.id.organicCLevel);
    11.         TextView nitrogenLevel = (TextView)findViewById(R.id.nitrogenlevel);
    12.         TextView phosphorusLevel = (TextView)findViewById(R.id.phosphorusLevel);
    13.         TextView potassiumLevel = (TextView)findViewById(R.id.potassiumLevel);
    14.         TextView  zincLevel = (TextView)findViewById(R.id.zincLevel);
    15.         TextView temperatureLevel = (TextView)findViewById(R.id.temparatureLevel);
    16.         TextView date1 = (TextView)findViewById(R.id.date);
    17.         String tempMessage="";
    18.         String pHMessage="";
    19.         String organicCMessage="";
    20.         String nitrogenMessage="";
    21.         String phosphorusMessage="";
    22.         String potassiumMessage="";
    23.         String zincMessage="";
    24.         String username = getIntent().getStringExtra("username");
    25.         double pH2 = Double.parseDouble(getIntent().getStringExtra("pH"));
    26.         double organicC2 = Double.parseDouble(getIntent().getStringExtra("organicC"));
    27.         double nitrogen2 = Double.parseDouble(getIntent().getStringExtra("nitrogen"));
    28.         double phosphorus2 = Double.parseDouble(getIntent().getStringExtra("phosphorus"));
    29.         double potassium2 = Double.parseDouble(getIntent().getStringExtra("potassium"));
    30.         double zinc2 = Double.parseDouble(getIntent().getStringExtra("zinc"));
    31.         double temp2 = Double.parseDouble(getIntent().getStringExtra("temp"));
    32.         String date = getIntent().getStringExtra("date");
    33.  
    34.         //Temperature Level
    35.         if (temp2 >= 24){
    36.             tempMessage = temp2 + " is too high";
    37.         }
    38.         else if (temp2 >= 18 && temp2 <= 24){
    39.             tempMessage = temp2 + " falls withing optimal temperature";
    40.         }
    41.         else if(temp2 < 18){
    42.             tempMessage = temp2 + " temperature too low";
    43.         }
    44.         else
    45.             tempMessage = "Incorrect reading";
    46.  
    47.         //pH Level
    48.         if (pH2 >= 5.5 && pH2 <= 7.0){
    49.             pHMessage = pH2 + " falls in optimal pH";
    50.         }
    51.         else if(pH2 < 5.5 && pH2>= 0){
    52.             pHMessage = pH2 + " might be too acidic";
    53.         }
    54.         else if(pH2 >7 && pH2 <= 14){
    55.             pHMessage = pH2 + " might be too alkaline";
    56.         }
    57.         else
    58.             pHMessage = "Wrong Measurement!";
    59.  
    60.         //Organic carbon level
    61.         if (organicC2 < 1.2){
    62.             organicCMessage = "Low fertility";
    63.         }
    64.         else if(organicC2 >= 1.2 && organicC2 <= 1.7){
    65.             organicCMessage = "Medium fertility";
    66.         }
    67.         else if(organicC2 > 1.7){
    68.             organicCMessage = "High fertility";
    69.         }else
    70.             organicCMessage = "Wrong Measurement";
    71.  
    72.         //nitrogen Level
    73.         if (nitrogen2 >= 0 && nitrogen2 < 15){
    74.             nitrogenMessage = "Level too low";
    75.         }
    76.         else if (nitrogen2 >= 15 && nitrogen2 < 30){
    77.             nitrogenMessage = "Medium level";
    78.         }
    79.         else if (nitrogen2 >= 30){
    80.             nitrogenMessage = "High Level";
    81.         }
    82.         else
    83.             nitrogenMessage = "Wrong measurement";
    84.  
    85.         //Phosphorus Level
    86.         if (phosphorus2 >= 0 && phosphorus2 < 25){
    87.             phosphorusMessage = "Level too low";
    88.         }
    89.         else if (phosphorus2 >= 25 && phosphorus2 < 50){
    90.             phosphorusMessage = "Medium Level";
    91.         }
    92.         else if (phosphorus2 >= 50){
    93.             phosphorusMessage = "High level";
    94.         }
    95.         else
    96.             phosphorusMessage = "Wrong measurement";
    97.  
    98.         //potassium Level
    99.         if (potassium2 >= 0 && potassium2 < 60){
    100.             potassiumMessage = "Level too low";
    101.         }
    102.         else if (potassium2 >= 60 && potassium2 < 100){
    103.             potassiumMessage = "Medium level";
    104.         }
    105.         else if (potassium2 >= 100){
    106.             potassiumMessage = "High Level";
    107.         }
    108.         else
    109.             potassiumMessage = "Wrong Measurement";
    110.  
    111.         //Zinc Level
    112.         if (zinc2 >= 1.6 && zinc2 <= 3){
    113.             zincMessage = "Level too low";
    114.         }
    115.         else if (zinc2 > 3 && zinc2 < 4){
    116.             zincMessage = "Medium level";
    117.         }
    118.         if (zinc2 >= 4 && zinc2 <= 8){
    119.             zincMessage = "High level";
    120.         }
    121.         else
    122.             zincMessage = "Wrong measurement";
    123.  
    124.  
    125.         date1.setText(date);
    126.         /*pHLevel.setText(pHMessage);
    127.         organicCLevel.setText(organicCMessage);
    128.         nitrogenLevel.setText(nitrogenMessage);
    129.         phosphorusLevel.setText(phosphorusMessage);
    130.         potassiumLevel.setText(potassiumMessage);
    131.         zincLevel.setText(zincMessage);
    132.         temperatureLevel.setText(tempMessage);*/
    133.  
    134.     }
    135. }
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...

Share This Page

Loading...