Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android getString() returns wrong string

I'm facing the Problem that getString() returns not the String of the id but another string. But first here is my Code:

public public class ShopFragment extends Fragment {
    ...
    public class ShopManager(){
        ...
        private TableRow[] getRowsFromItems(){
        ...
        TextView headlineName = new TextView(getContext());
        headlineName.setText(getString(R.string.shop_headline_name));
        TextView headlinePrice = new TextView(getContext());
        headlinePrice.setText(getString(R.string.shop_headline_price));
        ...
        }
    }
}

strings.xml:

<resources>
    ...
    <string name="show_leaderboards">Leaderboards</string>
    <string name="show_achievements">Achievements</string>
    ...
    <string name="shop_headline_name">Article</string>
    <string name="shop_headline_price">Price</string>
    ...
</resources>

The Problem is, that getString(R.string.shop_headline_name) returns "Achievements" and getString(R.string.shop_headline_price) returns "Leaderboards". I have no idea how to fix this and I'm quite confused why this happens. What am I doing wrong? Thanks for your answers

like image 353
cmtut Avatar asked Jul 14 '16 16:07

cmtut


1 Answers

Clean and build should do the trick. Your R.java, which holds all the ids, was not generated properly. A clean and build will generate it properly.

like image 168
Tony Avatar answered Oct 20 '22 13:10

Tony