小编Ege*_*glu的帖子

意外覆盖:以下声明具有相同的JVM签名

我在Kotlin中遇到了这个错误:

class GitHubRepoAdapter(private val context: Context,
    private val values: List<GithubRepo>) : ArrayAdapter<GithubRepo>(context, R.layout.list_item,
    values) {
Run Code Online (Sandbox Code Playgroud)

私有val上下文:上下文

在日志中它说:

错误:(14,25)意外覆盖:以下声明具有相同的JVM签名(getContext()Landroid/content/Context;):fun():Context fun getContext():Context!

我无法看到导致问题的原因.

kotlin kotlin-extension kotlin-android-extensions

46
推荐指数
4
解决办法
2万
查看次数

无法在提供的主机和端口上连接到MongoDB

我只是想为MongoDB尝试MongoDB Compass GUI,但是当我尝试使用本地主机端口连接时:27017我收到此错误:

无法在提供的主机和端口上连接到MongoDB

我在YouTube上按照这些说明操作.

mongodb mongodb-compass

34
推荐指数
6
解决办法
6万
查看次数

为什么"不推荐使用getString()来获取设备标识符?

我正在尝试将我的设备ID提供给Logcat,但Android Studio正在向我发出此警告.

建议不要使用getstring来获取设备标识符

String deviceID = Settings.Secure.getString(getApplicationContext().getContentResolver(),
        Settings.Secure.ANDROID_ID);
Run Code Online (Sandbox Code Playgroud)

为什么不推荐?

java android

30
推荐指数
1
解决办法
8360
查看次数

如何在 Jetpack Compose 中将屏幕高度分成两半?

我想在 Jetpack Compose 中将屏幕水平分成两半,如下所示: 在此输入图像描述

    @Composable
fun Splash(alpha: Float) {
    val configuration = LocalConfiguration.current
    val screenHeight = configuration.screenHeightDp.dp
    val screenWidth = configuration.screenWidthDp.dp
    val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.cat2))
    Box(
        modifier = Modifier
            .background(Blue)
            .height(screenHeight /  2)
            .padding(8.dp),
        contentAlignment = Alignment.TopCenter
    ) {
        Column() {
            Text(text = "Example", fontSize = 44.sp)
        }
    }
    Box(
        modifier = Modifier
            .background(Red)
            .height(screenHeight /  2)
            .padding(8.dp),
        contentAlignment = Alignment.BottomCenter
    ){
        Column {
           
            Text(text = "Example", textAlign = TextAlign.End, color = Grey, fontSize = 12.sp)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我可以使用 …

android android-jetpack-compose

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

是否可以在Android Studio中删除我的代码中的所有评论?

我一直在Android Studio中开展一个项目,它有很多评论.是否可以删除代码中的所有注释(单行//和多行/*)?优选地,不处理正则表达式.

android android-studio

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

如何以编程方式滚动recyclerView?

我有一个水平的recyclerView,当我第一次打开活动时,我想让recyclerview中的所有项目滚动到底部(在这种情况下向右)并返回到顶部(向左).有点像动画.滚动行为应该对用户可见.

我试着这样做:

Animation slideRight = AnimationUtils.loadAnimation(this, R.anim.slide_right);
        Animation slideLeft = AnimationUtils.loadAnimation(this, R.anim.slide_left);
        slideRight.setDuration(1000);
        slideLeft.setDuration(1000);
        slideRight.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                recyclerView.startAnimation(slideLeft);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        recyclerView.startAnimation(slideRight);
Run Code Online (Sandbox Code Playgroud)

anim slide left:

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <translate
        android:duration="200"
        android:fromXDelta="-100%"
        android:fromYDelta="0%"
        android:toXDelta="0%"
        android:toYDelta="0%" />

</set>
Run Code Online (Sandbox Code Playgroud)

向右滑动:

<translate
    android:duration="200"
    android:fromXDelta="100%"
    android:fromYDelta="0%"
    android:toXDelta="0%"
    android:toYDelta="0%" />
Run Code Online (Sandbox Code Playgroud)

它可以工作,但它只是将recyclerview作为一个整体滑动,我只想滚动(滑动)项目.我怎样才能做到这一点?

android android-layout android-recyclerview

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

如何在项目gradle.properties中设置org.gradle.jvmargs=-Xmx5120M?

我明白了

为了在进程中运行 dex,Gradle 守护进程需要更大的堆。

错误,我想添加org.gradle.jvmargs=-Xmx5120M到我的 gradle.properties 来解决这个问题。但是,我在我的项目中找不到该gradle.properties文件。

android gradle android-gradle-plugin gradle.properties

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

如何使用RxJava 2 + Retrofit 2进行发布?

这个问题可能听起来很简单,但我很难过.

我可以通过这种方式进行改造2:

class RetrofitClient {

    private static Retrofit retrofit = null;

    static Retrofit getClient(String baseUrl) {
        if (retrofit == null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl(baseUrl)
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
        }
        return retrofit;
    }

}
Run Code Online (Sandbox Code Playgroud)

Api服务界面:

 @POST("postsInit")
    @FormUrlEncoded
    Call<InitPost> postInit(
            @Field("appVersion") String versionName,
            @Field("appId") String applicationId,

    );
Run Code Online (Sandbox Code Playgroud)

最后:

apiService.postInit(versionName, applicationId).enqueue(new Callback<InitPost>() {
            @Override
            public void onResponse(@NonNull Call<InitPost> call, @NonNull Response<InitPost> response) {

                if (response.isSuccessful()) {
                    Timber.d("post submitted to API");
                    getInitResponse();
                }
            }

            @Override
            public void onFailure(@NonNull Call<InitPost> call, @NonNull Throwable t) …
Run Code Online (Sandbox Code Playgroud)

android rx-java retrofit2 rx-java2

6
推荐指数
1
解决办法
4068
查看次数

RecyclerView Item 的按下状态

我使用水平 recyclerview 作为自定义底部导航栏。我想为每个项目定义一个按下状态,以便它们的颜色可以改变。

我试图这样做,但无法管理它

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/menu_pressed" android:state_activated="true" />
    <item android:drawable="@color/menu_pressed" android:state_pressed="true" />
    <item android:drawable="@color/menu_pressed" android:state_checked="true" />
    <item android:drawable="@color/menu_pressed" android:state_focused="true" />
    <item android:drawable="@color/menu" />
</selector>
Run Code Online (Sandbox Code Playgroud)

回收者观点:

 <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="65dp"
        android:layout_gravity="bottom"
        android:background="@drawable/menu_selector"
        android:fadingEdge="vertical|horizontal"
        android:fadingEdgeLength="60dp"
        android:fillViewport="false"
        android:requiresFadingEdge="horizontal|vertical"
        app:layoutManager="android.support.v7.widget.LinearLayoutManager"
        android:clickable="true"
        android:focusable="true"
        android:focusableInTouchMode="true">
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview

6
推荐指数
1
解决办法
1815
查看次数

从1方法中剥离无效的本地信息 - Proguard

之后我收到了这个警告gradle build.我认为这与我Proguard rules和我有关Logs.我怎样才能"删除无效的当地人信息"?

我想将我的Log包装到LogUtil类:

public class LogUtils {
    public static void debug(final String tag, String message) {
        if (BuildConfig.DEBUG) {
            Log.d(tag, message);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

并将其添加到proguard规则

-assumenosideeffects class android.util.Log {
    public static *** d(...);
}
Run Code Online (Sandbox Code Playgroud)

是一个很好的解决方案,但我的项目中有很多Log.d,所以这很难.

与木材相同的问题.我认为转换为时已晚

if (BuildConfig.DEBUG) {
  Timber.plant(new Timber.DebugTree());
}
Run Code Online (Sandbox Code Playgroud)

android proguard android-proguard

6
推荐指数
1
解决办法
6788
查看次数