Я следовал этому Ссылка
ОШИБКА:
"Ошибка привела к сбою пакета без попытки загрузки данных для серии 000--9999"
Android подключается к серверу SymmetricDS, но не может получить данные, и из-за этой ошибки Ошибка
Мой класс dbProvider:
public class DbProvider extends ContentProvider {
//TODO: Update REGISTRATION_URL with Sync URL of corp-000
private final String REGISTRATION_URL = "http://172.18.21.239:8080/sync/corp-000";
private final String NODE_ID = "002";
private final String NODE_GROUP = "store";
final String SQL_CREATE_TABLE_ITEM = "CREATE TABLE IF NOT EXISTS item(\n" +
" item_id INTEGER NOT NULL PRIMARY KEY ,\n" +
" name VARCHAR\n" +
");";
final String SQL_CREATE_TABLE_ITEM_SELLING_PRICE = "CREATE TABLE IF NOT EXISTS item_selling_price(\n" +
" item_id INTEGER NOT NULL,\n" +
" store_id VARCHAR NOT NULL,\n" +
" price DECIMAL NOT NULL,\n" +
" cost DECIMAL,\n" +
" PRIMARY KEY (item_id, store_id)\n" +
");";
final String SQL_CREATE_TABLE_SALE_TRANSACTION = "CREATE TABLE IF NOT EXISTS sale_transaction(\n" +
" tran_id INTEGER NOT NULL PRIMARY KEY ,\n" +
" store_id VARCHAR NOT NULL,\n" +
" workstation VARCHAR NOT NULL,\n" +
" day VARCHAR NOT NULL,\n" +
" seq INTEGER NOT NULL\n" +
");\n";
final String SQL_CREATE_TABLE_SALE_RETURN_LINE_ITEM = "CREATE TABLE IF NOT EXISTS sale_return_line_item(\n" +
" tran_id INTEGER NOT NULL PRIMARY KEY ,\n" +
" item_id INTEGER NOT NULL,\n" +
" price DECIMAL NOT NULL,\n" +
" quantity INTEGER NOT NULL,\n" +
" returned_quantity INTEGER\n" +
");\n";
public static final String DATABASE_NAME = "mydb.db";
// Handle to a new DatabaseHelper.
private DatabaseHelper mOpenHelper;
/**
* This class helps open, create, and upgrade the database file. Set to package visibility
* for testing purposes.
*/
static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
// calls the super constructor, requesting the default cursor factory.
super(context, DATABASE_NAME, null, 2);
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
onCreate(db);
}
}
/**
* Initializes the provider by creating a new DatabaseHelper. onCreate() is called
* automatically when Android creates the provider in response to a resolver request from a
* client.
*/
@Override
public boolean onCreate() {
// Creates a new helper object. Note that the database itself isn't opened until
// something tries to access it, and it's only created if it doesn't already exist.
mOpenHelper = new DatabaseHelper(getContext());
// Init the DB here
mOpenHelper.getWritableDatabase().execSQL(SQL_CREATE_TABLE_ITEM);
mOpenHelper.getWritableDatabase().execSQL(SQL_CREATE_TABLE_ITEM_SELLING_PRICE);
mOpenHelper.getWritableDatabase().execSQL(SQL_CREATE_TABLE_SALE_TRANSACTION);
mOpenHelper.getWritableDatabase().execSQL(SQL_CREATE_TABLE_SALE_RETURN_LINE_ITEM);
// Register the database helper, so it can be shared with the SymmetricService
SQLiteOpenHelperRegistry.register(DATABASE_NAME, mOpenHelper);
Intent intent = new Intent(getContext(), SymmetricService.class);
intent.putExtra(SymmetricService.INTENTKEY_SQLITEOPENHELPER_REGISTRY_KEY, DATABASE_NAME);
intent.putExtra(SymmetricService.INTENTKEY_REGISTRATION_URL, REGISTRATION_URL);
intent.putExtra(SymmetricService.INTENTKEY_EXTERNAL_ID, NODE_ID);
intent.putExtra(SymmetricService.INTENTKEY_NODE_GROUP_ID, NODE_GROUP);
intent.putExtra("sourceGroupId", "corp");
intent.putExtra(SymmetricService.INTENTKEY_START_IN_BACKGROUND, true);
// TODO: Update properties with the desired Symmetric parameters (e.g. File Sync parameters)
Properties properties = new Properties();
properties.put(ParameterConstants.FILE_SYNC_ENABLE, "true");
properties.put("start.file.sync.tracker.job", "true");
properties.put("start.file.sync.push.job", "true");
properties.put("start.file.sync.pull.job", "true");
properties.put("job.file.sync.pull.period.time.ms", "10000");
properties.put("initial.load.use.extract.job.enabled", "true");
properties.put("stream.to.file.enabled", "true");
intent.putExtra(SymmetricService.INTENTKEY_PROPERTIES, properties);
getContext().startService(intent);
// Assumes that any failures will be reported by a thrown exception.
return true;
}
@Nullable
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
return null;
}
public String getType(Uri uri) {
throw new IllegalArgumentException("Unknown URI " + uri);
}
@Nullable
@Override
public Uri insert(Uri uri, ContentValues values) {
return null;
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
return 0;
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
return 0;
}
}
, помогите мнеЧтобы решить эту проблему.
Та же проблема была опубликована здесь !
, но все предоставленные решения не могут решить мою проблему.
DbProvider isиспользуется в mainActivity:
public class MainActivity extends AppCompatActivity {
private static final String INSERT_SQL = "insert into sale_transaction (store_id, workstation, day, seq) values ('301','3','1',55)";
private static final String SELECT_SQL = "select * from item";
private final int COLUMN_WIDTH = 14;
/**
* onCreate is called when Android starts this Activity from scratch.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText sqlTextField = (EditText)findViewById(R.id.sqlTextField);
final TextView outputTextView = (TextView)findViewById(R.id.outputTextView);
outputTextView.setMovementMethod(new ScrollingMovementMethod());
Button runButton = (Button)findViewById(R.id.runButton);
runButton.setOnClickListener(v -> {
String sql = sqlTextField.getText().toString();
SQLiteDatabase db = SQLiteOpenHelperRegistry.lookup(DbProvider.DATABASE_NAME).getReadableDatabase();
Cursor cursor = null;
try {
cursor = db.rawQuery(sql, null);
} catch (Exception ex) {
Context context = getApplicationContext();
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, ex.toString(), duration);
toast.show();
ex.printStackTrace();
return;
}
String tableFormat = "";
StringBuilder buff = new StringBuilder();
while (cursor.moveToNext()) {
List<String> values = new ArrayList<String>();
String[] columnNames = cursor.getColumnNames();
if (buff.length() == 0) {
for (int i = 0; i < cursor.getColumnCount(); i++) {
tableFormat += "%-" + COLUMN_WIDTH + "s|";
}
for (int j = 0; j < columnNames.length; j++) {
columnNames[j] = StringUtils.abbreviate(columnNames[j], COLUMN_WIDTH);
}
buff.append(String.format(tableFormat, columnNames)).append("\n");
}
for (int i = 0; i < cursor.getColumnCount(); i++) {
values.add(StringUtils.abbreviate(cursor.getString(i), COLUMN_WIDTH));
}
buff.append(String.format(tableFormat, values.toArray(new String[0]))).append("\n");
}
outputTextView.setText(buff.toString());
Context context = getApplicationContext();
CharSequence text = "Executed " + sql;
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
});
Button clearButton = (Button)findViewById(R.id.clearButton);
clearButton.setOnClickListener(v -> {
sqlTextField.setText("");
outputTextView.setText("");
});
Button selectButton = (Button)findViewById(R.id.selectButton);
selectButton.setOnClickListener(v -> sqlTextField.setText(SELECT_SQL));
Button insertButton = (Button)findViewById(R.id.insertButton);
insertButton.setOnClickListener(v -> sqlTextField.setText(INSERT_SQL));
Button newFileButton = (Button)findViewById(R.id.newFileButton);
newFileButton.setOnClickListener(v -> {
String fileName = sqlTextField.getText().toString();
File newFile = new File(getStorageDir(v.getContext(), "SymDS").getAbsoluteFile() + "/" + fileName);
try {
newFile.createNewFile();
} catch (Exception ex) {
ex.printStackTrace();
}
});
}
public File getStorageDir(Context context, String directoryName) {
File file =
new File(Environment.getExternalStoragePublicDirectory("/"), directoryName);
System.out.println("canRead " + Environment.getExternalStorageDirectory().canRead());
System.out.println("canWrite " + Environment.getExternalStorageDirectory().canWrite());
boolean ok = file.mkdirs(); //create folders where write files
if (!ok) {
CharSequence text = "Failed to create dir " + file;
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
return file;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return false;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
return false;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return false;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
}
@Override
public boolean onContextItemSelected(MenuItem item) {
return false;
}
}