1

我已经设置了服务器,目前停留在我的 android 代码中。

谁能帮我分享一下灯?

这是databasehandler我的课android application

package net.ddns.manajemenpekerjaan.manajemenpekerjaan;

import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import org.jumpmind.symmetric.android.SQLiteOpenHelperRegistry;
import org.jumpmind.symmetric.android.SymmetricService;

import java.sql.Blob;
import java.util.Properties;

/**
 * Created by Wuller on 12/25/2015.
 */
public class DatabaseOperation extends SQLiteOpenHelper {


public static final int DATABASE_VERSION = 1;
private DatabaseOperation mOpenHelper;

public final Context getContext() {
    return getContext();
}


public String CREATE_QUERY_TABEL_USER = "CREATE TABLE " +
        DataTabel.TableInfo.NAMA_TABEL_USER + "("
        + DataTabel.TableInfo.KOLOM_NIP_USER + " TEXT PRIMARY KEY,"
        + DataTabel.TableInfo.KOLOM_PASSWORD_USER + " TEXT,"
        + DataTabel.TableInfo.KOLOM_NAMA_USER + " TEXT,"
        + DataTabel.TableInfo.KOLOM_KODE_JABATAN_USER + " INTEGER"
        + ")";

public String CREATE_QUERY_TABEL_TUGAS = "CREATE TABLE " +
        DataTabel.TableInfo.NAMA_TABEL_TUGAS + "("
        + DataTabel.TableInfo.KOLOM_ID_TUGAS + " INTEGER PRIMARY KEY,"
        + DataTabel.TableInfo.KOLOM_PASSWORD_USER + " TEXT,"
        + DataTabel.TableInfo.KOLOM_VERSI_TUGAS + " DATETIME,"
        + DataTabel.TableInfo.KOLOM_NIP_ATASAN + " TEXT,"
        + DataTabel.TableInfo.KOLOM_NIP_BAWAHAN + " TEXT,"
        + DataTabel.TableInfo.KOLOM_DESKRIPSI_TUGAS + " TEXT,"
        + DataTabel.TableInfo.KOLOM_TARGET_TUGAS + " DATE,"
        + DataTabel.TableInfo.KOLOM_INISIATIF_TUGAS + " TEXT,"
        + DataTabel.TableInfo.KOLOM_NOMOR_DISPOSISI + " TEXT,"
        + DataTabel.TableInfo.KOLOM_LAMPIRAN_BUKTI + " BLOB,"
        + DataTabel.TableInfo.KOLOM_STATUS_TUGAS + " TEXT"
        + ")";

public String CREATE_QUERY_TABEL_VERSI_TUGAS = "CREATE TABLE " +
        DataTabel.TableInfo.NAMA_TABEL_VERSI_TUGAS + "("
        + DataTabel.TableInfo.KOLOM_ID_VERSI + " INTEGER PRIMARY KEY,"
        + DataTabel.TableInfo.KOLOM_VERSI_TANGGAL + " DATETIME,"
        + DataTabel.TableInfo.KOLOM_ID_TUGAS_VERSITUGAS + " INTEGER,"
        + DataTabel.TableInfo.KOLOM_STATUS_TUGAS_VERSITUGAS + " INTEGER"
        + ")";

public String CREATE_QUERY_TABEL_ATASAN_BAWAHAN = "CREATE TABLE " +
        DataTabel.TableInfo.NAMA_TABEL_ATASAN_BAWAHAN + "("
        + DataTabel.TableInfo.KOLOM_NIP_ATASAN_ATASANBAWAHAN + " TEXT,"
        + DataTabel.TableInfo.KOLOM_NIP_BAWAHAN_ATASANBAWAHAN + " TEXT,"
        + DataTabel.TableInfo.KOLOM_VERSI_ATASANBAWAHAN + " DATETIME"
        + ")";

public DatabaseOperation(Context context) {
    super(context, DataTabel.TableInfo.DATABASE_NAME, null, DATABASE_VERSION);
    Log.d("Database operations", "Database created");
}


@Override
public void onCreate(SQLiteDatabase sdb) {

    /////SETTING SYMMETRIC

    final String HELPER_KEY = "ManajemenPekerjaanHelperKey";
    //mOpenHelper = new DatabaseOperation(getContext());
    mOpenHelper = new DatabaseOperation(getContext());


    // Register the database helper, so it can be shared with the SymmetricService
    SQLiteOpenHelperRegistry.register(HELPER_KEY, mOpenHelper);
    Intent intent = new Intent(getContext(), SymmetricService.class);

    // Notify the service of the database helper key
    intent.putExtra(SymmetricService.INTENTKEY_SQLITEOPENHELPER_REGISTRY_KEY,
            HELPER_KEY);
    intent.putExtra(SymmetricService.INTENTKEY_REGISTRATION_URL,
            "http://manajemenpekerjaan.ddns.net:31415/sync/server");
    intent.putExtra(SymmetricService.INTENTKEY_EXTERNAL_ID,
            "android");
    intent.putExtra(SymmetricService.INTENTKEY_NODE_GROUP_ID, "client");
    intent.putExtra(SymmetricService.INTENTKEY_START_IN_BACKGROUND,
            true);

    Properties properties = new Properties();
    intent.putExtra(SymmetricService.INTENTKEY_PROPERTIES, properties);

    getContext().startService(intent);

    return;

    //SETTING SYMMETRIC

    sdb.execSQL(CREATE_QUERY_TABEL_USER);
    sdb.execSQL(CREATE_QUERY_TABEL_TUGAS);
    sdb.execSQL(CREATE_QUERY_TABEL_VERSI_TUGAS);
    sdb.execSQL(CREATE_QUERY_TABEL_ATASAN_BAWAHAN);
    Log.d("Database operations", "Table created");
}

@Override
public void onUpgrade(SQLiteDatabase sdb, int oldVersion, int newVersion) {

    sdb.execSQL("DROP TABLE IF EXIST " + DataTabel.TableInfo.NAMA_TABEL_USER);
    sdb.execSQL("DROP TABLE IF EXIST " + DataTabel.TableInfo.NAMA_TABEL_TUGAS);
    sdb.execSQL("DROP TABLE IF EXIST " + DataTabel.TableInfo.NAMA_TABEL_VERSI_TUGAS);
    sdb.execSQL("DROP TABLE IF EXIST " + DataTabel.TableInfo.NAMA_TABEL_ATASAN_BAWAHAN);

    onCreate(sdb);

}

public void InputData(DatabaseOperation mOpenHelper, String nipatasan, String nipbawahan, String deskripsitugas, String targettugas, String nomordisposisi, Blob lampiranbukti, String statustugas) {

    SQLiteDatabase SQ = mOpenHelper.getWritableDatabase();
    ContentValues cv = new ContentValues();
    cv.put(DataTabel.TableInfo.KOLOM_NIP_ATASAN, nipatasan);
    cv.put(DataTabel.TableInfo.KOLOM_NIP_BAWAHAN, nipbawahan);
    cv.put(DataTabel.TableInfo.KOLOM_DESKRIPSI_TUGAS, deskripsitugas);
    cv.put(DataTabel.TableInfo.KOLOM_TARGET_TUGAS, String.valueOf(targettugas));
    cv.put(DataTabel.TableInfo.KOLOM_NOMOR_DISPOSISI, nomordisposisi);
    cv.put(DataTabel.TableInfo.KOLOM_LAMPIRAN_BUKTI, String.valueOf(lampiranbukti));
    cv.put(DataTabel.TableInfo.KOLOM_STATUS_TUGAS, statustugas);

    long k = SQ.insert(DataTabel.TableInfo.NAMA_TABEL_TUGAS, null, cv);


    Log.d("Database operations", "Tugas baru berhasil disimpan");

}

public Cursor AmbilDataTugas(DatabaseOperation mOpenHelper) {

    SQLiteDatabase SQ = mOpenHelper.getReadableDatabase();
    String[] kolom = {DataTabel.TableInfo.KOLOM_NIP_BAWAHAN, DataTabel.TableInfo.KOLOM_DESKRIPSI_TUGAS, DataTabel.TableInfo.KOLOM_TARGET_TUGAS, DataTabel.TableInfo.KOLOM_INISIATIF_TUGAS, DataTabel.TableInfo.KOLOM_STATUS_TUGAS};
    Cursor kursor = SQ.query(DataTabel.TableInfo.NAMA_TABEL_TUGAS, kolom, null, null, null, null, null);
    return kursor;
}

public Cursor AmbilDataLogin(DatabaseOperation mOpenHelper) {

    SQLiteDatabase SQ = mOpenHelper.getReadableDatabase();
    String[] kolom = {DataTabel.TableInfo.KOLOM_NIP_USER, DataTabel.TableInfo.KOLOM_PASSWORD_USER};
    Cursor kursor = SQ.query(DataTabel.TableInfo.NAMA_TABEL_USER, kolom, null, null, null, null, null, null);
    return kursor;

}

}

