0

my line : <action android:name="@string/s" />

changes to <action android:name="@strings/s1" />

when I hit the Run app button and since I don't have a string named s1 it gives me an error :

Error:(31, 39) No resource found that matches the given name (at 'name' with value '@strings/s1').

Also whether it should be @string/ or @strings/?(cause my guide says it should me @string/)

I tried putting : <action android:name="R.strings.s" />

but the same result

gif : http://g.recordit.co/SnRcWopWgE.gif

  • Try to Clean your project and see if this issue persists – EtherPaul Jul 02 '17 at 19:57
  • already did that –  Jul 02 '17 at 19:59
  • Which file is this? – Eenvincible Jul 02 '17 at 19:59
  • I don't know what are you asking @Eenvincible –  Jul 02 '17 at 20:00
  • Where are you declaring these actions? – Eenvincible Jul 02 '17 at 20:03
  • 1
    Then just try to give your String a reasonable name; `s` is just so mean; :) I am sure you can find a word – Eenvincible Jul 02 '17 at 20:06
  • renaming the string doesn't help at all and I am declaring these actions in AndroidManifest.xml in the second activity I created –  Jul 02 '17 at 20:10
  • That is interesting; so if you clean the project and even invalidate cache on the IDE, it doesn't help? What is that `intent-filter` for again? – Eenvincible Jul 02 '17 at 20:19
  • even cleaning the project changes the code and this project is just to check how do intent-filters work –  Jul 02 '17 at 20:22
  • if you change in your instant run or full mainfest, it will always take from your orignal mainfest file in that you didnt edit at all – Muthukrishnan Rajendran Jul 02 '17 at 20:25
  • in your gif you can clearly see you have 2 mainfest open, and that 2 are instant run and full mainfest, you should not edit in that. Just close that and dont click the error to open the mainfest, open the mainfest from side panel and edit in that your problem will be solved – Muthukrishnan Rajendran Jul 02 '17 at 20:29
  • The yellow-coloured tabs in your IDE typically indicate a generated file, in which any changes are overriden at compilation. Are you sure you have the correct Manifest open, and you aren't editing something in the build/gen folder? – PPartisan Jul 02 '17 at 20:31

2 Answers2

0

You have a typo. You put an extra s.

<action android:name="@string/s1" 

is correct.

The problem is with your instant run Please disable it from setting and make a full build again. Also change the original manifest! not the build or instant run version.

As Muthukrishnan Rajendran mention, pay attention :

If you use a string resource, it won't work. you should use a complete string.

If you want to open another activity, you should use Explicit intents.

Intent intent = new Intent(this,OtherActivity.class);
startActivity(intent);
finish();

There is no need do define any intent filter for what you want to do.

Omid Heshmatinia
  • 5,089
  • 2
  • 35
  • 50
  • Hi If you give like this you will get this error "Error:(31) Tag attribute name has invalid character ' '." while compiling, try in your studio and check – Muthukrishnan Rajendran Jul 02 '17 at 20:09
  • that doesn't help. it gets changed anyway and that is the reason for my confusion between @string/ or @strings/ in the first place (as I mentioned in the question) –  Jul 02 '17 at 20:12
  • hey you are changing the value in instant run Mainfest close that , and open your app mainfest and change – Muthukrishnan Rajendran Jul 02 '17 at 20:19
  • again i am telling you, Please close all the file and open only your mainfest in your side folder and edit there. you are confused with instant run mainfest, full mainfest and your actual mainfest. – Muthukrishnan Rajendran Jul 02 '17 at 20:24
  • But I said in the first comment if you give like your answer we will get the error – Muthukrishnan Rajendran Jul 02 '17 at 20:35
  • I get it. I know changed the original manifest file but here are my files : https://www.dropbox.com/sh/47k7lf1urxgsn70/AACGEV_CejxNPGEF1B8unTtTa?dl=0 since I am using the same @string/setstring now, the OtherActivity should launch on its own but its not.rather the app is crashing –  Jul 02 '17 at 20:36
  • @Smartiz, why are you duplicating the answer which already gave.? – Muthukrishnan Rajendran Jul 02 '17 at 20:37
  • @MuthukrishnanRajendran please help me with this. Look at my code. Since I used @string/setstring both in android manifest and main activity.java, accordingly my other activity should launch immediately which is happening if I replace them with the actual string but not when I use @string/setstring , people tell me that is not good programming practice –  Jul 02 '17 at 20:42
  • Could you please read my answer..? I gave clearly we can't give string reference to action name, instead give the string directly in the name. – Muthukrishnan Rajendran Jul 02 '17 at 20:44
  • What do you want to do ?!?!?!?! your code is so strange. do you want to open another activity ? @ErwinSmith – Omid Heshmatinia Jul 02 '17 at 20:44
  • Ok here is what I want to do. I am a beginner to android development and reading about intents and intents filters. so as soon as my main activity starts I make an intent of action @string/setstring and I want my Otheractivity to catch that and run. Instead that is not happening. What is working is if I don't use "@string/setstring" and directly quote some random strings over there. so basically my variable THE_ACTION and action android:name are not matching when they are both set to "@string/setstring" while they match if I set them both to "hello" –  Jul 02 '17 at 20:47
  • oh ok but my guide asks me to use the string resource since it is a good practice to use that –  Jul 02 '17 at 20:51
  • I really do not know what guide are yo using, but if you want to open an specific activity, you should use explicit intent. in which you define the receiver yourself. @ErwinSmith – Omid Heshmatinia Jul 02 '17 at 20:53
  • I have the following entry in my strings.xml file : hello I can use @string/setstring when calling the intent in my Main_Activity .java right?so I cannot write in my manifest file so do I change it to . Its not working both ways. It is only working in the case I don't use string resource at all. –  Jul 02 '17 at 21:27
0

I think you might be confused about the nature of the intent filter. It could be worth trying what can be considered a default action to load the home screen. Try removing your action and replace with

< action android:name="android.intent.action.MAIN" />

Document reference: https://developer.android.com/reference/android/content/Intent.html

Lew Perren
  • 1,209
  • 1
  • 10
  • 14