• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How Do I Import A Class That I Have Created Into MainActivity.java

ShatterStar

Newbie
Hi,

I am currently new to this and going through a tutorial. I have created a custom class in the app > src > main > java folder now when I try to Import this class the ndk doesn't pick it up and using the import statement "import myClass" doesn't work, what's going on? Have I created the java file in the correct directory? Do I need to add a reference or something? Please advise
 
What's your import statement in MainActivity.java?
Where is your class located? Is it in the same folder as MainActivity.java?
 
I'm new to this too. In Android Studio I right clicked on the directory with MainActivity in it and selected New Class and put the class I wanted to use there.

Then I just created an instance in the main activity using the "new" statement with my class creator. I did not use any "import" statements.

I have tried to attach a screenshot.
 
Yeah any Java IDE worth its salt (including Android Studio) will automatically write import statements as soon as you create a class of that type.
Can't remember the last time I actually manually wrote an import statement.
 
And now with the attachment
 

Attachments

  • Capture.JPG
    Capture.JPG
    176.1 KB · Views: 421
What's your import statement in MainActivity.java?
Where is your class located? Is it in the same folder as MainActivity.java?

I have tried "import myclass" and "import appNamespace.myclass" still no joy, and yes my class is located in the same directory as MainActivity.java
 
Hi,

I am currently new to this and going through a tutorial. I have created a custom class in the app > src > main > java folder now when I try to Import this class the ndk doesn't pick it up and using the import statement "import myClass" doesn't work, what's going on? Have I created the java file in the correct directory? Do I need to add a reference or something? Please advise

Upon further investigation I noticed that my new class was NOT in the same directory as ManActivity.java so I moved the files into the same directory and viola it worked, amateur mistake but I'm still learning, thanks for the help guys.
 
Back
Top Bottom