AndroidStudio not recognizing .java file - android

For some unknown reason, android studio decided not to recognize the .java file. Any idea how to resolve this?
I've tried deleting the file and recreating it, but it still results in the same issue. When recreating the file, some error came up and the file is automatically recreated
public class SubmitDealAsyncTask extends AsyncTask<Void, Void, String> {
...
}

It turns out that there's a wrong file association entry which associate that particular filename as a JavaFX file.
Look in the Preferences > Editor > File Types under Java files, the name of SubmitDealAsyncTask.java file is there and all I needed to do is to remove it.

Check your java file name and Class name.
class SubmitAsyncTask {}
should be saved in "SubmitAsyncTask.java"

Go to Preferences > Editor > File Types > Java, and then under each of the listed file types (Yes, unfortunately you have to look through all of them), and scroll down at the bottom of the to see if there is an entry for you file, and then click on it and the click the - sign.

How did you include this file? I had problems just copying java classes in Android Studio, so maybe you might want to create a new java class and copy the content of the desired file into it. Then there should be no problem.

Try to copy all the code from this file and paste it inside your package(where you paint over you name with blue lines).
Android Studio will create new .java file for you there.

#root I created the class by right clicking on the package folder(com.example.tttt) in the project view and then new java class and naming it SubmitAsyncTask and then using the prototype you provided to create a dummy class and it worked for me as you can see below so if this doesn't solve it then you are missing something in the code its no longer an IDE problem :

Related

Android Studio Activity Java File does not recognize XML

I have a big problem. Last I copied a CardView with RecyclerView from a video. After that I created a new empty activity, but the Javafile didn't want to accept the corresponding XML file. And if I go with ALT + ENTER he suggests to me to create your xml file, but afterwards he tells me it already exists. So I can open the XML file, the program recognizes it but it is not recognized in the Java data and I cannot select it there either. There a screen shot, There a picture from solution research, And There a photo of the xml File.
Can someone help me there? Thank you in advance!
I was facing the same problem but you just need to close your project and open it again, the error related to activity file will bee removed!!Just try it.....
maybe you need to rebuild your app
1- Build > clean project
2 - Build > Rebuild project
I hope it will work with you .
Delete those two files. Copy the code first.
Go to File ->new activity then create that activity and paste the code there, besides those lines.

Where do I put haarcascade_frontalface_alt.xml in the Android sample of JavaCV's FacePreview class?

There's a snippet of code in the Android sample's FacePreview class that boggles me:
File classifierFile = Loader.extractResource(getClass(),
"/org/bytedeco/javacv/facepreview/haarcascade_frontalface_alt.xml",
context.getCacheDir(), "classifier", ".xml");
I know I should change the names before haarcascade_frontalface_alt.xml to match my project name, but I can't figure out where to actually put the XML file in my project structure.
I did read somewhere that I have to put the xml file in the same folder as the FacePreview class... so does that mean I have to put it in src/main/java/<package_name>?
Edit: That doesn't work either. Do I have to download and cache it in the Activity?
it goes in src/main/resources/org/bytedeco/javacv/facepreview/haarcascade_frontalface_alt.xml
assuming gradle does the right thing

Search for the references to a layout xml file in android code using eclipse IDE for android

I am using eclipse IDE. If I have a variable or an instance of a class. If I select it and do Ctrl+Shift+G, I can get all the references to that variable or the class instance in that workspace. Similarly, can I get references to an xml file in the android code using any short cut?
Lets say, I have layout xml file app_view.xml. I need to search the android code where this xml is being referenced.
I don't know of any shortcut, but you could just use the search menu to search in your project for occurrences of
R.layout.your_layout_name
If you copy (ctrl + c) in a java file the text R.layout.your_layout_name, you can directly use Search => Text => Project.
Or a less 'elegant' solution, temporary remove the xml from the project, so that you can look for compile errors in your java sources.

Why is eclipse not adding my strings to the resource file?

Ok so I am working on an Android OS and I have followed the instructions and pulled down the source, plus setup eclipse properly. I have made a change in my strings.xml file in one of the framework projects. However, after I perform a make on the project that string does not get added to the appropriate resource file in out/target/common/. Hence my Eclipse is not picking up any new resource.
I have performed the following.
1.) A clean on the project.
2.) Completely delete the out so that everything would be rebuilt.
3.) Tested to make sure the build was actually pulling changes from that same project. Basically I added my string directly to the project instead of using a resource.
Try out following points they may work...
Check all activities if import android.R;is imported in any java file remove that import statement.
Then delete R.java file.
It may works, just check
Ok so I figured out the problem. If you are working on the OS source and you want to add a string to the string.xml file you MUST also add the following line of code to your public.xml file that exists inside your values folder.
<java-symbol type="string" name="my_string_resource_name" /> <!--In public.xml-->

How to add menu in Android without getting "R" error

I am writing a simple application to get familiar with android programming. Today I want to play with menus. I follow this page!. I first create "menu" folder under "res" and then add "game_menu.xml" in it. However this "R" thing can't get that folder. I tried some refresh to get it 'auto-generated' but it didn't work. I clean for a rebuild, but this time R.java completely dissappeared. How can I make eclipse to recreate R or what is the problem?
Are you sure the R is not creating the appropriate link for the menu?
To find your xml menu, you must type: "R.menu." & hit ctrl+space and all your menu's will pop up.
Try this way.
And if you want to check your R file, if its creating the menu link, search for:
"public static final class menu" in R file
In that class you will find your xml menu's..
are you able to compile ? Check which R you have imported in your code. It should not be the android.R but the one from your project
You have most likely misspelled something in your xml file, or have some other error. If the xml files are not entirely correct (or other resource files), the R. file cannot be built. Go through the file and make sure that everything is error free.
A common mistake is to name the resources with capitals, although the names can only contain small letters.
another common mistake is to use unsupported folder names.

Categories

Resources