If you replace your use of Toast.makeText() with Log.i(), what is printed to
the log?


On Wed, Aug 5, 2009 at 1:41 PM, saptarshi chatterjee <
[email protected]> wrote:

> no no Nelissen , you missed the first field of the out put . It's the same
> id number that's repeated. *1 "12c/2","<Dum Dum
> Park>,<Howrah>","India","Kolkata"
> 2 "227","<Bangur>,<Khidirpur>","India","Kolkata"
> 1 "12c/2","<Dum Dum Park>,<Howrah>","India","Kolkata"
> 2 "227","<Bangur>,<Khidirpur>","India","Kolkata"
> *
> You run the program see the out put and you will understand .
> *Next time when I run it ,it shows*
> *1 "12c/2","<Dum Dum Park>,<Howrah>","India","Kolkata"
> 2 "227","<Bangur>,<Khidirpur>","India","Kolkata"
> 3 "12c/2","<Dum Dum Park>,<Howrah>","India","Kolkata"
> 4 "227","<Bangur>,<Khidirpur>","India","Kolkata"
> *
> 1 "12c/2","<Dum Dum Park>,<Howrah>","India","Kolkata"
> 2 "227","<Bangur>,<Khidirpur>","India","Kolkata"
> 3 "12c/2","<Dum Dum Park>,<Howrah>","India","Kolkata"
> 4 "227","<Bangur>,<Khidirpur>","India","Kolkata"
> where it should had been
> 1 "12c/2","<Dum Dum Park>,<Howrah>","India","Kolkata"
> 2 "227","<Bangur>,<Khidirpur>","India","Kolkata"
> 3 "12c/2","<Dum Dum Park>,<Howrah>","India","Kolkata"
> 4 "227","<Bangur>,<Khidirpur>","India","Kolkata"
>
>
> *
> *
>
> On Thu, Aug 6, 2009 at 2:05 AM, Marco Nelissen <[email protected]>wrote:
>
>> Looks to me like every time you run your app, you insert two more rows in
>> to the database, so the first it will have 2 rows, then 4, 6, 8, etc.
>>
>>
>>
>> On Wed, Aug 5, 2009 at 1:12 PM, saptarshi chatterjee <
>> [email protected]> wrote:
>>
>>>
>>> package com.outp.inp;
>>>
>>>
>>>
>>>
>>>
>>> import android.app.Activity;
>>> import android.content.ContentValues;
>>> import android.content.Context;
>>> import android.database.Cursor;
>>> import android.database.SQLException;
>>> import android.database.sqlite.SQLiteDatabase;
>>> import android.database.sqlite.SQLiteOpenHelper;
>>> import android.os.Bundle;
>>> import android.util.Log;
>>> import android.widget.Toast;
>>>
>>>
>>> public class myact extends Activity {
>>>
>>>
>>>        public static final String KEY_ROWID = "_id";
>>>    public static final String KEY_VEHICLE = "vehicle";
>>>    public static final String KEY_ROUTE = "route";
>>>    public static final String KEY_COUNTRY = "country";
>>>    public static final String KEY_CITY = "city";
>>>    private static final String TAG = "DBAdapter";
>>>
>>>    private static final String DATABASE_NAME = "publicTransport";
>>>    private static final String DATABASE_TABLE = "vehicleTable";
>>>    private static final int DATABASE_VERSION = 1;
>>>
>>>    long id;
>>>    Cursor c;
>>>
>>>    private static final String DATABASE_CREATE =
>>>        "create table vehicleTable (_id integer primary key
>>> autoincrement, "
>>>        + "vehicle text not null, route text not null, "
>>>        + "country text not null,city text not null);";
>>>
>>>
>>>    private  final Context context=this;
>>>    private DatabaseHelper DBHelper;
>>>    private SQLiteDatabase sqlitedatabase;
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>    /** Called when the activity is first created. */
>>>    @Override
>>>    public void onCreate(Bundle savedInstanceState) {
>>>        super.onCreate(savedInstanceState);
>>>        setContentView(R.layout.main);
>>>
>>>
>>>        DBHelper = new DatabaseHelper(context);
>>>        sqlitedatabase = DBHelper.getWritableDatabase();
>>>
>>>        id = insertRow(
>>>                        "12c/2","<Dum Dum
>>> Park>,<Howrah>","India","Kolkata");
>>>         id = insertRow(
>>>                        "227","<Bangur>,<Khidirpur>","India","Kolkata");
>>>         Toast.makeText(this, "new \n\n"+id,Toast.LENGTH_LONG).show();
>>>
>>>
>>>         Cursor c = getAllRows();
>>>         if (c.moveToFirst())
>>>         {
>>>             do {
>>>                 DisplayRow(c);
>>>             } while (c.moveToNext());
>>>         }
>>>         sqlitedatabase.close();
>>>
>>>
>>>
>>>    }
>>>
>>>
>>>
>>>    private static class DatabaseHelper extends SQLiteOpenHelper
>>>    {
>>>        DatabaseHelper(Context context)
>>>        {
>>>            super(context, DATABASE_NAME, null, DATABASE_VERSION);
>>>
>>>        }
>>>
>>>
>>>        public void onCreate(SQLiteDatabase db)
>>>        {
>>>
>>>            db.execSQL(DATABASE_CREATE);
>>>
>>>
>>>        }
>>>
>>>        @Override
>>>        public void onUpgrade(SQLiteDatabase db, int oldVersion,
>>>                              int newVersion)
>>>        {
>>>            Log.w(TAG, "Upgrading database from version " +
>>> oldVersion
>>>                  + " to "
>>>                  + newVersion + ", which will destroy all old data");
>>>            db.execSQL("DROP TABLE IF EXISTS titles");
>>>            onCreate(db);
>>>        }
>>>    }
>>>
>>>
>>>
>>>
>>>
>>>    public long insertRow(String vehicle, String route, String
>>> country,String city)
>>>    {
>>>        ContentValues initialValues = new ContentValues();
>>>        initialValues.put(KEY_VEHICLE, vehicle);
>>>        initialValues.put(KEY_ROUTE, route);
>>>        initialValues.put(KEY_COUNTRY, country);
>>>        initialValues.put(KEY_CITY, city);
>>>        return sqlitedatabase.insert(DATABASE_TABLE, null,
>>> initialValues);
>>>    }
>>>
>>>
>>>
>>>
>>>    public Cursor getAllRows()
>>>    {
>>>        return sqlitedatabase.query(DATABASE_TABLE, new String[] {
>>>                        KEY_ROWID,
>>>                        KEY_VEHICLE,
>>>                        KEY_ROUTE,
>>>                        KEY_COUNTRY,
>>>                        KEY_CITY},
>>>                null,
>>>                null,
>>>                null,
>>>                null,
>>>                null);
>>>    }
>>>
>>>
>>>
>>>
>>>    public void DisplayRow(Cursor c)
>>>    {
>>>        Toast.makeText(this,
>>>                "id: " + c.getString(0) + "\n" +
>>>                "VEHICLE: " + c.getString(1) + "\n" +
>>>                "ROUTE: " + c.getString(2) + "\n" +
>>>                "COUNTRY:  " + c.getString(3)+
>>>                "CITY:  " + c.getString(4),
>>>                Toast.LENGTH_LONG).show();
>>>    }
>>>
>>>
>>>
>>>
>>>
>>>
>>>  }
>>>
>>>
>>>    -------------------------------------
>>>
>>> According to me the out put of these prgrm should be
>>>
>>> 1 "12c/2","<Dum Dum Park>,<Howrah>","India","Kolkata"
>>> 2 "227","<Bangur>,<Khidirpur>","India","Kolkata"
>>>
>>> But Out put is coming as--
>>>
>>> 1 "12c/2","<Dum Dum Park>,<Howrah>","India","Kolkata"
>>> 2 "227","<Bangur>,<Khidirpur>","India","Kolkata"
>>> 1 "12c/2","<Dum Dum Park>,<Howrah>","India","Kolkata"
>>> 2 "227","<Bangur>,<Khidirpur>","India","Kolkata"
>>>
>>>
>>> I have seen others prgrmms too that's giving same output twice . Can
>>> any one please explain??
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>
>
> --
> Saptarshi Chatterjee
> fireup.co.in : Igniting intellect
>
> This e-mail, include confidential and
> proprietary information, and strictly should be used only by the person
> to whom it is addressed.,If you have received this e-mail in error, please
> notify the
> sender by replying to this message and delete this e-mail immediately.
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to