大家好我只想向我的应用程序寻求帮助,每当我选择一个id时它的力就会停止,它显示错误在我的String中,但我没有看到任何错误,它告诉我错误是在“ final String user = etinput.getText()。toString();“。这是我的代码
ArrayList<Messages> list;
MessageDatabase mydb;
MessageAdapter adapter = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_list_message);
listv = (ListView) findViewById(R.id.lv);
registerForContextMenu(listv);
add = (FloatingActionButton) findViewById(R.id.fabadd);
fbnew = (FloatingActionButton) findViewById(R.id.fabnew);
fbedit = (FloatingActionButton) findViewById(R.id.fabedit);
fbdelete = (FloatingActionButton) findViewById(R.id.fabdelete);
add = (FloatingActionButton) findViewById(R.id.fabadd);
backlist = (ImageButton) findViewById(R.id.imgbacklist);
rotateplus = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fabplus);
clockplus = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fabplusclose);
fabopen = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fab_open);
fabclose = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fab_close);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(open){
add.startAnimation(clockplus);
fbnew.startAnimation(fabclose);
fbedit.startAnimation(fabclose);
fbdelete.startAnimation(fabclose);
fbnew.setClickable(false);
fbedit.setClickable(false);
fbdelete.setClickable(false);
open = false;
}
else{
add.startAnimation(rotateplus);
fbnew.startAnimation(fabopen);
fbedit.startAnimation(fabopen);
fbdelete.startAnimation(fabopen);
fbnew.setClickable(true);
fbedit.setClickable(true);
fbdelete.setClickable(true);
open = true;
fbnew.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(ListMessage.this,AddActivity.class);
startActivity(i);
finish();
}
});
fbdelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
alert();
}
});
fbedit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LayoutInflater lay = getLayoutInflater();
viewlayout = lay.inflate(R.layout.input, (ViewGroup) findViewById(R.id.layoutinput));
AlertDialog.Builder b = new AlertDialog.Builder(ListMessage.this);
b.setTitle("Enter the MSG ID you want to edit");
b.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
EditText etinput = (EditText) findViewById(R.id.edtinput);
Intent a = new Intent(ListMessage.this,UpdateActivity.class);
startActivity(a);
finish();
}
});
b.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
});
b.setView(viewlayout);
AlertDialog alert = b.create();
alert.show();
}
});
}
}
});
backlist.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
mydb = new MessageDatabase(this, "MDB.sqlite", null, 1);
list = new ArrayList<Messages>();
adapter = new MessageAdapter(this, R.layout.messages, list);
listv.setAdapter(adapter);
Cursor cursor = SecondActivity.mydb.getData("SELECT * FROM MDB ");
list.clear();
while (cursor.moveToNext()) {
int id = cursor.getInt(0);
String frm = cursor.getString(1);
String to = cursor.getString(2);
String msg = cursor.getString(3);
list.add(new Messages(id, frm, to, msg));
}
adapter.notifyDataSetChanged();
}
private void editt() {
}
private void alert() {
LayoutInflater lay = getLayoutInflater();
viewlayout = lay.inflate(R.layout.input, (ViewGroup) findViewById(R.id.layoutinput));
EditText etinput = (EditText) findViewById(R.id.edtinput);
final String user = etinput.getText().toString();
AlertDialog.Builder b = new AlertDialog.Builder(ListMessage.this);
b.setTitle("Enter the MSG ID you want to delete");
b.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Integer rows = mydb.deleteData(user);
if (rows > 0) {
Toast.makeText(getApplicationContext(), "Done...", Toast.LENGTH_LONG).show();
Intent a = new Intent(ListMessage.this,ListMessage.class);
startActivity(a);
finish();
} else {
Toast.makeText(getApplicationContext(), "Delete Failed...", Toast.LENGTH_LONG).show();
}
}
});
b.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
});
b.setView(viewlayout);
AlertDialog alert = b.create();
alert.show();
}
答案 0 :(得分:0)
点亮你的
EditText etinput = (EditText) findViewById(R.id.edtinput);
在onCreate中并让所有类都可以访问它。
或者如果它是来自另一个视图的editText
EditText etinput = (EditText) view.findViewById(R.id.edtinput);