我希望有人遇到我在构建我的java/Kotlin项目时遇到的问题.该项目与java和kotlin互操作,具有以下版本:
在我做了一些改变之前,Kotlin编译得很好,即将几个java类转换为等效的kotlin版本.
以下是我看到的错误:
c:\projects\myproject>gradlew :java:workspace:models:compileKotlin --stacktrace :java:workspace:models:compileKotlin
w: Annotations path entry points to a non-existent location:
C:\projects\myproject\java\workspace\models\annotations
e: C:\projects\CustomerProfileEmail.kt: (15, 32): Unresolved reference: toLowerCase
e: C:\projects\CustomerProfilePhone.kt: (34, 22): Unresolved reference: equalsIgnoreCase
e: C:\projects\Account.kt: (17, 21): Unresolved reference: javaClass
e: C:\projects\Account.kt: (18, 21): Unresolved reference: javaClass
e: C:\projects\Account.kt: (31, 15): Unresolved reference: indexOf
e: C:\projects\Account.kt: (35, 15): Expression 'length' of type 'kotlin.Int' cannot be invoked as a function. The function invoke() is not found
e: C:\projects\Account.kt: (39, …Run Code Online (Sandbox Code Playgroud) 我是Volley和Android的新手.下面是我正在尝试执行的代码片段(Android使用Volley),但它是服务器返回400.使用另一个REST客户端完美地工作.这是使用PUT方法向服务器发出的请求.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
sendRequest();
}
private void sendRequest() {
RequestQueue queue = Volley.newRequestQueue(this);
final JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("password", "ttttt");
jsonObject.put("username", "tester3");
jsonObject.put("token", "blah");
} catch (JSONException e) {
// handle exception
}
JsonObjectRequest putRequest = new JsonObjectRequest(Request.Method.PUT, url, jsonObject,
new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response) {
// response
Log.d("Response", response.toString());
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
// error
Log.d("Error.Response", error.toString());
}
}
) …Run Code Online (Sandbox Code Playgroud) 我觉得我错过了我对以下代码如何工作的理解的一些关键部分:
private fun retrieveAndStore() {
launch(UI) {
val service = retrofit.create(AWSService::class.java)
val response = service.retrieveData().await()
store(data = response)
}
}
private suspend fun store(data: JsonData) {
val db = Room.databaseBuilder(applicationContext, AppDatabase::class.java, "app-db").build()
db.appDao().insert(storyData)
}
Run Code Online (Sandbox Code Playgroud)
这是我在运行时得到的错误:
java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
Run Code Online (Sandbox Code Playgroud)
我不明白为什么网络代码通过改造工作但存储功能失败.我希望有人能告诉我发生了什么事?
有趣的是,如果我用异步{} .await包装db调用它可以工作,这是否意味着协同程序只能调用其他协同程序?