رفتن به مطلب
انجمن اندروید ایران | آموزش برنامه نویسی اندروید و موبایل
  • android.png.1fab383bc8500cd93127cebc65b1dcab.png

پست های پیشنهاد شده

برنامه من از دیتابیس آماده استفاده می کند و در emulator اجرا می شود . اما در گوشی اجرا نمی شود و کرش می کند. لطفا کمک کنید

لینک ارسال
به اشتراک گذاری در سایت های دیگر

میشه لطفا کلاسی که برای کپی کردن دیتابیس نوشته اید را در انجمن قرار دهید، احتمال مجوز های کامل را برای کپی کردن دیتابیس رعایت نکرده اید و در ورژن 4 به بالاتر اینکار انجام نمیشود.

لینک ارسال
به اشتراک گذاری در سایت های دیگر

http://uplod.ir/ridgyzujsq15/DBHelper.java.htm

http://uplod.ir/vsirfver8ofw/MainActivity.java.htm

 

این هم فایل برنامه دوستان لطفا کمک کنید . دارم دیوانه می شوم از بس برنامه کرش  می کند

لینک ارسال
به اشتراک گذاری در سایت های دیگر

لینک فایل ها موجود نیست، لطفا فایل ها را در آپلود سنتر انجمن فقط اپلود نمایید

http://p30droid.com/Uploader

لینک ارسال
به اشتراک گذاری در سایت های دیگر

کلاس دیتابیس را ویرایش کردم ، چون مجوز های کامل را برای کپی  کردن فایل ها رعایت نکرده بودید:

[shcode=java]

public class DBHelper extends SQLiteOpenHelper{

 

    //The Android's default system path of your application database.

    private static String DB_PATH;

 

    private static String DB_NAME = "per";

 

    private SQLiteDatabase myDataBase; 

 

    private final Context myContext;

 

    /**

     * Constructor

     * Takes and keeps a reference of the passed context in order to access to the application assets and resources.

     * @param context

     */

    public DBHelper(Context context) {

 

    super(context, DB_NAME, null, 1);

        this.myContext = context;

        DB_PATH = Environment.getDataDirectory() + "/data/" + context.getPackageName() + "/" + "databases/";

    }

 

  /**

     * Creates a empty database on the system and rewrites it with your own database.

     * */

    public void createDataBase() throws IOException{

 

    boolean dbExist = checkDataBase();

 

    if(dbExist){

    //do nothing - database already exist

    }else{

 

    //By calling this method and empty database will be created into the default system path

               //of your application so we are gonna be able to overwrite that database with our database.

        this.getReadableDatabase();

 

        try {

 

    copyDataBase();

 

    } catch (IOException e) {

 

        throw new Error("Error copying database");

 

        }

    }

 

    }

 

    /**

     * Check if the database already exist to avoid re-copying the file each time you open the application.

     * @return true if it exists, false if it doesn't

     */

    private boolean checkDataBase(){

 

    SQLiteDatabase checkDB = null;

 

    try{

    String myPath = DB_PATH + DB_NAME;

    checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY| SQLiteDatabase.NO_LOCALIZED_COLLATORS

| SQLiteDatabase.CREATE_IF_NECESSARY);

 

    }catch(SQLiteException e){

 

    //database does't exist yet.

 

    }

 

    if(checkDB != null){

 

    checkDB.close();

 

    }

 

    return checkDB != null ? true : false;

    }

 

    /**

     * Copies your database from your local assets-folder to the just created empty database in the

     * system folder, from where it can be accessed and handled.

     * This is done by transfering bytestream.

     * */

    private void copyDataBase() throws IOException{

 

    //Open your local db as the input stream

    InputStream myInput = myContext.getAssets().open(DB_NAME);

 

    // Path to the just created empty db

    String outFileName = DB_PATH + DB_NAME;

 

    //Open the empty db as the output stream

    OutputStream myOutput = new FileOutputStream(outFileName);

 

    //transfer bytes from the inputfile to the outputfile

    byte[] buffer = new byte[1024];

    int length;

    while ((length = myInput.read(buffer))>0){

    myOutput.write(buffer, 0, length);

    }

 

    //Close the streams

    myOutput.flush();

    myOutput.close();

    myInput.close();

 

    }

 

    public void openDataBase() throws SQLException{

 

    //Open the database

        String myPath = DB_PATH + DB_NAME;

    myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY| SQLiteDatabase.NO_LOCALIZED_COLLATORS

| SQLiteDatabase.CREATE_IF_NECESSARY);

 

    }

 

    @Override

public synchronized void close() {

 

       if(myDataBase != null)

       myDataBase.close();

 

       super.close();

 

}

 

@Override

public void onCreate(SQLiteDatabase db) {

 

}

 

@Override

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

 

}

 

        // Add your public helper methods to access and get content from the database.

       // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy

       // to you to create adapters for your views.

 

}

[/shcode]

لینک ارسال
به اشتراک گذاری در سایت های دیگر

سلام دوست عزیز

ممنون از اینکه وقت گذاشتید این کد را کپی کردم اما باز هم  برنامه کرش کرد . لطفا کمک کنید.

این هم لینک خطای برنامه

http://p30droid.com/Uploader/do.php?img=268

لینک ارسال
به اشتراک گذاری در سایت های دیگر

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...