使用Android Studio将项目迁移到AndroidX(并手动修复了很多导入错误)后,我没有遇到编译错误,但是当应用启动时,我崩溃了:
Error inflating class android.support.design.widget.AppBarLayout。
布局文件中有问题的行是:
<android.support.design.widget.AppBarLayout
我的依赖项build.gradle是:
dependencies {
def lifecycle_version = '2.1.0-alpha02'
// used below--will be different for androidx (migrated 2019-02-04)
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha03'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'com.squareup.okio:okio:1.15.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.5'
implementation 'com.jakewharton.rxrelay2:rxrelay:2.1.0'
// Relay class
implementation 'com.jakewharton.rx2:replaying-share:2.1.0'
// ReplayingShare
implementation 'com.jakewharton.rxbinding2:rxbinding:2.2.0'
// RxBinding
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" // see def above
// includes ViewModel and LiveData …Run Code Online (Sandbox Code Playgroud) 为了获得Java新流的一些经验,我一直在开发一个处理扑克牌的框架.这是我的代码的第一个版本,用于创建Map包含手中每个套装的卡数(Suit是enum):
Map<Suit, Long> countBySuit = contents.stream() // contents is ArrayList<Card>
.collect( Collectors.groupingBy( Card::getSuit, Collectors.counting() ));
Run Code Online (Sandbox Code Playgroud)
这很好用,我很高兴.然后我重构,为"Suit Cards"和Jokers创建单独的Card子类.所以这个getSuit()方法从Card类转移到了它的子类SuitCard,因为Jokers没有套装.新代码:
Map<Suit, Long> countBySuit = contents.stream() // contents is ArrayList<Card>
.filter( card -> card instanceof SuitCard ) // reject Jokers
.collect( Collectors.groupingBy( SuitCard::getSuit, Collectors.counting() ) );
Run Code Online (Sandbox Code Playgroud)
请注意巧妙地插入过滤器以确保所考虑的卡实际上是西装卡而不是小丑.但它不起作用!显然,这collect条线并没有意识到它被传递的对象是保证是一个SuitCard.
在困惑了一段时间后,我绝望地尝试插入一个map函数调用,令人惊讶的是它有效!
Map<Suit, Long> countBySuit = contents.stream() // contents is ArrayList<Card>
.filter( card -> card instanceof SuitCard ) // reject …Run Code Online (Sandbox Code Playgroud) 在Android Studio中,以下代码将变量commandBytes着色以指示"隐式匿名类参数":
public boolean writeCommand( byte[] commandBytes ) {
if( writeCommandInProgress.compareAndSet( false, true ) ) {
writeSubscription = bleDevice
.establishConnection( asBleServiceRef, false )
.flatMap( rxBleConnection -> rxBleConnection.writeCharacteristic( asInputCharId, commandBytes) )
.subscribe(
characteristicValue -> {
writeCommandInProgress.set( false );
if( !Arrays.equals( characteristicValue, commandBytes ) )
Log.d( LOG_TAG, "Data read back from writeCommand() doesn't match input");
},
throwable -> Log.d( LOG_TAG, "Error in writeCommand: " + commandBytes.toString() + "; " + throwable.getMessage() )
);
return true;
} else return false;
} …Run Code Online (Sandbox Code Playgroud) 在RxJava中是否有类似于Subject适用于某个类的类Single?据推测,我会调用它onSuccess( item )或onError( Throwable )方法,输出将转发给SingleSubscriber.
我想我可以使用它Observable Subject并将其转换为a Single但看起来有点笨重.
目前使用RxJava 1但对RxJava 2的情况也很感兴趣.
我需要使用类似类的东西java.time.Duration来表示从微秒到秒的时间间隔。但是Android Studio不向我提供此选项。
我想我可以使用a float并将所有内容表示为秒,但这似乎不太直观和有意义。
这些时间间隔与任何现实世界的时间轴都不相关,它们只是时间间隔。
给定以下格式的日期/时间字符串:
2021-12-05 21:10:00 UTC,如何将其解析为 Java DateTime 对象?它似乎需要一个格式化字符串,例如uuuu-MM-dd HH:mm:ss,但是我该如何处理“UTC”以及如何确保 Java 对象指定 UTC?