supportFragmentManager.commit in kotlin is not working - java

Can anyone help me with this please? Inside my fragment supportFragmentManager.commit{} is not working. Android Studio is not recognizing this I don't know what to do. I am working in kotlin project

That commit {} method (with the transaction in a lambda) is an extension function provided by the Fragment KTX library. If you haven't already, you need to add this dependency in build.gradle:
dependencies {
implementation "androidx.fragment:fragment-ktx:1.2.5"
}
and then Android Studio should automatically offer to fix the commit call by importing it. If it doesn't (it can be awkward sometimes), add this to your imports:
import androidx.fragment.app.commit
and maybe these too, I don't know if they'll be necessary
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
you might need to remove some other matching imports so you're just using the androidx versions

Related

Does not exist import android.support.v4.util.ArrayMap;; (What is the easy way to migrate) Does the migration is necessary for any android project

After migrating to android x via android studio getting annotation issues (What is the easy way to migrate) Does the migration is necessary for any android project?
How can I easily migrate the app in android studio.
error: package android.support.annotation does not exist
import android.support.v4.util.ArrayMap;
See the class mappings:
android.support.annotation should rather be: androidx.annotation.
And you probably still have (the wrong one) support libraries referenced; eg:
implementation "com.android.support:support-v4:28.0.0"
Should rather be:
// https://mvnrepository.com/artifact/androidx.legacy/legacy-support-v4/1.0.0
implementation "androidx.legacy:legacy-support-v4:1.0.0"
The same goes for the annotations:
https://mvnrepository.com/artifact/androidx.annotation/annotation/1.1.0
implementation "androidx.annotation:annotation:1.1.0"
all of the references need to be updated.

Android Studio not excluding a transitive dependency and complains about class conflict

Hi I'm working on an Android app and I need to use a library called Semantics3. The issue I'm having is that the Semantics3 library depends on a few different libraries one of which is org.json but Android Studio automatically includes its own unique version of org.json which causes various issues. I've tried a few things to work around this and I'll describe them below.
First, I just imported the Semantics3 library. All the code compiles but when code from the library runs to make a service call the app crashes. This is due to a "NoSuchMethod" error because Semantics3 makes use of a constructor from a class in org.json which the AS version doesn't include.
To get around this I made my own jar file of the Semantics3 code and add in the dependencies it needs on my own in Gradle. The app still crashes, though not because it can't find the constructor. In this case the error is due to an exception from org.json, specifically "org.json.JSONException: Value com.android.okhttp.internal.huc.HttpURLConnectionImpl of type java.lang.String cannot be converted to JSONObject". I couldn't figure out why this error was popping up so I decided to try out the Semantics3 library outside of Android and just made a simple Maven project. In the Maven project I can make service calls just fine with no issue, but if I add the jar file and dependencies on my own, I get the same error as in AS.
So I figure there's something missing in the source code on Github that I used to make the jar or something but that's beyond me to figure out, so I'm back at trying to just import the library. My final and current attempt involves trying to explicitly import the version of org.json that Semantics3 needs along with the Semantics3 library in Gradle. But when I bring in the Sematnics3 library I try to exclude the transitive dependency Semantics3 introduces to org.json. I've included the Gradle file for this attempt below.
// https://mvnrepository.com/artifact/com.semantics3/Sem3Java
implementation('com.semantics3:Sem3Java:1.2.4'){
exclude group:'org.json:json'
}
implementation 'org.json:json'
constraints {
implementation(group: 'org.json', name: 'json', version: '20190722') {
because 'Semantics3 requires version 20190722 of org.json, not the default AS version'
}
}
The issue is when I try to run the code with the above setup in Gradle I get an error saying there are duplicate class definitions contained in the Semantics3 library and org.json library. And yes there are certainly conflicts but I thought the exclude bit to the Semantics3 implementation would be enough to prevent that from happening. Did I make a mistake somewhere or am I misunderstanding or misusing the exclude? If it makes a difference it appears the Semantics3 library does hardcode the org.json library into its Jar file. I appreciate any help with this. Thank you.

ActivityMainBinding class does not recognize my package

I am trying to make a project using MVVM.
I've enabled dataBinding by modifying the gradle file.
dataBinding{
enabled = true
}
but after I build my project it doesn't recognize on of my packages.
I tried clean and restart android studio but it does not fix.
If you are trying to import a whole package you should use.
com.example.yourpackage.*
In this case the compiler can understand what you are doing.
If you have created Your viewModel Check the Following.
Have you mentioned Variable in your layout.
Check if you have missed typed any while binding.
clean and Rebuild Project
Goto Gradle->->app->other->dataBindingGenBaseClassesDebug and run it.
This worked for my project.
try this -
import com.example.mvvmLogin.ViewModel.LoginViewModel;`
and at the declaration -
protected LoginViewModel mViewMOdel;
do the same for other activities in the packages
if you are using
import com.example.mvvmLogin.ViewModel.*;
declaration is done by
protected LoginViewModel mViewMOdel;
using protected ViewModel.LoginViewModel mViewMOdel; is not correct

Android Facebook sdk Session.OpenRequest(myFragment) is undefined?

For some reason I cannot see the line of code:
session = new Session.OpenRequest(this).setCallBack(statusCallBack)
It gives me an error that Session.OpenRequest(myFragment) is undefined. Does anyone know why this is and how I can fix it?
Found out what i was doing wrong. It has to be a fragment from the support library. I was extending the regular fragment class.
Apparently, Session.OpenRequest(Fragment fragment) constructor should work. Assuming that you have added Facebook SDK properly in your project, organize the imports in your class to import the Session.OpenRequest class. This constructor seems to be invisible for your code.
If you are using Eclipse IDE organize imports by pressing Ctrl+Shift+O.

NoClassDefFoundError Android with ActionBarActivity

I currently have an ActionBarActivity which always returns a NoClassDefFoundError. I've read that it might be a problem with the ADT but I cannot be sure, hence my question. I've imported the ActionBar sample from the Android samples under
android-sdk\samples\android-14\ActionBarCompat
I've labelled the ActionBarCompat project as a library under Project -> Properties but I'm still getting the error.
To reiterator:
public class SearchActivity extends ActionBarActivity { // Doesn't work, yields exception
public class SearchActivity extends Activity { // Works perfectly
Has anyone else experienced a similar error and perhaps found a solution?
Thanks in advance.
http://developer.android.com/tools/support-library/setup.html
The "Adding libraries with resources" section may help
since this is not in the most common v4 support library
include only android-support-v4.jar is not enough
Ended up using ActionBarSherlock instead and added a project reference under Project Properties as well as in the Build Path. Seems to have fixed all errors relating to my question.
Just this morning, Google released Android 4.3. They also updated its support library that allows ActionBar to be implemented on lower versions. Just have to extend ActionBarActivity. See guidelines here and tutorial here.
I've got the same problem. I solved it getting the android-support-v7-appcompat.jar library.
See here http://developer.android.com/tools/support-library/setup.html#using-apis how to install it.
I recommend focus on "Adding libraries without resources" instead "Adding libraries with resources" for the sake of simplicity.
When you do it, don't forget to import the this library into your Activity Java source. You can do it declaring import android.support.v7.app.ActionBarActivity;
I solved this problem like so, when you add the library make sure it does not have the android-support-v4 along with it (in libs folder of the library un-check android dependencies and android-support-v4), that's in the case where your project already have the android-support-v4, that's why you can't find class ActionBarActivity
This Link
may help you.
This library is located in the /extras/android/support/v7/appcompat/ directory.
Include in eclipse and add as library. This will solve your problem.

Categories

Resources