小编Nee*_*ani的帖子

使用 kotlinx-coroutine-test 中的类时出错

好像kotlinx协同程序测试的依赖是不是为我工作,我可以像依赖的不是访问成员TestCoroutineDispatchersetMain()resetMain()等我下这个文档,但尽管添加gradle这个依赖无法访问的成员。我尝试重建项目并使缓存无效并重新启动,但似乎没有任何效果。我也尝试过,androidExtensions {experimental = true}但仍然没有运气。

构建.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.android.kotlincoroutines"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
androidExtensions {
    experimental = true
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1'


    implementation 'androidx.appcompat:appcompat:1.1.0-alpha02' …
Run Code Online (Sandbox Code Playgroud)

android kotlin kotlin-coroutines

12
推荐指数
2
解决办法
1933
查看次数

e:[kapt]发生异常:android.databinding.tool.util.LoggedErrorException:发现数据绑定错误

我启用了数据绑定,但是在执行代码时出现此错误。

错误

e:[kapt]发生异常:android.databinding.tool.util.LoggedErrorException:发现数据绑定错误。

我创建了一个片段类和该类的XML。我能够导入datbindingutil类。

我已经完成了重建/与gradle文件同步/使缓存无效并重新启动,没有任何效果。

XML文件

<layout>

<!--suppress AndroidUnknownAttribute -->
<data class=".databinding.ProfileFragmentBinding">

    <variable
        name="user"
        type="com.sample.sample.user.User" />

    <variable
        name="vm"
        type="com.sample.sample.user.UserViewModel" />

    <variable
        name="handler"
        type="com.sample.sample.user.profile.ProfileFragment" />
</data>


<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/profileIV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/medium"
        android:layout_marginTop="@dimen/medium"
        android:contentDescription="@null"
        android:src="@mipmap/ic_launcher_round"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:url="@{user.avatarUrl}" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="@+id/profileIV"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/profileIV">

        <TextView
            android:id="@+id/profileNameLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="@font/myriad_pro_semibold"
            android:text="@{user.name}"
            android:textColor="@color/black_transparent_de"
            android:textSize="@dimen/text_regular"
            tools:text="NAME" />

        <TextView
            android:id="@+id/badgeLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:fontFamily="@font/myriad_pro_semibold"
            android:text="@{user.badge}"
            android:textColor="@color/grey_000000"
            android:textSize="@dimen/text_regular"
            tools:text="Superman" />

        <TextView
            android:id="@+id/profile_Label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:fontFamily="@font/roboto_bold"
            android:text="@{user.badge}" …
Run Code Online (Sandbox Code Playgroud)

data-binding android viewmodel kotlin

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

在 Next.Js 中的 useEffect 中进行网络调用时出现 CORS 错误

getStaticProps正在对有效的 API进行网络调用superhero.com,但当我尝试在其中进行相同的操作时useEffect,会抛出 CORS 错误。

从源“http://localhost:3000”获取“https://superheroapi.com/api//1”的访问已被 CORS 策略阻止:不存在“Access-Control-Allow-Origin”标头所请求的资源。如果不透明响应满足您的需求,请将请求模式设置为“no-cors”以在禁用 CORS 的情况下获取资源。

我尝试过使用fetchaxios进行网络调用,但遇到了相同的错误。问题或限制是否出在 Next.js 上?

编辑:尝试使用JSON 占位符API useEffect,它正在工作。

cors reactjs next.js

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

babel-node不被识别为内部或外部命令,可操作程序或批处理文件

当我尝试通过babel命令运行JS文件时,它显示:

"babel-node不被识别为内部或外部命令,可操作程序或批处理文件".

1.js用这个书面创建了文件"console.log("hello world")"; 并尝试使用babel-node命令运行,但它显示上述错误.

babel ecmascript-6

9
推荐指数
7
解决办法
9684
查看次数

无法从配置的远程连接到存储库.你想要检查.git配置

我尝试在Android Studio中将我的存储库共享给Github并收到以下消息:

"无法从配置的远程连接到存储库.您可能需要检查.git配置"

如果我忽略并共享,Github会创建一个空的存储库,不会上传git文件.我重新安装了GitHub并在Android Studio中创建了一个指向git.exe的链接,并在Github上删除了同名的存储库.但同样的消息再次出现.那么,如何在GitHub上创建存储库并推送文件?任何帮助将非常感激.

android github

8
推荐指数
2
解决办法
7636
查看次数

组件在 history.push() 之后没有被渲染

单击按钮时,我通过执行更改了 URL history.push()

import createHistory from 'history/createBrowserHistory'  
const history = createHistory()  
.  
. some code  
.  
history.push(`/share/${objectId}`)
Run Code Online (Sandbox Code Playgroud)

并希望该RouteURL 中提到的组件能够呈现,但这并没有发生。但是,刷新该组件时会按预期呈现。但是我不明白为什么它不会在 URL 更改时立即呈现。我试过将组件包装在withRouter.

import React, {Component} from 'react'  
import {BrowserRouter, Router, Route, Switch, withRouter} from 'react-router-dom'  
import createHistory from 'history/createBrowserHistory'  

import Home from './pages/home'  
import ViewFile from './pages/view-file'  

const history = createHistory()

class App extends Component {
    constructor(props) {
      super(props)
    }

      render() {
      return (
          <BrowserRouter>
              <Switch>
                  <Route exact path={'/'} component={Home}/>
                  <Route path={'/share/:id'} component={withRouter(ViewFile)}/>
              </Switch>
          </BrowserRouter>
      )
  } …
Run Code Online (Sandbox Code Playgroud)

browser-history history.js reactjs react-router

8
推荐指数
3
解决办法
2万
查看次数

Firebase存储getDownloadUrl()方法无法解析

要将图像上传到Firebase存储,我将附加addOnSuccessListenerStorageReference的实例上.虽然重写onSuccess方法我正在调用getDownloadUrl()实例,taskSnapshot但它给了我一个错误说

无法解析方法getDownloadUrl()

我在2个月前创建的这个应用程序,此应用程序运行良好,getDownloadUrl()工作正常.另外,在taskSnapshot我按Ctrl +空格的情况下,在建议中我找不到getDownloadUrl()方法.为什么会这样?

代码onActivityResult():

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == RC_SIGN_IN) {
        if (resultCode == RESULT_OK) {
            Toast.makeText(this, "Signed in!!!1", Toast.LENGTH_SHORT).show();
        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(this, "Failed to sign in", Toast.LENGTH_SHORT).show();
            finish();
        }
    }
    else if(requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK){
        Uri …
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-storage

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

我如何在 Flutter 中使用其他组件的页面中实现选项卡控制器?

我想在我的 Flutter 应用程序中的其他组件的页面中添加一个选项卡控制器。我怎样才能做到这一点?当我添加 TabBar 时它没问题但是当我添加 TabBarView 时它不起作用。我附上了页面的截图。我想做这个。我怎么能在颤振应用程序中做到这一点。?

class Details extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
  body: new Center(
    child: new Column(
      children: <Widget>[
        new DropdownButton<String>(
          items: <String>['USD', 'EUR', 'LTC'].map((String value) {
            return new DropdownMenuItem<String>(
              value: value,
              child: new Text(value),
            );
          }).toList(),
          onChanged: (_) {},
          value: 'USD',
        ),
        new Text(
            '\$6,146.76',
          style: new TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 40.0,
            color: Theme.of(context).accentColor,
          ),
        ),
        new Text('Last Updated at'),
        new DefaultTabController(
            length: 2,
            child: new Container(
              child: new Column( …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-layout

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

除非“--module”标志为“amd”或“system”,否则无法使用选项“outFile”编译模块

我写一个import语句import { PI } from './math/circle'app.ts文件,并具有恒定export const PI = 3.14circle.ts文件,但在做运行程序tsc app.ts --outFile app.js一直显示此错误。

错误 TS6131:除非“--module”标志为“amd”或“system”,否则无法使用选项“outFile”编译模块。1 导出常量 PI = 3.14

但是根据我正确导入的文档。我还尝试将“module”:“commonjs”更改为“module”:“amd”/“system”,然后重新加载VSCode窗口,但没有成功。我哪里错了?

配置文件

{
  "compilerOptions": {    
    "target": "es5",                         
    "module": "amd",                    
    "strict": true,                          
    "noImplicitAny": true,                
    "strictNullChecks": true,              
    "strictPropertyInitialization": false
  },
  "exclude": [
    "node_modules"
  ]
}
Run Code Online (Sandbox Code Playgroud)

PS:打字稿版本 3.5.3

typescript

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

RTL 中的 waitForElementToBeRemoved 错误超时

我有一个使用Formik制作的基本登录表单,只是尝试编写 RTL 和 jest 代码来填写详细信息、提交表单并导航到主页。因此,写了以下内容:

 it('Fill the form and login', async () => {
    render(<Login />)

    await userEvent.type(screen.getByTestId('emailInput'), 'neeraj@gmail.com')
    await userEvent.type(screen.getByTestId('passwordInput'), 'neeraj')
    await userEvent.click(screen.getByTestId('submitBtn'))

    expect(window.location.pathname).toBe('/')
  })
Run Code Online (Sandbox Code Playgroud)

上面的测试已经通过,但出现了经典的行为错误。

When testing, code that causes React state updates should be wrapped into act(...):
    
    act(() => {
      /* fire events that update state */
    });
    /* assert on the output */
Run Code Online (Sandbox Code Playgroud)

因此,参考此博客文章并按照建议使用waitForElementToBeRemoved函数,但现在测试因超时错误而失败。

使用 waitForElementToBeRemoved 更新测试用例

When testing, code that causes React state updates should …
Run Code Online (Sandbox Code Playgroud)

reactjs react-testing-library

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