我是新改装的,我使用的是 Retrofit2 版本 2.4.0 。有我的 Api 客户端代码:
public class ApiClient {
public static final String BASE_URL = "https://api.coinmarketcap.com/v1/";
public static Retrofit retrofit = null;
public static Retrofit getApiClient (){
if (retrofit == null){
retrofit = new Retrofit().Builder.baseUrl(BASE_URL).
addConverterFactory(GsonConverterFactory.create()).build();
}
return retrofit;
}
Run Code Online (Sandbox Code Playgroud)
}
这是我的错误:在 'retrofit2.Retrofit' 中不公开,无法从外部访问
它在代码的这一部分向我显示错误:new Retrofit().Builder
我使用SQLiteOpenHelper从资产读取数据库。它适用于除android p以外的所有android版本。
这是我的copyDataBase函数:
private static void copyDataBase() throws IOException {
InputStream myInput = myContext.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
SharedPreferences shData = myContext.getSharedPreferences("data", 0);
SharedPreferences.Editor editor = shData.edit();
editor.putBoolean("databaseIsOnMemory", true);
editor.commit();
}
Run Code Online (Sandbox Code Playgroud)
我在这个函数中放了一个日志,它确实通过了它。但我收到此错误:
android.database.sqlite.SQLiteException: no such table: irancell (code 1 SQLITE_ERROR)
Run Code Online (Sandbox Code Playgroud)
这就是我如何获取数据:
c = myDataBase.query(true, Table_Name, new String[] {IDData,TextData},
null,null,null,null,null, null);
c.moveToFirst();
int i = 1; …Run Code Online (Sandbox Code Playgroud)