80,351
社区成员
发帖
与我相关
我的任务
分享
public class InfoManage extends Activity {
protected static final int DATE_DIALOG_ID = 0;
TextView tvtitle, textView;
EditText txtMoney, txtTime, txtHA, txtMark;
Spinner spType;
Button btnEdit, btnDel;
String[] strInfos;
String strid, strType;
private int mYear;
private int mMonth;
private int mDay;
OutaccountDAO outaccountDAO = new OutaccountDAO(InfoManage.this);
InaccountDAO inaccountDAO = new InaccountDAO(InfoManage.this);
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.infomanage);
tvtitle = (TextView) findViewById(R.id.inouttitle);
textView = (TextView) findViewById(R.id.tvInOut);
txtMoney = (EditText) findViewById(R.id.txtInOutMoney);
txtTime = (EditText) findViewById(R.id.txtInOutTime);
spType = (Spinner) findViewById(R.id.spInOutType);
txtHA = (EditText) findViewById(R.id.txtInOut);
txtMark = (EditText) findViewById(R.id.txtInOutMark);
btnEdit = (Button) findViewById(R.id.btnInOutEdit);
btnDel = (Button) findViewById(R.id.btnInOutDelete);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
strInfos = bundle.getStringArray(Showinfo.FLAG);
strid = strInfos[0];
strType = strInfos[1];
if (strType.equals("btnoutinfo")){
tvtitle.setText("支出管理");
textView.setText("地 点:");
Tb_outaccount tb_outaccount = outaccountDAO.find(Integer
.parseInt(strid));
txtMoney.setText(String.valueOf(tb_outaccount.getMoney()));
txtTime.setText(tb_outaccount.getTime());
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.outtype,android.R.layout.simple_dropdown_item_1line);
spType.setAdapter(adapter);
spType.setPrompt(tb_outaccount.getType());
txtHA.setText(tb_outaccount.getAddress());
txtMark.setText(tb_outaccount.getMark());
} else if (strType.equals("btnininfo")){
tvtitle.setText("收入管理");
textView.setText("付款方:");
Tb_inaccount tb_inaccount = inaccountDAO.find(Integer
.parseInt(strid));
txtMoney.setText(String.valueOf(tb_inaccount.getMoney()));
txtTime.setText(tb_inaccount.getTime());
spType.setPrompt(tb_inaccount.getType());
txtHA.setText(tb_inaccount.getHandler());
txtMark.setText(tb_inaccount.getMark());
}
txtTime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
showDialog(DATE_DIALOG_ID);
}
});
btnEdit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (strType.equals("btnoutinfo")){
Tb_outaccount tb_outaccount = new Tb_outaccount();
tb_outaccount.setid(Integer.parseInt(strid));
tb_outaccount.setMoney(Double.parseDouble(txtMoney
.getText().toString()));
tb_outaccount.setTime(txtTime.getText().toString());
tb_outaccount.setType(spType.getSelectedItem().toString());
tb_outaccount.setAddress(txtHA.getText().toString());
tb_outaccount.setMark(txtMark.getText().toString());
outaccountDAO.update(tb_outaccount);
} else if (strType.equals("btnininfo")){
Tb_inaccount tb_inaccount = new Tb_inaccount();
tb_inaccount.setid(Integer.parseInt(strid));
tb_inaccount.setMoney(Double.parseDouble(txtMoney.getText().toString()));
tb_inaccount.setTime(txtTime.getText().toString());
tb_inaccount.setType(spType.getSelectedItem().toString());
tb_inaccount.setHandler(txtHA.getText().toString());
tb_inaccount.setMark(txtMark.getText().toString());
inaccountDAO.update(tb_inaccount);
}
Toast.makeText(InfoManage.this, "修改成功!", Toast.LENGTH_SHORT)
.show();
}
});
btnDel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if (strType.equals("btnoutinfo")){
outaccountDAO.detele(Integer.parseInt(strid));
} else if (strType.equals("btnininfo")){
inaccountDAO.delete(Integer.parseInt(strid));
}
Toast.makeText(InfoManage.this, "删除成功!", Toast.LENGTH_SHORT)
.show();
}
});
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
updateDisplay();
}
@Override
protected Dialog onCreateDialog(int id){
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, mDateSetListener, mYear, mMonth,
mDay);
}
return null;
}
private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateDisplay();
}
};
private void updateDisplay() {
txtTime.setText(new StringBuilder().append(mYear).append("-")
.append(mMonth + 1).append("-").append(mDay));
}
}
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.keyon.moneymanager, PID: 7640
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.keyon.moneymanager/com.example.keyon.moneymanager.activity.InfoManage}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getDatabasePath(java.lang.String)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2820)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3027)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:101)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:73)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1786)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getDatabasePath(java.lang.String)' on a null object reference
at android.content.ContextWrapper.getDatabasePath(ContextWrapper.java:326)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:327)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:273)
at com.example.keyon.moneymanager.dao.OutaccountDAO.<init>(OutaccountDAO.java:18)
at com.example.keyon.moneymanager.activity.InfoManage.<init>(InfoManage.java:38)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:61)
at android.app.Instrumentation.newActivity(Instrumentation.java:1210)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2808)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3027)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:101)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:73)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1786)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
OutaccountDAO outaccountDAO;
InaccountDAO inaccountDAO ;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.infomanage);
outaccountDAO = new OutaccountDAO(InfoManage.this);
inaccountDAO = new InaccountDAO(InfoManage.this);
}