Why IDEA shows java files as invalid in my Android project? - java

I am trying to build apk from this repository.
I have problem: idea show .java files as invalid, you can see it on this pic:
What am I doing?
I download mentioned (git) sources and copy sources to some directory
I open this directory from IDEA as directory
In project settings I am setting Project SDK as Android 22 and create Android module in Modules section
Downloaded sources require android-support-v7-appcompat lib, so I am getting many errors, like IDEA can't find theme in xml
To remove this error, I had added library android-support-v7 in project settings, added module \android-sdk\extras\android\support\v7\appcompat\ to modules and set android-support-v7 module as dependency for my main android module
I invalidate cache and restart IDEA
After this steps I got xml's without errors about theme (because appcompat library was added), but java files are not looking valid, as I showed on picture above.
Also, I got red Main activity in AndroidManifest.xml file and I can't go to the declaration of the activity by clicking ctrl + LMB on it.

You need to specify the source dir.
Right click on com's parent folder, then Mark directory as and sources root.

Right click on java folder ->mark directory as -> sources root
https://www.jetbrains.com/idea/help/configuring-content-roots.html

Try to check you package...com.yourproject in the imports, try to import the R packge and the rest of your packge like class and other things like import com.yourproject.R.... In the Android Studio rigth click, F4 you also can ser the project proprieties....all i see is that post a awser and let me help you witj this

Related

package com.codename1.charts does not exist

