I have made a function in my app to delete a record from a database. I am using a seperate activity to do my deleting. When i enter in the row id to be deleted my app tells me that the app has stopped working, but when i click ok it returns me to the main activity screen. I am using a notifyAll() function to update the database and the list view that I have on the main activity, I think this is where its going wrong but I cant figure out why as I am still quite new to android.
this is the activity where i am using the notifyAll()
package com.example.rory.dbtest;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.pinchtapzoom.R;
public class Delete extends Activity implements View.OnClickListener{
public EditText edit1;
Button delete;
DBAdapter db = new DBAdapter(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_delete);
edit1 = (EditText)findViewById(R.id.edit1);
delete = (Button)findViewById(R.id.deleteBtn);
delete.setOnClickListener((View.OnClickListener) this);
}
public void onClick(View v) {
String userInput = edit1.getText().toString();
//if the ROW ID its a number (long)
try{
long rowID = Long.parseLong(userInput);
//call the delete method
db.open();
db.deleteContact(rowID);
db.close();
db.notifyAll();
}catch(NumberFormatException e){
Log.e("INPUT ERROR","Input is not a number!",e);
//notify the user that the input is invalid.
Toast.makeText(this,"Invalid Value!",Toast.LENGTH_LONG).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.delete, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
This is the logcat error that I am getting
object not locked by thread before notifyAll()
0 comments:
Post a Comment