Created
May 18, 2018 13:26
-
-
Save edenizk/312acf61f6b5fcbd33274b956547f864 to your computer and use it in GitHub Desktop.
Exception handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.deniz.exceptionhandling; | |
import android.content.Context; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
import org.w3c.dom.Text; | |
import static android.app.PendingIntent.getActivity; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
TextView txtRates = (TextView) findViewById(R.id.txtRates); | |
TextView txtPpl = (TextView) findViewById(R.id.txtPpl); | |
String oldTxtRates, oldTxtPpl; | |
int[] pplRates = { 1, 4, 3, 5, 2, 5, 1, 3, 4, 5, 2, 4, 5, 6}; | |
int[] occurence = new int[6]; | |
for(int respond = 0 ; respond<pplRates.length;respond++) { | |
try { | |
++occurence[pplRates[respond]]; | |
} catch (Exception e) { | |
Toast.makeText(getApplicationContext(), "ERROR " + e, | |
Toast.LENGTH_LONG).show(); | |
} | |
} | |
for(int amount = 1 ; amount<occurence.length;amount++){ | |
oldTxtRates = txtRates.getText().toString(); | |
oldTxtPpl = txtPpl.getText().toString(); | |
txtRates.setText(oldTxtRates + amount + "\n"); | |
txtPpl.setText(oldTxtPpl + occurence[amount] + "\n"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment