小编tyn*_*ynn的帖子

无法访问活动绑定android

我有一个名为activity_suggestions. 我在其中使用数据绑定。因此文件ActivitySuggestionsBinding被生成。项目编译成功。但是当我尝试运行该项目时,出现此错误

e: error: cannot access ActivitySuggestionsBinding
Run Code Online (Sandbox Code Playgroud)

我正在使用3.1.2带有 kotlin 版本的android studio 1.4.1。任何帮助将不胜感激

编辑
粘贴我的模块级别 build.gradle 和应用级别 build.gradle

模块 Build.gradle

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {

    dataBinding {
        enabled = true
    }
..
}

dependencies{
..
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation "com.google.dagger:dagger:$rootProject.daggerVersion"
    implementation "com.google.dagger:dagger-android:$rootProject.daggerVersion"
    implementation "com.google.dagger:dagger-android-support:$rootProject.daggerVersion"
    kapt "com.google.dagger:dagger-android-processor:$rootProject.daggerVersion"
    kapt "com.google.dagger:dagger-compiler:$rootProject.daggerVersion"
    provided 'javax.annotation:jsr250-api:1.0'
    implementation "android.arch.lifecycle:runtime:$rootProject.archVersion"
    implementation "android.arch.lifecycle:extensions:$rootProject.archVersion"
    annotationProcessor "android.arch.lifecycle:compiler:$rootProject.archVersion"
    kapt "com.android.databinding:compiler:3.1.2"
..
}
Run Code Online (Sandbox Code Playgroud)

应用程序构建.gradle

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android{

    dataBinding{
        enabled = true …
Run Code Online (Sandbox Code Playgroud)

data-binding android kotlin android-databinding android-studio-3.0

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

Android Kotlin MockMaker问题

嗨,我正在尝试模拟最后一个类(默认情况下,kotlin中的所有类都是最终类),并在gradle中添加了以下依赖项:

testImplementation 'junit:junit:4.12'
testImplementation 'au.com.dius:pact-jvm-consumer-junit_2.11:3.5.10'
testImplementation "org.mockito:mockito-android:2.13.0"
testImplementation 'org.mockito:mockito-inline:2.13.0'
testImplementation "org.mockito:mockito-core:2.13.0"
//testImplementation 'io.mockk:mockk:1.8'
testImplementation 'org.assertj:assertj-core:3.8.0'

androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation "org.mockito:mockito-core:2.13.0"
androidTestImplementation "org.mockito:mockito-android:2.13.0"
androidTestImplementation 'org.mockito:mockito-inline:2.13.0'
androidTestImplementation "com.android.support.test.espresso:espresso-intents:3.0.2"
Run Code Online (Sandbox Code Playgroud)

该模仿内联应该使您能够模拟最终的kotlin类,因此我使用testImplementation和androidTestImplementation将其添加到我的Java单元测试和仪器测试中

在构建项目时,出现以下错误:

More than one file was found with OS independent path 'mockito-extensions/org.mockito.plugins.MockMaker'
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?如果我删除了类内联的androidTestImplementation,它可以正常编译,但是在运行仪器测试时,我收到了类比错误,说它无法模拟最终类。

android mockito kotlin

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

Kotlin 数据类 | 添加我自己的变量而不是 JSON 键

我正在为我的 andorid 应用程序使用改造和 kotlin。

对于我的 API 之一,我有以下数据类

class Set(val set_id: Long, val tickets: List<Ticket>, val timer: Int) {}
class Ticket(val ticket_id: Long, val rows: List<Row>) {}
class Row(val row_id: Long, val row_numbers: List<Int>) {}
Run Code Online (Sandbox Code Playgroud)

示例 JSON 数据

{
  "set_id": 60942,
  "tickets": [
    {
      "ticket_id": 304706,
      "rows": [
        {
          "row_id": 914116,
          "row_numbers": [
            0,
            11,
            21,
            0,
            42,
            52,
            0,
            76,
            85
          ]
        }
      ]
    }
  ],
  "timer": 12
}
Run Code Online (Sandbox Code Playgroud)

Set类包含一个列表,Ticket每张票都有一个列表Row

我的 JSON 对象仅包含这些值,并且在此之前工作正常。改造映射也有效。

问题: 我想isPlaying …

android json gson kotlin retrofit2

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

在 Android 上使用 Chrome 打开 android-app 方案

我想知道我必须如何配置我的应用程序才能打开它android-app://application.id

adb shell am start android-app://application.id
Run Code Online (Sandbox Code Playgroud)

URI_ANDROID_APP_SCHEME如记录似乎不工作。相反,Chrome 和 Firefox 只打开market://我的应用程序的链接。

对于 Chrome,我找到了一个仅描述该intent://方案的文档

当意图过滤器包含DEFAULTBROWSABLE类别时,它适用于Firefox

<intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.LAUNCHER" />
    <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

android google-chrome android-intent firefox-android android-chrome

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

使用 unicode 字符 u201c

我是 python 的新手,在理解 unicode 时遇到问题。我正在使用 Python 3.4。我花了一整天试图通过阅读有关 unicode 的信息来解决这个问题,包括http://www.fileformat.info/info/unicode/char/201C/index.htmhttp://python-notes.curiousefficiency.org /en/latest/python3/text_file_processing.html

我需要引用特殊引号,因为它们用于我正在分析的文本中。我确实测试过 W7 命令窗口可以读写 2 个特殊引号字符。为了简单起见,我写了一个单行脚本:

print ('“') # that's the special quote mark in between normal single quotes
Run Code Online (Sandbox Code Playgroud)

并得到这个输出:

Traceback (most recent call last):
  File "C:\Users\David\Documents\Python34\Scripts\wordCount3.py", line 1, in <module>
    print ('\u201c')
  File "C:\Python34\lib\encodings\cp437.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u201c' in position 0: character maps to <undefined>
Run Code Online (Sandbox Code Playgroud)

那么我如何写一些东西来引用这两个字符u201Cu201D

这是文件打开语句中的正确编码选择吗?

with open(fileIn, mode='r', encoding='utf-8', errors='replace') as f:
Run Code Online (Sandbox Code Playgroud)

python unicode encoding utf-8 python-3.x

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

使用 kotlin 时在单元测试和仪器测试之间共享代码

类似问题:在 Android Studio 中的 Android Instrumentation 测试和单元测试之间共享代码

我的设置如下:

  • src/test包含单元测试的文件夹。这些可以是 Java 或 Kotlin 类
  • src/androidTest包含仪器测试。这些也可以是 Java 或 Kotlin 类
  • src/sharedTest 是一个文件夹,其中包含一堆在单元测试和仪器测试之间共享的实用程序。

这种共享在 gradle 中定义为:

sourceSets {
    test.java.srcDirs += 'src/sharedTest/java'
    androidTest.java.srcDirs += 'src/sharedTest/java'
}
Run Code Online (Sandbox Code Playgroud)

这允许任何Java类在src/testsrc/androidTest访问 utils。但不是 Kotlin 单元测试。我的假设是它们没有添加到 sourceSets 中。

我的问题是:我怎样才能添加它们?我试过:

sourceSets {
    test.kotlin.srcDirs += 'src/sharedTest/java'
}
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用。

java android unit-testing kotlin

5
推荐指数
1
解决办法
553
查看次数

如何在自定义视图中获取android默认属性

我创建了一个简单的自定义视图,其中包含a RelativeLayoutEditText:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/edt_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

此外,我添加了一些自定义属性res/values/attrs.xml,我在自定义视图构造函数中检索这些属性,一切正常.

现在,我想EditText在自定义视图中检索默认属性,例如我想android:text在自定义视图中获取属性.

我的自定义视图类(简化):

public class CustomEditText extends RelativeLayout {
    private int panCount;

    public CustomEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs,
            R.styleable.CustomEditText, 0, 0);
        try {
            this.panCount = typedArray.getInt(R.styleable.CustomEditText_panCount, 16);
        } finally {
            typedArray.recycle();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果不重新声明文本属性,我怎么能这样做res/values/attrs.xml呢?

android android-widget custom-view android-custom-view android-attributes

5
推荐指数
1
解决办法
5108
查看次数

使用Completable.timer对RxJava进行单元测试

Android Studio 3.5.2
RxJava2
Kotlin 1.3.50
Run Code Online (Sandbox Code Playgroud)

我有下面的类,它像一个计时器。

class DelayTimerImp(private val scheduler: IScheduler)
    : DelayTimer {

    override fun createTimeout(delay: Long, timeUnites: TimeUnit): Completable {
        return Completable.timer(delay, TimeUnit.SECONDS, scheduler.main())
    }
}
Run Code Online (Sandbox Code Playgroud)

我在这样的方法中使用它:

private fun startTimeoutRequest(delay: Long) {
    compositeSubscription.add(delayTimer.createTimeout(delay, TimeUnit.SECONDS)
            .subscribeOn(schedulers.io())
            .subscribe(::timeoutHasExceeded, ::timeoutError))
}
Run Code Online (Sandbox Code Playgroud)

在我的测试类中,它使用TestScheduler来返回io线程。我在嘲笑delayTimer。即使我thenReturn(Completable.complete())的方法timeOutHasExceeded不会进入他们。我认为如果Completable已完成进入该方法。

@Test
fun `should reload and show loading state`() {
    // Arrange
    whenever(delayTimer.createTimeout(10, TimeUnit.SECONDS))
            .thenReturn(Completable.complete())

    // Act
    vipInformationPresenterImp.tryAgainTapped()

    // Assert methods in the timeOutHasExceeded
}
Run Code Online (Sandbox Code Playgroud)

另外,如果我通过将延迟更改为来更改以下内容1

whenever(delayTimer.createTimeout(1, …
Run Code Online (Sandbox Code Playgroud)

android kotlin rx-java2

5
推荐指数
1
解决办法
186
查看次数

图像(base64)无法正确上传

不幸的是,当我尝试将一些图像从Android设备上传到数据库时,我遇到了一些问题.图像位于文件夹中.此文件夹包含图像以及其他内容.我不知道图像的名称,我只需要上传图像(jpg).在我上传图像之前,我需要使用base64对它们进行编码.

首先,我从文件夹中获取jpg文件.然后我从图像名称中获取ID.之后我通过base64编码:

Button upload = (Button) findViewById(R.id.upload);
upload.setOnClickListener(new View.OnClickListener() {
    public void onClick(View arg0) {
        String path = Environment.getExternalStorageDirectory().getPath();
        File dir = new File(path);
        File[] files = dir.listFiles();

        for (int i = 0; i < files.length; ++i) {
            if (files[i].getName().endsWith(".jpg")) {
                pics = new File(String.valueOf(files[i]));
                id = String.valueOf(files[i]);
                String sub = id.substring(id.lastIndexOf("/") + 1);
                int index = sub.indexOf("_");
                String book;
                if (index >= 0) {
                    book = sub.substring(0, index);
                    ID = book;
                    Log.e("ID", ID);
                }
                Bitmap imagex = BitmapFactory.decodeFile(pics.getAbsolutePath());
                ByteArrayOutputStream …
Run Code Online (Sandbox Code Playgroud)

java base64 android android-asynctask

4
推荐指数
1
解决办法
316
查看次数

如何将const char*从python传递给c函数

ctypes在Python中使用它来打开一个用C++编写的文件.

我的C++代码:

extern "C" {
void openfile(const char *filename) {
    cout<<"File to open for writing = " <<filename<<endl;
    FILE *fp = fopen(filename,"w");
    fprintf(fp,"writing into file");
    fclose(fp);
}
}
Run Code Online (Sandbox Code Playgroud)

我的Python代码:

>>> import ctypes
>>> lib = ctypes.cdll.LoadLibrary('/in/vrtime/mahesh/blue/rnd/software/test/test.so')
>>> outfile = "myfirstfile.txt"
>>> lib.openfile(outfile)
File to open for writing = m
Run Code Online (Sandbox Code Playgroud)

我得到的文件名是m,这是char我文件的第一个字符.

如何将整个字符串传递给C端?

python ctypes python-c-api

4
推荐指数
1
解决办法
5309
查看次数