在C - 警告:格式'%d'需要匹配的'int'参数[-Wformat]

时间:2015-10-26 10:07:19

标签: c compiler-errors

我正在尝试构建一个可以执行多项不同任务的程序,例如将瓦特转换为dBm / dBW等,反之亦然。

我已经让单独的程序自己正常工作但是当我试图将它们与'select which convertor to run'部分组合时,我得到了编译器错误,程序失败,如下所述。

以下是相关代码:

public class ForecastFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor>{

    private ListView forecasteListView;
    private SimpleCursorAdapter forecasteAdapter;

    private String mLocation;
    private static final int FORE_CAST_LOADER = 404;

    private static final String[] FORE_CAST_COLUMNS = {
       WeatherContract.WeatherEntry.TABLE_NAME + "." + WeatherContract.WeatherEntry._ID,
       WeatherContract.WeatherEntry.COLUMN_DATE,
       WeatherContract.WeatherEntry.COLUMN_SHORT_DESC,
       WeatherContract.WeatherEntry.COLUMN_MAX_TEMP,
       WeatherContract.WeatherEntry.COLUMN_MIN_TEMP,
       WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING

    };

    public static final int COL_WEATHER_ID = 0;
    public static final int COL_WEATHER_DATE = 1;
    public static final int COL_WEATHER_DESC = 2;
    public static final int COL_WEATHER_MAX_TEMP = 3;
    public static final int COL_WEATHER_MIN_TEMP = 4;
    public static final int COL_LOCATION_SETTING = 5;

    public ForecastFragment() {
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        getLoaderManager().initLoader(FORE_CAST_LOADER, null, this);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.forcast_menu, menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.action_refresh){
           updateWeather();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    private void updateWeather() {
        FetchWeatherTask forecastWeather = new FetchWeatherTask(getActivity());

        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
        String cityName = sharedPreferences.getString(getString(R.string.pref_city_key),getString(R.string.pref_city_default));
        forecastWeather.execute(cityName, null, null);
    }

    @Override
    public void onStart() {
        super.onStart();
        updateWeather();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        forecasteAdapter = new SimpleCursorAdapter(getActivity(),
                R.layout.list_item_forecast,
                null,
                new String[]{WeatherContract.WeatherEntry.COLUMN_DATE,
                        WeatherContract.WeatherEntry.COLUMN_SHORT_DESC,
                        WeatherContract.WeatherEntry.COLUMN_MAX_TEMP,
                        WeatherContract.WeatherEntry.COLUMN_MIN_TEMP
                },
                new int[]{R.id.list_item_date_textView,
                        R.id.list_item_forecast_desc_textView,
                        R.id.list_item_high_textView,
                        R.id.list_item_low_textView
                }, 0

        );

        Log.e("onCreateView()", "List Adapter is of " + forecasteAdapter.getCount() + " size");

        View rootView = inflater.inflate(R.layout.fragment_main, container, false);    
        forecasteListView = (ListView) rootView.findViewById(R.id.listView_forecast);    
        return rootView ;
    }

    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        String sortOrder = WeatherContract.WeatherEntry.COLUMN_DATE + " ASC";

        mLocation = Utility.getPreferredLocation(getActivity());

        Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(mLocation, System.currentTimeMillis());

        Log.e("FORE_CAST_FRAGMENT", "Uri : " + weatherForLocationUri.toString() );
        return new CursorLoader(getActivity(), weatherForLocationUri, FORE_CAST_COLUMNS, null, null, sortOrder);
    }

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
        Log.e("Loader<Cursor>", "Size of Cursor is " + data.getCount());
        forecasteAdapter.swapCursor(data);
    }

    @Override
    public void onLoaderReset(Loader<Cursor> loader) {
        forecasteAdapter.swapCursor(null);
    }
}

这是我收到的错误:

Error during operation.

以下是我收到的编译器错误消息:

Compiler error.

1 个答案:

答案 0 :(得分:4)

你这里有一个错字

printf("\n\tYou entered: %d \n"),conv;

替换为

printf("\n\tYou entered: %d \n",conv);

以便您实际执行conv变量传递给printf()