不知道错误在哪儿。。。帮忙解答后发红包好吗?没有c币
你这图片看不清楚,直接把错误代码贴上来
我重新弄。。。。。。。
这些。。。谢谢啦
package com.example.sqlite;import java.util.ArrayList;import java.util.List;import android.R.layout;import android.support.v7.app.ActionBarActivity;import android.app.Activity;import android.content.DialogInterface;import android.content.DialogInterface.OnClickListener;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.ArrayAdapter;import android.widget.Button;import android.widget.EditText;import android.widget.ListAdapter;import android.widget.ListView;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends Activity implements OnClickListener { private static final String TAG="Add"; private static final ListAdapter ListAdapter = null; private EditText ecode,ename,ebirth; private Button badd,bdel,bupdate,bsele; private SQLiteDatabase db=null; private TextView tedatashow; private ListView datashow; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ecode=(EditText)findViewById(R.id.ecode); ename=(EditText)findViewById(R.id.ename); ebirth=(EditText)findViewById(R.id.ebirth); badd=(Button)findViewById(R.id.badd); bdel=(Button)findViewById(R.id.bdel); bupdate=(Button)findViewById(R.id.bupdate); bsele=(Button)findViewById(R.id.bsele); tedatashow=(TextView)findViewById(R.id.tedatashow); datashow=(ListView)findViewById(R.id.datashow); badd.setOnClickListener((android.view.View.OnClickListener) this); bdel.setOnClickListener((android.view.View.OnClickListener) this); bsele.setOnClickListener((android.view.View.OnClickListener) this); bupdate.setOnClickListener((android.view.View.OnClickListener) this); } public void onClick(View v) { // TODO Auto-generated method stub MyDBHelper helper=new MyDBHelper(this); db=helper.getWritableDatabase(); if(v==badd){ if(ecode.getText().toString().trim().length()!=0 && ename.getText().toString().trim().length()!=0 && ebirth.getText().toString().trim().length()!=0){ try{ String sql="INSERT INTO user(code,name,birthday)" +"VALUES('"+ecode.getText()+"','" +ename.getText()+"','" +ebirth.getText()+"')"; db.execSQL(sql); Toast.makeText(this, "添加成功!", Toast.LENGTH_LONG).show(); ecode.setText(""); ename.setText(""); ebirth.setText(""); }catch(Exception e){ Toast.makeText(this, "出错了!"+ e.getMessage(),Toast.LENGTH_LONG).show(); } }else Toast.makeText(this, "学号和姓名出生日期不能为空!", Toast.LENGTH_LONG).show(); } if(v==bdel){ if(ecode.getText().toString().trim().length()!=0){ try{ String sql="delete from user where code='"+ecode.getText()+"'"; db.execSQL(sql); Toast.makeText(this, "成功删除!", Toast.LENGTH_LONG).show(); ecode.setText(""); }catch(Exception e){ Toast.makeText(this, "出错了!", Toast.LENGTH_LONG).show(); } if(v==bupdate){ if(ecode.getText().toString().trim().length()!=0 && ename.getText().toString().trim().length()!=0 && ebirth.getText().toString().trim().length()!=0){ try{ String sql="update user set code='"+ecode.getText() +"',name='"+ename.getText()+"',birthday='" +ebirth.getText()+"'where code='" +ecode.getText()+"''"; db.execSQL(sql); Toast.makeText(this, "成功更新!", Toast.LENGTH_LONG).show(); ecode.setText(""); ename.setText(""); ebirth.setText(""); }catch(Exception e){ Toast.makeText(this, "出错了!"+e.getMessage(),Toast.LENGTH_LONG).show(); } }else Toast.makeText(this, "学号姓名出生日期不能为空!", Toast.LENGTH_LONG).show(); } if(v==bsele){ try{ Listall=new ArrayList(); String sql="SELECT code,name,birthday FROM user"; Cursor result=this.db.rawQuery(sql, null); for(result.moveToFirst();!result.isAfterLast();result.moveToNext()){ all.add("["+result.getString(0)+"]"+""+result.getString(1)+","+result.getString(2)); } datashow.setAdapter(ListAdapter);new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1,all); }catch(Exception f){ Toast.makeText(this, "显示不了", Toast.LENGTH_LONG).show(); } } db.close(); } } } @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }
你这图片 和代码 给你自己看都看懵逼了
截取错误的那几行就可以了
帮你顶顶,顺便也运行一下你的程序。。。。。。。。
你发的东西看不清 私信我