简体   繁体   中英

Android studio 1.0.2 cannot resolve symbol R in all java sources except MainActivity

I have MainActivity under package com.example.example. I have several fragments under com.example.example.fragments. I have several classes under com.example.example.utils.

While MainActivity is ok, all the others have problems resolving symbol R. I moved one of them to com.example.example but still had a problem so I moved it back to com.example.example.utils and suddenly it was OK but then I realized it added com.example.example.R to the import section. Though it did work I removed it because it's a workaround and not a fix (MainActivity doesn't have this import in its section).

All my XML files have a green indication so it's not that (I think). I read a lot of posts about this issue but nothing helped, neither clean nor build. What else can cause this error?

Update: Apparently, when moving all sources under com.example.example it does work so the question should be: how can I make it work when sources are under a different package inside the main com.example.example

Actually, this not a work around. If you take a look at your manifest, the root level tag has the package="com.example.example" attribute. This is indeed the correct behavior. That is the namespace of the application package, and all resources are located there. The reason your MainActivity does not have this is because it is located within the package namespace, in your case its package is already com.example.example .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM