I'm facing problems after upgrading the latest poi 5.2.2.
Now my project is using the springboot default logback to print the logs.
but after upgrading the poi
implementation "org.apache.poi:poi:5.2.2"
it must let me implement the log4j implementation. so I added
implementation 'org.apache.logging.log4j:log4j-core:2.17.2'
then this works in my local environment.
However got below errors in docker environment
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath.
Either remove Logback or the competing implementation (class org.apache.logging.slf4j.Log4jLoggerFactory
loaded from file:/opt//BOOT-INF/lib/log4j-slf4j-impl-2.17.2.jar). If you are using WebLogic you will need to add 'org.slf4j' to
prefer-application-packages in WEB-INF/weblogic.xml: org.apache.logging.slf4j.Log4jLoggerFactory
at org.springframework.util.Assert.instanceCheckFailed(Assert.java:702)
at org.springframework.util.Assert.isInstanceOf(Assert.java:621)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.get
below is my build.gradle file
configurations.all {
exclude group: 'org.hibernate', module: 'hibernate-entitymanager'
exclude group: 'org.apache.tomcat', module: 'tomcat-jdbc'
exclude group: 'log4j'
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' }
implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.springframework:spring-context-support"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
implementation "org.springframework.boot:spring-boot-starter-data-mongodb"
implementation "org.springframework.boot:spring-boot-starter-freemarker"
implementation "org.springframework.boot:spring-boot-starter-mail"
implementation "org.springframework.boot:spring-boot-starter-security"
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "org.springframework.boot:spring-boot-starter-validation"
implementation "org.springframework.security:spring-security-oauth2-client"
implementation "org.springframework.security:spring-security-oauth2-jose"
implementation "org.springframework.security:spring-security-oauth2-resource-server"
implementation "ch.qos.logback:logback-classic:1.2.11"
implementation 'org.apache.logging.log4j:log4j-core:2.17.2'
btw, basing POI official introduction, it also supports other logging framework, so I also tried this jar
https://logging.apache.org/log4j/log4j-2.2/log4j-to-slf4j/index.html
but I still get error like below
Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j
at org.apache.logging.slf4j.Log4jLoggerFactory.validateContext(Log4jLoggerFactory.java:60)
at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:44)
at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:33)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:53)
at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:33)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:363)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:655)
at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:174)
... 1 more
this really drives me crazy, could you help me on this?
I have written some code that manipulates MotionEvent instances, and want to write a unit test for it.
The unit test needs to validate my manipulations only; it does not need to simulate any user actions.
I understand it needs to be an instrumented test to be able to use the methods of MotionEvent; I need the actual methods, not any mocking.
I have defined an instrumented test in the directory src/androidTest/...; however, it still throws the exception
java.lang.RuntimeException: Method obtain in android.view.MotionEvent not mocked.
My build.gradle file for the module has the following entries:
defaultConfig {
...
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
...
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
The imports in my test class are as follows:
import android.view.MotionEvent;
import org.junit.Test;
import static org.junit.Assert.*;
How can I run this test?
My mistake was as follows.
I initially thought that a local unit test would suffice, since no user action was involved.
It turned out to be wrong: the local unit tests do not get access to the Android methods.
I moved my file containing the test, to the place prescribed for the instrumented tests, /src/androidTest/java/, but did not change the file; this can be seen in my imports.
For this reason it still ran as a local non-instrumented test.
After I realized it, I changed the file to mimic the ExampleInstrumentedTest created by Android studio together with my project. I also deleted the run configuration which was still a local test.
After that Android studio prompted me to create a new run configuration, and the test ran successfully.
I want to use RoundedDrawable widget, but it is not visible. This is my gradle dependency :
implementation 'androidx.wear:wear:1.2.0-alpha09'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'com.google.android.gms:play-services-wearable:17.1.0'
implementation 'androidx.percentlayout:percentlayout:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.0'
implementation 'com.google.android.support:wearable:2.8.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
compileOnly 'com.google.android.wearable:wearable:2.8.1'
implementation "androidx.wear:wear-input:1.1.0-alpha02"
I have a Groovy project built using Gradle. The issue happens when I build a jar that has all the dependencies (fatJar), so I'm forced to do everyting in the Java way and get none of the Groovy enhancements
When I try to use any of the Groovy enhancements, I get MissingMethodException, this happens on: (just to give some examples)
new Date().format("yyyyMMddhhmmss")
[1,2,3].average()
Dependencies are:
dependencies {
// Use the latest Groovy version for building this library
implementation 'org.codehaus.groovy:groovy-all:2.5.13'
implementation 'org.codehaus.groovy:groovy-dateutil:2.5.13'
//implementation 'org.codehaus.groovy:groovy-datetime:2.5.13'
// Use the awesome Spock testing and specification framework
testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
compile 'log4j:log4j:1.2.17'
// TODO
//implementation 'com.github.ppazos:openEHR-OPT:Tag'
compile fileTree(dir: 'lib', include: '*.jar')
}
This is the project https://github.com/ppazos/testehr
Not really sure what is going on.
Currently started to learn MVVM Kotlin. This youtube tutorial is pretty confusing but direct to the point.
https://www.youtube.com/watch?v=0LaUXQcGuT0&t=254s
I have this error in my title.
this code triggers the error in my MainActivity
So here's my Module:app (build.gradle)
Dependencies
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//Config data binding compiler with Kotlin
kapt 'com.android.databinding:compiler:3.1.1'
//LifeCycle Extensions
implementation 'android.arch.lifecycle:extensions:1.1.1'
//Toasty to show Toast
implementation 'com.github.GrenderG:Toasty:1.2.8'
}
DataBinding
dataBinding{
enabled=true
}
applied plugin
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "org.jetbrains.kotlin.kapt"
apply plugin: 'kotlin-kapt'
My activity_main.xml
<data>
<variable
name="viewModel"
type="com.example.rnd.kotlinmvvmlogin.ViewModel.LoginViewModel"/>
</data>
and Here's my File Structure of MVVM
MainActivity.kt
package com.example.rnd.kotlinmvvmlogin.View
import android.arch.lifecycle.ViewModelProviders
import android.databinding.DataBindingUtil
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import com.example.rnd.kotlinmvvmlogin.Interface.LoginResultCallbacks
import com.example.rnd.kotlinmvvmlogin.R
import com.example.rnd.kotlinmvvmlogin.ViewModel.LoginViewModel
import com.example.rnd.kotlinmvvmlogin.ViewModel.LoginViewModelFactory
import com.example.rnd.kotlinmvvmlogin.databinding.ActivityMainBinding
import es.dmoral.toasty.Toasty
class MainActivity : AppCompatActivity(), LoginResultCallbacks {
override fun onSuccess(message: String) {
Toasty.success(this, message, Toast.LENGTH_SHORT)
.show()
}
override fun onError(message: String) {
Toasty.error(this, message, Toast.LENGTH_SHORT)
.show()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val activityMainBinding = DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main)
activityMainBinding.viewModel = ViewModelProviders.of(this, LoginViewModelFactory(this))
.get(LoginViewModel::class.java)
}
}
I understand the process of MVVM but I don't know what is reason why this error keeps occuring. The tutorial of this MVVM is really helpful for understanding the mvvm kotlin that's why I'm pursuing to continue this app to make it work.
I had same issue. Problem is in your type type="com.example.rnd.kotlinmvvmlogin.ViewModel.LoginViewModel"
Remember in databinding only Viewmodel class name should start with Capital letter and other parent folder of a class should start with lower case. Just rename ViewModelwith viewModel. Clear and Rebuild the project.
Many people experience this because they have their packages named starting with a capital letter. Rename your package names to start with a small case letters such that in your path of reference to view Model class its only the view Model class that starts with a capital letter
i.e type="com.example.rnd.kotlinmvvmlogin.viewModel.LoginViewModel"
solves your problem
Simply rename the package from ViewModel to viewModel. The first character just has to be lowercase and it'll work.
UPDATE
hey, i see you did not include this library
implementation 'androidx.core:core-ktx:1.0.2'
my dependencies
Have you try write code like below
activityMainBinding?.viewModel = ViewModelProviders.of(this,LoginViewFactory(this)).get(LoginViewModel::class.java)
Because it needs nullable variable, but you assigned non-nulable variable
The problem is the package name that you're using for your view model classes
Although google call this structural design pattern "MVVM" and everybody want to make "Model", "ViewModel" and "View" packages in their project, but when data-binding library wants to generate the files for you will confront problem with package names.
So you just need to change the destination name of :
import com.example.rnd.kotlinmvvmlogin.ViewModel.LoginViewModel
to :
import com.example.rnd.kotlinmvvmlogin.data.LoginViewModel
or anything else.
Also you may want to change "View" to "ui" so it don't cause problem for later.
Yes it's quite unfortunate, even though it is referred to as a MVVM architecture, you can't have a package named "ViewModel", "ViewModels", "viewModels", or in any case similar to the sort, or else it just won't build, and it gives you a completely misleading error.