|
|
|
รบกวนถาม : เขียน code เสร็จแล้ว ไม่มี error หรือ warning แต่พอรันแล้ว เกิด error ใน emolater android |
|
|
|
|
|
|
|
code ที่เขียน
Code (Java)
package com.example.feeprice;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.graphics.Typeface;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private EditText ePrice;
private EditText eDiscount;
private EditText eTax;
private Button bAdd;
private Button bMinus;
private Button bDel;
private Button bCal;
String eStart;
private Context context;
private Typeface thaifont;
//for set double
private Double editStartD=0D;
private Double priceAfterDis=0D;
private Double priceForSale=0D;
private Double disCountNum=0D;
private Double disCountCost=0D;
private Double taxNum=0D;
Double taxPrice=0D;
//for set text show word
private TextView txtPrice;
private TextView txtDiscount;
private TextView txtAfterDis;
private TextView txtTax;
private TextView txtTotal;
//for set text view display
private TextView rPrice;
private TextView rDiscount;
private TextView rafdis;
private TextView rtax;
private TextView rtotal;
//for display number
private TextView shPrice;
private TextView shDiscount;
private TextView shafdis;
private TextView shtax;
private TextView shtotal;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ePrice=(EditText) findViewById(R.id.price);
eDiscount=(EditText) findViewById(R.id.discount);
eTax=(EditText) findViewById(R.id.tax);
bAdd=(Button) findViewById(R.id.posi);
bMinus=(Button) findViewById(R.id.nega);
bDel=(Button) findViewById(R.id.del);
bCal=(Button) findViewById(R.id.cal);
txtPrice=(TextView) findViewById(R.id.tprice);
txtDiscount=(TextView) findViewById(R.id.tdiscount);
txtAfterDis=(TextView) findViewById(R.id.tafdis);
txtTax=(TextView) findViewById(R.id.ttax);
txtTotal=(TextView) findViewById(R.id.ttotal);
rPrice=(TextView) findViewById(R.id.spprice);
rDiscount=(TextView) findViewById(R.id.spdiscount);
rafdis=(TextView) findViewById(R.id.spafdis);
rtax=(TextView) findViewById(R.id.sptax);
rtotal=(TextView) findViewById(R.id.sptotal);
txtPrice.setTypeface(thaifont);
txtDiscount.setTypeface(thaifont);
txtAfterDis.setTypeface(thaifont);
txtTax.setTypeface(thaifont);
txtTotal.setTypeface(thaifont);
shPrice.setTypeface(thaifont);
shDiscount.setTypeface(thaifont);
shafdis.setTypeface(thaifont);
shtax.setTypeface(thaifont);
shtotal.setTypeface(thaifont);
txtPrice.setText("");
txtDiscount.setText("");
txtAfterDis.setText("");
txtTax.setText("");
txtTotal.setText("");
bCal.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
eStart=ePrice.getText().toString();//get text and save to eStart
if(eDiscount.getText().toString().equals(""))
{eDiscount.setText("0");} //set discount to "0"
if(ePrice.equals("")){
Toast t=Toast.makeText(context, "ไม่ใช่ตัวเลข", Toast.LENGTH_SHORT);
TextView tv=(TextView) t.getView().
findViewById(android.R.id.message);//message auto generate
tv.setTypeface(thaifont);
t.show();
}else{
editStartD=Double.parseDouble(eStart);
disCountNum=Double.parseDouble(eDiscount.getText().toString());
if(disCountNum==0){
priceAfterDis=editStartD;
}else{
priceAfterDis=editStartD-(editStartD*(disCountNum/100.0));
disCountCost=editStartD*(disCountNum/100.0);
taxNum=Double.parseDouble(eTax.getText().toString());
taxPrice=priceAfterDis*(taxNum/100.0);
priceForSale=priceAfterDis+(priceAfterDis*(taxNum/100.0));
}
txtPrice.setText("\t\t\t\tราคาตั้งต้น");
rPrice.setText(""+editStartD);
shPrice.setText("บาท");
txtDiscount.setText("\t\t\t\tส่วนลด");
rDiscount.setText(""+disCountCost);
shDiscount.setText("บาท");
txtAfterDis.setText("\t\t\t\tราคาหลังส่วนลด");
rafdis.setText(""+priceAfterDis);
shafdis.setText("บาท");
txtTax.setText("\t\t\t\tภาษี");
rtax.setText(""+taxNum);
shtax.setText("บาท");
txtTotal.setText("\t\t\t\tราคาขาย");
rtotal.setText(""+priceForSale);
shtotal.setText("บาท");
}
}
});
bDel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
AlertDialog.Builder dialog=new AlertDialog.Builder(context);
dialog.setMessage("Delete all");
dialog.setPositiveButton("yes",new OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
ePrice.setText("");
eDiscount.setText("");
eTax.setText("");
txtPrice.setText("\t\t\t\tราคาตั้งต้น");
shPrice.setText("บาท");
txtDiscount.setText("\t\t\t\tส่วนลด");
shDiscount.setText("บาท");
txtAfterDis.setText("\t\t\t\tราคาหลังส่วนลด");
shafdis.setText("บาท");
txtTax.setText("\t\t\t\tภาษี");
shtax.setText("บาท");
txtTotal.setText("\t\t\t\tราคาขาย");
shtotal.setText("บาท");
}
});
dialog.setNegativeButton("no",new OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
} );
dialog.show();
}
});
bAdd.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int plus=Integer.parseInt(eDiscount.getText().toString());
plus++;
eDiscount.setText(String.valueOf(plus));
}
});
bMinus.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int plus=Integer.parseInt(eDiscount.getText().toString());
plus--;
if(plus<=0){plus=0;}
eDiscount.setText(String.valueOf(plus));
}
});
}
}
|
|
|
|
|
Date :
2012-08-14 18:14:31 |
By :
YouAreMyFeed |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มัน Error ตอน runtime ครับ อาจจะต้องลองดูใน LogCat หรือใช้การ Debug ดูครับ
|
|
|
|
|
Date :
2012-08-14 20:05:41 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|