我使用 android studio 发现的错误是

sdb.execSQL("DROP TABLE IF EXIST " + DataTabel.TableInfo.NAMA_TABEL_USER);
    sdb.execSQL("DROP TABLE IF EXIST " +      DataTabel.TableInfo.NAMA_TABEL_TUGAS);
    sdb.execSQL("DROP TABLE IF EXIST " + DataTabel.TableInfo.NAMA_TABEL_VERSI_TUGAS);
    sdb.execSQL("DROP TABLE IF EXIST " + DataTabel.TableInfo.NAMA_TABEL_ATASAN_BAWAHAN);

这么说UNREACABLE STATEMENT

4

1 回答 1

0

在检查了代码后,我发现了问题......:D

这是返回声明....

Properties properties = new Properties();
intent.putExtra(SymmetricService.INTENTKEY_PROPERTIES, properties);

getContext().startService(intent);

return;

//SETTING SYMMETRIC

sdb.execSQL(CREATE_QUERY_TABEL_USER);
sdb.execSQL(CREATE_QUERY_TABEL_TUGAS);
sdb.execSQL(CREATE_QUERY_TABEL_VERSI_TUGAS);
sdb.execSQL(CREATE_QUERY_TABEL_ATASAN_BAWAHAN);
Log.d("Database operations", "Table created");
}

