Home>

I am making an application with android studio, but I am writing code referring to various sites to send an email directly to my G-Mail from within the application, but an error occurs in some code parts It has come out and I investigated various things, but I am struggling because I can not understand the cause.
[Cannot resolve method'getInstance' in'Session' is displayed. ]
I wondered if I hadn't imported the library and tried importing various things, but I couldn't solve it. .. ..
Is this getInstance () itself no longer available?
I'm wondering if I'm overlooking something basic or if there are other deep causes.
I'm sorry, but I would appreciate it if you could give me some advice. .. ..
Thank you.] (Bf53bc09d705719bb2215ac076b1188e.png)

  • Answer # 1

    https://nosix.hatenablog.com/entry/2018/11/12/153359

    While looking at the above site, I converted it to java and checked it
    Sessionimport javax.mail.Session;Are you using Session?

    First, add a dependency on JavaMail for Android to the app module build.gradle.
    As you can see, you have to add the following to the dependencies of the app's build.gradle.

      implementation'com.sun.mail:android-mail: 1.5.5'
        implementation'com.sun.mail:android-activation: 1.5.5'

    === Addendum
    Is there anything that is xxx.Session in the part where imports are lined up at the top?
    The one that was automatically imported when I first typed Session remains, so if I write it later, it will be like that.

    So if there is a class with the same name in the imported class, it will be javax.mail.Session etc. to determine which class it is.
    (The one imported first will be given priority)

    Or just type Session and Ctrl click to see what file Session is currently used as Session.
    (If you delete the import used earlier as Session, javax.mail.Session can be used as Session)

    So the usage hasn't changed.
    If you have the same name, you need to choose what to use.