在我的安卓应用中:
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
private static Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl(BuildConfig.API_BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(CoroutineCallAdapterFactory.Companion.create())
.client(httpClient.build());
public class Trader implements Serializable {
private String id;
private long last_iteration_time;
private double last_bnc_btx_diff_entrance_percent;
}
Run Code Online (Sandbox Code Playgroud)
改造接口方法:
import kotlinx.coroutines.Deferred
import com.myproject.model.Trader
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query
@GET("traders/json")
suspend fun getTraidersList(): Deferred<Response<List<Trader>>>
Run Code Online (Sandbox Code Playgroud)
并使用它:
suspend fun getTraidersList(): TransportResponse = withContext(Dispatchers.IO) {
val traderMonitorRestClient = RestClientFactory.createRestClient(TraderMonitorRestClient::class.java)
val operrationDeferred: Deferred<Response<List<Trader>>> = traderMonitorRestClient.getTraidersList()
executeAwaitOperation(operrationDeferred) …Run Code Online (Sandbox Code Playgroud) 在我的 agent_details_activity.xml 中:
<ImageView
android:id="@+id/imageViewPhoto"
android:layout_width="0dp"
android:layout_height="400dp"
app:agentImageUrl="@{item.url}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolBarContainer" />
Run Code Online (Sandbox Code Playgroud)
在活动中:
class AgentDetailsActivity : AppCompatActivity() {
private lateinit var binding: AgentDetailsActivityBinding
companion object {
val AGENT_DETAILS = AgentDetailsActivity::class.java.name + "_AGENT_DETAILS"
}
private val TAG = AgentDetailsActivity::class.java.name
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = AgentDetailsActivityBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.setHandler(this);
}
@BindingAdapter("agentImageUrl")
fun loadImage(view: ImageView, imageUrl: String) {
Glide.with(view.context)
.load(imageUrl)
.apply(RequestOptions().error(R.drawable.no_image))
.into(view)
}
Run Code Online (Sandbox Code Playgroud)
但在运行时我得到错误:
Shutting down VM
FATAL EXCEPTION: main
Process: com.android.testproject.android.kotlin.debug, PID: 24924
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.testproject.android.kotlin.debug/com.android.testproject.android.kotlin.coroutine_retrofit.ui.activity.AgentDetailsActivity}: java.lang.IllegalStateException: …Run Code Online (Sandbox Code Playgroud) 我在我的项目中使用 Gradle 6.1 版。
该项目的build.gradle如下:
plugins {
id 'application'
}
application {
mainClass = 'com.mytestproject.Main'
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
group 'com.mytestproject'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行这个命令时./gradlew assemble,它给了我下面给出的错误:
./gradlew assemble
FAILURE: Build failed with an exception.
* Where:
Build file '/com/myproject/build.gradle' line: 6
* What went wrong:
A problem occurred evaluating root project 'JavaTestProject'.
> Could not set unknown …Run Code Online (Sandbox Code Playgroud) Linux 薄荷 20.2
PostgreSQL 9.6。
脚步:
sudo systemctl enable postgresql.service
Run Code Online (Sandbox Code Playgroud)
结果:
Synchronizing state of postgresql.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable postgresql
Run Code Online (Sandbox Code Playgroud)
然后像这样重新启动服务:
sudo service postgresql restart
Run Code Online (Sandbox Code Playgroud)
当检查状态时,如下所示:
service postgresql status
Run Code Online (Sandbox Code Playgroud)
我明白了:
postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Wed 2021-08-04 17:33:34 EEST; 47s ago
Process: 29261 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 29261 (code=exited, status=0/SUCCESS)
Run Code Online (Sandbox Code Playgroud)
为什么服务已退出?
这里的内容/var/log/postgresql/postgresql-9.6-main.log
2021-08-05 14:59:14.739 EEST [116538] LOG: database system was shut …Run Code Online (Sandbox Code Playgroud) 爪哇8,
我想在我的 java 项目中使用 JUnit 4。
在我的 build.gradle 中
dependencies {
implementation 'org.apache.commons:commons-lang3'
implementation 'org.apache.logging.log4j:log4j-api'
implementation 'org.apache.logging.log4j:log4j-core'
implementation 'org.apache.logging.log4j:log4j-slf4j-impl'
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.2'
testImplementation('org.assertj:assertj-core:3.21.0')
testImplementation('org.mockito:mockito-core:4.0.0')
testImplementation('junit:junit:4.13.2')
}
Run Code Online (Sandbox Code Playgroud)
这是我的单元测试:
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.*;
import static org.assertj.core.api.Assertions.assertThat;
public class VsatVlansNSTest {
@BeforeClass
public static void setupAll() {
//
}
@Test
public void find_NS_2_4_higher_matcher() {
// some test here
}
}
Run Code Online (Sandbox Code Playgroud)
但我收到错误:
g.gradle.api.internal.tasks.testing.TestSuiteExecutionException: Could not complete execution for Gradle Test Executor 5.
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:63)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) …Run Code Online (Sandbox Code Playgroud) IntelliJ IDEA 2022.3.3(社区版)JDK 1.8
这是我的App.java
public class App {
public String getGreeting() {
return "Interesting cases!" +
"\nJDK: " + System.getProperty("java.version");
}
public static void main(String[] args) {
System.out.println(new App().getGreeting());
}
}
Run Code Online (Sandbox Code Playgroud)
这里的build.gradle:
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java application project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual …Run Code Online (Sandbox Code Playgroud) Windows 10(64位).Android Studio 2.3.
我的Android模拟器位于文件夹中:
d:\程序\的Android\avd.android\AVD\Nexus_4_4.avd \
假设我在文件夹D:\ temp中.
如何从文件夹D:\ temp我可以启动我的模拟器(从PC的命令行)?
在我的 Kotlin, Retrofit 2 项目中:
class TransportService {
// static analog
companion object {
@JvmStatic
fun checkoutSessions(bodyMap: Map<String, Any>, callback: Callback<Void>) {
val stripeMonitorRestClient = RestClientFactory.createRestClient(StripeRestClient::class.java!!)
val headerMap = mutableMapOf<String, String>()
headerMap["Accept"] = "application/json"
headerMap["Content-Type"] = "application/x-www-form-urlencoded"
headerMap["Stripe-Version"] = "2019-03-14; checkout_sessions_beta=v1"
headerMap["Authorization"] = "Bearer sk_test_4eC39HqLyjWDarjtT1zdp7dc"
val adMessagesList = stripeMonitorRestClient.checkoutSessions(headerMap, bodyMap) // error here
// asynchronously
adMessagesList.enqueue(callback)
}
}
}
Run Code Online (Sandbox Code Playgroud)
和休息客户端api:
import retrofit2.Call
import retrofit2.http.FieldMap
import retrofit2.http.HeaderMap
import retrofit2.http.POST
import retrofit2.http.FormUrlEncoded
interface StripeRestClient {
@FormUrlEncoded
@POST("checkout/sessions")
fun checkoutSessions(@HeaderMap headers: Map<String, String>, …Run Code Online (Sandbox Code Playgroud) 在我的 Android 应用程序中,我使用 Retrofit 2:
public enum OperationType {
@SerializedName("payment")
PAYMENT,
@SerializedName("payout")
PAYOUT,
@SerializedName("transfer")
TRANSFER
}
fun getOperationsList(typeList: List<OperationType>, callback: Callback<List<Operation>>) {
val call = myRestClient.getOperationsList(typeList)
executeRequest(call, callback)
}
@GET("/operations")
fun getOperationsList(@Query("type") typeList: List<OperationType>): Call<List<Operation>>
Run Code Online (Sandbox Code Playgroud)
但我在这一行收到运行时错误:
val call = myRestClient.getOperationsList(typeList)
Run Code Online (Sandbox Code Playgroud)
错误:
Shutting down VM
FATAL EXCEPTION: main
Process: md.qsystems.android.tango.debug, PID: 22714
java.lang.IllegalArgumentException: Parameter type must not include a type variable or wildcard: java.util.List<? extends OperationType> (parameter #1)
for method TangoRestClient.getOperationsList
at retrofit2.Utils.methodError(Utils.java:52)
at retrofit2.Utils.methodError(Utils.java:42)
at retrofit2.Utils.parameterError(Utils.java:61)
at retrofit2.RequestFactory$Builder.validateResolvableType(RequestFactory.java:764)
at retrofit2.RequestFactory$Builder.parseParameterAnnotation(RequestFactory.java:401) …Run Code Online (Sandbox Code Playgroud) android ×4
gradle ×2
java ×2
retrofit2 ×2
build.gradle ×1
gradlew ×1
junit4 ×1
kotlin ×1
linux-mint ×1
postgresql ×1