小编a_s*_*ber的帖子

向 Gson 注册此类型的 InstanceCreator 可能会解决此问题

在我的安卓应用中:

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)

android kotlin-coroutines

11
推荐指数
2
解决办法
1万
查看次数

必需的 DataBindingComponent 在类 AgentDetailsActivityBindingImpl 中为 null

在我的 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)

android android-databinding

11
推荐指数
4
解决办法
6574
查看次数

Android Studio.如何将实时模板导出到文件?

Android Studio 2.3.2.我想导出实时模板 - > AndroidLog到文件. 在此输入图像描述

我怎么能这样做?谢谢.

android-studio

10
推荐指数
2
解决办法
1836
查看次数

无法为扩展“应用程序”设置未知属性“mainClass”

我在我的项目中使用 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)

java gradle gradlew build.gradle

10
推荐指数
1
解决办法
5266
查看次数

未运行 - Active:活动(已退出)

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)

postgresql linux-mint

10
推荐指数
1
解决办法
2万
查看次数

org.gradle.api.internal.tasks.testing.TestSuiteExecutionException:无法完成 Gradle 测试执行器 5 的执行

爪哇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)

java junit4 gradle

10
推荐指数
1
解决办法
1万
查看次数

“executable”属性中的工具链与“javaLauncher”属性中的工具链不匹配

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)

intellij-idea

10
推荐指数
1
解决办法
7240
查看次数

Android:如何从命令行启动模拟器?

Windows 10(64位).Android Studio 2.3.

我的Android模拟器位于文件夹中:

d:\程序\的Android\avd.android\AVD\Nexus_4_4.avd \

假设我在文件夹D:\ temp中.

如何从文件夹D:\ temp我可以启动我的模拟器(从PC的命令行)?

android android-emulator

9
推荐指数
5
解决办法
2万
查看次数

Kotlin,改造 2:lang.IllegalArgumentException:参数类型不得包含类型变量或通配符:java.util.Map&lt;java.lang.String, ?&gt;

在我的 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)

kotlin retrofit2

9
推荐指数
2
解决办法
3664
查看次数

参数类型不得包含类型变量或通配符

在我的 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 retrofit2

9
推荐指数
1
解决办法
6353
查看次数