package melina.latihan2;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.v...
btntambah.setOnClickListener(this);
btnkurang = (Button)findViewById(R.id.btnkurang);
btnkurang.setOnClickListener(this);
...
TextView ettxtbil2 = null;
txtbil2 =
Double.parseDouble(ettxtbil2.getText().toString());
} catch (Exception e) {
// TODO: ...
if (v.getId()==R.id.btntambah) {
vhasil=obja.gethasilpenjumlahan();
txthasil.setText(String.valueOf(vhasil));
} else if (v...
Upcoming SlideShare
Loading in …5
×

Pemrograman Mobile - Try Catch

306 views
181 views

Published on

Published in: Software, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
306
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Pemrograman Mobile - Try Catch

  1. 1. package melina.latihan2; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity implements OnClickListener { Button btntambah; Button btnkurang; Button btnkali; Button btnbagi; EditText txtbil1; EditText txtbil2; EditText txthasil; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btntambah = (Button)findViewById(R.id.btntambah);
  2. 2. btntambah.setOnClickListener(this); btnkurang = (Button)findViewById(R.id.btnkurang); btnkurang.setOnClickListener(this); btnkali = (Button)findViewById(R.id.btnkali); btnkali.setOnClickListener(this); btnbagi = (Button)findViewById(R.id.btnbagi); btnbagi.setOnClickListener(this); btnbagi.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub kalkulasi(); } }); txtbil1 = (EditText) findViewById(R.id.txtbil1); txtbil2 = (EditText) findViewById(R.id.txtbil2); txthasil = (EditText) findViewById(R.id.txthasil); } public void kalkulasi(){ double txtbil1 = 10; double txtbil2 = 0; try {
  3. 3. TextView ettxtbil2 = null; txtbil2 = Double.parseDouble(ettxtbil2.getText().toString()); } catch (Exception e) { // TODO: handle exception Toast.makeText(this, "Oops! an error occurred,please check the division number!", Toast.LENGTH_LONG).show(); txthasil.setText("Hasil pembagian Error ! "); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public void onClick(View v) { // TODO Auto-generated method stub double vbil1,vbil2,vhasil; vbil1 = Double.valueOf(txtbil1.getText().toString()); vbil2 = Double.valueOf(txtbil2.getText().toString()); aritmatika obja = new aritmatika(vbil1, vbil2);
  4. 4. if (v.getId()==R.id.btntambah) { vhasil=obja.gethasilpenjumlahan(); txthasil.setText(String.valueOf(vhasil)); } else if (v.getId()==R.id.btnkurang) { vhasil=obja.gethasilpengurangan(); txthasil.setText(String.valueOf(vhasil)); } else if (v.getId()==R.id.btnkali) { vhasil=obja.gethasilperkalian(); txthasil.setText(String.valueOf(vhasil)); } else if (v.getId()==R.id.btnbagi) { vhasil=obja.gethasilpembagian(); txthasil.setText(String.valueOf(vhasil)); } } }

×