在我删除它之后一切正常(编译器构建)

Properties properties = new Properties();
intent.putExtra(SymmetricService.INTENTKEY_PROPERTIES, properties);

getContext().startService(intent);

//SETTING SYMMETRIC

sdb.execSQL(CREATE_QUERY_TABEL_USER);
sdb.execSQL(CREATE_QUERY_TABEL_TUGAS);
sdb.execSQL(CREATE_QUERY_TABEL_VERSI_TUGAS);
sdb.execSQL(CREATE_QUERY_TABEL_ATASAN_BAWAHAN);
Log.d("Database operations", "Table created");
}

但是当我启动应用程序时,我从 logcatt 收到此错误,表明数据库尚未与服务器同步......

12-27 07:22:56.337 2986-2986/net.ddns.manajemenpekerjaan.manajemenpekerjaan D/Database operations: Database created
12-27 07:22:56.387 2986-2986/net.ddns.manajemenpekerjaan.manajemenpekerjaan D/AndroidRuntime: Shutting down VM
12-27 07:22:56.397 2986-2986/net.ddns.manajemenpekerjaan.manajemenpekerjaan W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41465730)
12-27 07:22:56.427 2986-2986/net.ddns.manajemenpekerjaan.manajemenpekerjaan E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                          android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
                                                                                              at android.database.AbstractCursor.checkPosition(AbstractCursor.java:424)
                                                                                              at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
                                                                                              at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
                                                                                              at net.ddns.manajemenpekerjaan.manajemenpekerjaan.MenuLogin.onClick(MenuLogin.java:47)
                                                                                              at android.view.View.performClick(View.java:4240)
                                                                                              at android.view.View$PerformClick.run(View.java:17721)
                                                                                              at android.os.Handler.handleCallback(Handler.java:730)
                                                                                              at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                                              at android.os.Looper.loop(Looper.java:137)
                                                                                              at android.app.ActivityThread.main(ActivityThread.java:5103)
                                                                                              at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                              at java.lang.reflect.Method.invoke(Method.java:525)
                                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
                                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                                                                              at dalvik.system.NativeStart.main(Native Method)
12-27 07:22:59.006 2986-2986/? I/Process: Sending signal. PID: 2986 SIG: 9

知道如何使应用程序与服务器人员同步吗?

于 2015-12-27T12:25:08.667 回答