0

i am trying to build android, with a small addition, but i gave me the following errors:

packages/apps/Settings/src/com/android/settings/cyanogenmod/ProgressBar.java:144: cannot find symbol symbol : variable ram_bar_button_reset location: class com.android.settings.R.string menu.add(0, MENU_RESET, 0, R.string.ram_bar_button_reset) ^ packages/apps/Settings/src/com/android/settings/cyanogenmod/ProgressBar.java:162: cannot find symbol symbol : variable ram_bar_reset location: class com.android.settings.R.string alertDialog.setTitle(R.string.ram_bar_reset);

when i open up the file with the correspondending lines:

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{       
menu.add(0, MENU_RESET, 0,
R.string.ram_bar_button_reset)
    .setIcon(R.drawable.ic_settings_backup)
    .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);   
}

and:

private void resetToDefault() 
{       
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
    alertDialog.setTitle(R.string.ram_bar_reset);
    alertDialog.setMessage(R.string.progressbar_reset_message);
    alertDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() 
{           
public void onClick(DialogInterface dialog, int id) 
{
    ProgressBarColorReset();            
}       
});         

    alertDialog.setNegativeButton(R.string.cancel, null);
    alertDialog.create().show();    
}

can someone tell me what to do?

Yann
  • 978
  • 2
  • 12
  • 31
OwnDroid
  • 11
  • 4

1 Answers1

1

To get a string value from string.xml, you should use: Reference

String myStr = getResources().getString(R.string.myStringID);

In your case, try

getResources().getString(R.string.ram_bar_reset);

alertDialog.setTitle( getResources().getString(R.string.ram_bar_reset));
alertDialog.setMessage( getResources().getString(R.string.progressbar_reset_message));
alertDialog.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() ;

Ensure, your res\values\strings.xml contains strings with names defined as below:

<resources>
    <string name="ram_bar_reset">Reset RAM Bar</string>
    <string name="progressbar_reset_message">Reset Progress Bar</string>
    <string name="ok">OK</string>
</resources>

EDIT: Final Java as requested:

CODE BLOCK 1:

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{       
menu.add(0, MENU_RESET, 0,
getResources().getString(R.string.ram_bar_button_reset))  // <---- Changed Here
    .setIcon(getResources().getDrawable(R.drawable.ic_settings_backup))  // <-- Changed Here
    .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);   
}

CODE BLOCK 2:

private void resetToDefault() 
{       
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
    alertDialog.setTitle( getResources().getString(R.string.ram_bar_reset)); // <---- Changed Here
    alertDialog.setMessage( getResources().getString(R.string.progressbar_reset_message)); // <---- Changed Here
    alertDialog.setPositiveButton(getResources().getString(R.string.ok), // <---- Changed Here
                new DialogInterface.OnClickListener() 


    {           
    public void onClick(DialogInterface dialog, int id) 
    {
        ProgressBarColorReset();            
    }       
    });



    alertDialog.setNegativeButton(getResources().getString(R.string.cancel),// <---- Changed Here
                                     null);
    alertDialog.create().show();    
}
Community
  • 1
  • 1
ngrashia
  • 9,869
  • 5
  • 43
  • 58