In EmployeeEdit.onCreate() you set mRowId = null;
Peli
On Oct 14, 7:15 pm, JavaAndroid <[EMAIL PROTECTED]> wrote:
> Hi All,
> I could trouble shoot my issue. I could insert a new record and delete
> an existing one..But while editing and updating i m getting rowId as
> 0. it simply displays 0 for all records...
> i feel we are setting the rowId to intent in this method..
> protected void onListItemClick(ListView l, View v, int position, long
> _id)
>
> protected void onListItemClick(ListView l, View v, int position, long
> _id){
> super.onListItemClick(l, v, position, _id);
> Cursor c = mCursor;
> Log.d(TAG, "Position in the List "+position);
> Log.d(TAG, "Cursor-----"+c);
> c.moveToPosition(position);
> Log.d(TAG, "Row Id for the selected Record"+c.getLong(0));
> Intent i = new Intent(this,EmployeeEdit.class);
> i.putExtra(EmployeeDAO.KEY_ROW_ID,_id);
> i.putExtra(EmployeeDAO.EMP_NAME, c.getString(
> c.getColumnIndexOrThrow(EmployeeDAO.EMP_NAME)));
> i.putExtra(EmployeeDAO.EMP_AGE, c.getInt(
> c.getColumnIndexOrThrow(EmployeeDAO.EMP_AGE)));
> i.putExtra(EmployeeDAO.EMP_QUALIFICATION, c.getString(
>
> c.getColumnIndexOrThrow(EmployeeDAO.EMP_QUALIFICATION)));
> i.putExtra(EmployeeDAO.EMP_DEPT, c.getString(
> c.getColumnIndexOrThrow(EmployeeDAO.EMP_DEPT)));
> startActivityForResult(i, ACTIVITY_EDIT);
> }
>
> protected void onActivityResult(int requestCode, int resultCode,
> Intent intent){
> super.onActivityResult(requestCode, resultCode, intent);
> Bundle extras = intent.getExtras();
> switch(requestCode){
> case ACTIVITY_CREATE:
> String employeeName = extras.getString(EmployeeDAO.EMP_NAME);
> int employeeAge =
> Integer.parseInt(extras.getString(EmployeeDAO.EMP_AGE));
> String employeeQualification =
> extras.getString(EmployeeDAO.EMP_QUALIFICATION);
> String employeeDept = extras.getString(EmployeeDAO.EMP_DEPT);
> employee.insertEmployeeInformation(employeeName, employeeAge,
> employeeQualification, employeeDept);
> fillData();
> break;
> case ACTIVITY_EDIT:
> Long rowId = extras.getLong(EmployeeDAO.KEY_ROW_ID);
> Log.d(TAG, "RowId in Activity Edit"+rowId);
> if(rowId != null){
> Log.d(TAG, "RowId While Updating the record "+rowId);
> String updateEmployeeName =
> extras.getString(EmployeeDAO.EMP_NAME);
> int updateEmployeeAge =
> Integer.parseInt(extras.getString(EmployeeDAO.EMP_AGE));
> String updateEmployeeQualification =
> extras.getString(EmployeeDAO.EMP_QUALIFICATION);
> String updateEmployeeDept =
> extras.getString(EmployeeDAO.EMP_DEPT);
> employee.updateEmployeeInformation(rowId,
> updateEmployeeName,
> updateEmployeeAge,
> updateEmployeeQualification,
> updateEmployeeDept);
> fillData();
> break;
> }
> }
>
> we would be taking this value in onActivityResult() method and calling
> DAO layer from there.....
>
> i have debugged this, but rowId always remains at 0.... can anybody
> find where the Problem is??
>
> All classes are present in first Post...
> Thanks in Advance
>
> Thanks
> JavaAndroid
>
> On Oct 13, 10:57 pm, JavaAndroid <[EMAIL PROTECTED]> wrote:
>
> > Peli
> > Thanks a million for your timely help. Logcat was really helpful in
> > identifying the issue, and i got my application working.....thanks
> > again
>
> > JavaAndroid
>
> > On Oct 13, 6:15 pm, Peli <[EMAIL PROTECTED]> wrote:
>
> > > The answer is in the last post
> > > here:http://groups.google.com/group/android-beginners/browse_thread/thread...
>
> > > Since there can be several emulators open at a time, you also have to
> > > open the "devices" list, and click on your emulator to activate the
> > > logcat output.
>
> > > Peli
>
> > > On Oct 13, 10:25 am, JavaAndroid <[EMAIL PROTECTED]> wrote:
>
> > > > Hi Peli,
> > > > Thanks for ur Valuable response. I m not aware of this logcat tab in
> > > > eclipse. Is that present in any Window??
>
> > > > Thanks
> > > > JavaAndroid
>
> > > > On Oct 13, 12:42 pm, Peli <[EMAIL PROTECTED]> wrote:
>
> > > > > You have to use logcat to see the debugging statements.
>
> > > > > Either from Eclipse open the logcat tab and choose the device from the
> > > > > devices list.
> > > > > Or in a shell enter "adb logcat".
>
> > > > > Peliwww.openintents.org
>
> > > > > On Oct 13, 2:49 am, JavaAndroid <[EMAIL PROTECTED]> wrote:
>
> > > > > > Hi All,
> > > > > > I m a novice in Google Android.. Just started with couple of
> > > > > > tutorials
> > > > > > present in Google Android Documentation page.
> > > > > > I have modified theNotePadapplicationpresent there. I have four
> > > > > > textfields namely, employeeName,employeeAge,
> > > > > > employeeQualification, employeeDept.
> > > > > > I could insert a new record and delete an existing record, but i m
> > > > > > facing problem in editing an existing record. When i click a record
> > > > > > it
> > > > > > says, theApplicationEmployeeInformation has stopped unexpectedly.
> > > > > > Here is my EmployeeInfo class
> > > > > > package com.dreamapp.employeeinfo.activity;
>
> > > > > > import android.app.ListActivity;
> > > > > > import android.content.Intent;
> > > > > > import android.database.Cursor;
> > > > > > import android.os.Bundle;
> > > > > > import android.util.Log;
> > > > > > import android.view.Menu;
> > > > > > import android.view.MenuItem;
> > > > > > import android.view.View;
> > > > > > import android.widget.ListView;
> > > > > > import android.widget.SimpleCursorAdapter;
>
> > > > > > import com.dreamapp.employeeinfo.util.EmployeeDAO;
>
> > > > > > public class EmployeeInfo extends ListActivity {
> > > > > > private static final int ACTIVITY_CREATE =0;
> > > > > > private static final int ACTIVITY_EDIT =1;
>
> > > > > > private static final int INSERT_ID = Menu.FIRST;
> > > > > > private static final int DELETE_ID = Menu.FIRST+1;
>
> > > > > > private EmployeeDAO employee;
> > > > > > private Cursor mCursor;
>
> > > > > > private static final String TAG="EmployeeInfo";
> > > > > > /** Called when the activity is first created. */
> > > > > > [EMAIL PROTECTED]
> > > > > > public void onCreate(Bundle savedInstanceState) {
> > > > > > super.onCreate(savedInstanceState);
> > > > > > setContentView(R.layout.employee_list);
> > > > > > employee = new EmployeeDAO(this);
> > > > > > employee.open();
> > > > > > fillData();
> > > > > > }
>
> > > > > > public void fillData(){
> > > > > > mCursor = employee.fetchAllEmployeeInformation();
> > > > > > startManagingCursor(mCursor);
>
> > > > > > String[] from = new String[] {EmployeeDAO.EMP_NAME};
>
> > > > > > int[] to = new int[] {R.id.text1};
> > > > > > SimpleCursorAdapter employeeList =
> > > > > > new SimpleCursorAdapter(this, R.layout.employee_row,
> > > > > > mCursor,from, to);
> > > > > > setListAdapter(employeeList);
> > > > > > }
>
> > > > > > public boolean onCreateOptionsMenu(Menu menu){
> > > > > > super.onCreateOptionsMenu(menu);
> > > > > > menu.add(0, INSERT_ID, 0, R.string.menu_insert);
> > > > > > menu.add(0, DELETE_ID, 0, R.string.menu_delete);
> > > > > > return true;
> > > > > > }
>
> > > > > > public boolean onMenuItemSelected(int featureId, MenuItem item){
> > > > > > switch(item.getItemId()){
> > > > > > case INSERT_ID:
> > > > > > insertEmployeeInformation();
> > > > > > return true;
> > > > > > case DELETE_ID:
> > > > > > employee.deleteEmployeenformation(getListView().
> > > > > > getSelectedItemId());
> > > > > > fillData();
> > > > > > return true;
> > > > > > }
> > > > > > return super.onMenuItemSelected(featureId, item);
> > > > > > }
>
> > > > > > public void insertEmployeeInformation(){
> > > > > > Intent i = new Intent(this,EmployeeEdit.class);
> > > > > > startActivityForResult(i, ACTIVITY_CREATE);
> > > > > > }
>
> > > > > > protected void onListItemClick(ListView l, View v, int position,
> > > > > > long id){
> > > > > > super.onListItemClick(l, v, position, id);
> > > > > > Cursor c = mCursor;
> > > > > > Log.w(TAG, "Position in the List "+position);
> > > > > > c.moveToPosition(position);
> > > > > > Intent i = new Intent(this,EmployeeEdit.class);
> > > > > > i.putExtra(EmployeeDAO.KEY_ROW_ID, id);
> > > > > > i.putExtra(EmployeeDAO.EMP_NAME, c.getString(
>
> > > > > > c.getColumnIndexOrThrow(EmployeeDAO.EMP_NAME)));
> > > > > > i.putExtra(EmployeeDAO.EMP_AGE, id);
> > > > > > i.putExtra(EmployeeDAO.EMP_QUALIFICATION, c.getInt(
>
> > > > > > c.getColumnIndexOrThrow(EmployeeDAO.EMP_QUALIFICATION)));
> > > > > > i.putExtra(EmployeeDAO.EMP_QUALIFICATION, c.getString(
>
> > > > > > c.getColumnIndexOrThrow(EmployeeDAO.EMP_QUALIFICATION)));
> > > > > > i.putExtra(EmployeeDAO.EMP_DEPT, c.getString(
>
> > > > > > c.getColumnIndexOrThrow(EmployeeDAO.EMP_DEPT)));
> > > > > > startActivityForResult(i, ACTIVITY_EDIT);
> > > > > > }
>
> > > > > > protected void onActivityResult(int requestCode, int resultCode,
> > > > > > Intent intent){
> > > > > > super.onActivityResult(requestCode, resultCode, intent);
> > > > > > Bundle extras = intent.getExtras();
> > > > > > switch(requestCode){
> > > > > > case ACTIVITY_CREATE:
> > > > > > String employeeName =
> > > > > > extras.getString(EmployeeDAO.EMP_NAME);
> > > > > > int employeeAge =
> > > > > > extras.getInt(EmployeeDAO.EMP_NAME);
> > > > > > String
>
> ...
>
> read more »
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---