I want to test the GeoVizDemo [https://codenameone.googlecode.com/svn/trunk/Demos/GeoVizDemo] app in this blog post https://www.codenameone.com/blog/geo-visualization-library.html but when I have opened up the project in Netbeans the files in /src DensityChart.java, GeoVizDemo.java and PopulationData.java all have errors such as
package com.codename1.io does not exist or
package com.codename1.charts does not exist
How do I fix this?
Your app is missing some jar files. To fix this, follow these steps:
Create a new CN1 Project. Set your package name to com.codename1.demos.geoviz and Main Class to GeoVizDemo. Choose Flat Blue theme and Hello world(visual) template.
Download CN1GeoViz.cn1lib and copy it to your lib folder.
Download DensityChart.java, GeoVizDemo.java and PopulationData.java, copy them to src/com/codename1/demos/geoviz folder (Replace any file in there).
Download pop_density.csv and us-states.json, copy them to the project main folder.
Open your project properties in Netbeans or Eclipse and Update project Library.
Right click on your project and Choose Codenameone -> Refresh Libs.
Do a clean build and fix any error showing and that's it.

Importing google-play-service library, appear "No projects are found to import"

I tried importing google-play-service library, but it shows me the message below.
It's the Path:
IT's the message:
What did I do wrong?!?
Hey,Try this way,hope this will help you to solve your problem
Copy your google play service from eclipse and paste in same derive of your system where you create project, then check.
if it not work then create new workspace and check. sometime it make app by default and said there is no project.
Checkout and tell me if it work or not
You just Import the project Sdk/extras/google/google_play_sevices/libproject/google_play_services_ib/
dont go beyond this path, just imort this whle projest.
Note: While importing or attaching lib project with your project then take care of one thing:
If path appear on import starts with a drive letter(C:, D: etc) then ,it means import not successful, it should be start with dot (...)
The library project should be on same location where your project is (for successfull import.) while it is in workspace on at any other location.
try to paste it in directly in your workspace and if you simply wants to add jar files then use buildpath option for particuler project.

Trying to use "android-holo-colors.com" and "AppCompat"

I'm develiping an Android application in Eclipse, with minSdkVersion="8"
I want to use the theme generated by "android-holo-colors.com" but the file values/themes_apptheme.xml throws an error in this line:
<style name="_AppTheme" parent="Theme.AppCompat.Light">
error: Error retrieving parent for item: No resource found that
matches the given name 'Theme.AppCompat.Light'.
This is what I've done so far:
With Android SDK Manager I downloaded Extras > Android Support Library
I copied the file android-support-v7-appcompat.jar from here: C:\Users\Administrator\android-sdks\extras\android\support\v7\appcompat\libs to my project's library lib
I right clicked the jar in Eclipse, and then Build Path > Add to build path
(These 3 steps are also in Android's documentation)
I downloaded the generated .zip from android-holo-colors.com and put all the files in their corresponding folders. Eg: I took all the xml's from the zip's drawable folder and place them in my project's drawable folder. Etc.
After doing all the above:
I'm getting the error stated at the beginning of my question.
So, the question is how do I solve this? (but previous questions can be: "am I including correctly the appcompat library?", "am I including correctly all the holo files?")
Some additional information that could be important:
My lib folder in the project also has android-support-v4.jar (if I right click on it, the possibility to add to build path is there, so I guess it is not in the build path)
I tried to use GridLayout the same way (steps 1-3) but I had a similar problem: the class GridLayout wasn't recognized/found
Well, solved...
Apparently just putting the .jar in my project and in its buildpath wasn't enough*.
After step 3 in my question, I would add:
In the same eclipse workspace, "import project from existing source" and select C:\Users\Administrator\android-sdks\extras\android\support\v7\appcompat
Right click in it, Properties > Android > "Is Library" must be checked (it already was after the previous step)
In my project, which is living in the same workspace, right click, Properties > Android > Under the "Library" section, click on "Add.." and add the android-support-v7-appcompat project
(*) Although now is working, I'm not really sure if the step 2 and 3 in my question are necessary, because the project already "uses" the other project, which should create the same jar. If someone can clarify this last paragraph, would be great.

Android Using Jar Files

So I'm trying to use the jReddit wrapper class because I am developing a reddit app on the android. Here is what I did:
I first went to jreddit and downloaded as a zip
Then I went to eclipse, made a project and copied the files from the extracted folder into the new project. Here's a picture of what it looks like:
Then I used the build.xml from here and "Ran as Ant" to create a jar file in the dist folder as you can see above
I made my android project and copied the jar file into the lib folder and built the path. The project looks like this:
Finally, here is my MainActivity.java. Sorry, I couldn't format the code properly on here
There are no errors, so I can run it on the android. However, when I click the login button to activate the function call onClickBtn, before it can even get into the function it throws an error saying: Could not find class 'im.goel.jreddit.user.User', referenced from method com.example.reddit.MainActivity.onClickBtn
Did I not import this jar in correctly or am i just not using it properly? Why is it compiling fine like it can see the user class but when run on the android it doesn't know what it is?
Extract the contents to the same folder as your other classes. Usually src.
Or
Go to project properties (Alt + Enter) and select Java Build Path (Left panel). Then select Libraries (Top middle). Click the Add External JARs button and select your jar.

Error in xml layout:The following classes could not be found: - android.support.v4.view.Viewpager

My android.support.v4.jar is in my libs folder and in my android private libraries also.
But I got a problem appearing over top of my my xml layout saying- "The following classes could not be found: - android.support.v4.view.Viewpager."
I'm not sure whats wrong please help! I've searched around many forums and nothing seems to be working. The same problem occured when I tried integrating admod into my application it said, on the xml layout, The following classes could not be found: - android.support.v4.ads.AdRequest. I have a hunch it has to do with my jar being in the wrong spot..
hey i've fixed this by converting the ViewPager
from "android.support.v4.view.Viewpager" to "androidx.viewpager.widget.ViewPager".
to do that you just have to open up the .xml file > design and then right click on that ViewPager > Convert view as shown the next picture
then you just type viewPager and the search bar will auto complete that.. thats all of it.
Hope this fix the issue like it did to me.
You have to reference your project with this library.
Make sure you have downloaded the Android Support Library using the SDK Manager.
Create a libs/ directory in the root of your application project.
Copy the JAR file from your Android SDK installation directory (e.g., /extras/android/support/v4/android-support-v4.jar) into your application's project libs/ directory.
Right click the JAR file and select Build Path > Add to Build Path.
http://developer.android.com/tools/support-library/setup.html

Categories