Digital Developer Conference: a FREE half-day online conference focused on AI & Cloud – North America: Nov 2 – India: Nov 9 – Europe: Nov 14 – Asia Nov 23 Register now

Close outline
  • United States
IBM?
  • Site map
IBM?
  • Marketplace

  • Close
    Search
  • Sign in
    • Sign in
    • Register
  • IBM Navigation
IBM Developer Answers
  • Spaces
    • Blockchain
    • IBM Cloud platform
    • Internet of Things
    • Predictive Analytics
    • Watson
    • See all spaces
  • Tags
  • Users
  • Badges
  • FAQ
  • Help
Close

Name

Community

  • Learn
  • Develop
  • Connect

Discover IBM

  • ConnectMarketplace
  • Products
  • Services
  • Industries
  • Careers
  • Partners
  • Support
10.190.13.195

Refine your search by using the following advanced search options.

Criteria Usage
Questions with keyword1 or keyword2 keyword1 keyword2
Questions with a mandatory word, e.g. keyword2 keyword1 +keyword2
Questions excluding a word, e.g. keyword2 keyword1 -keyword2
Questions with keyword(s) and a specific tag keyword1 [tag1]
Questions with keyword(s) and either of two or more specific tags keyword1 [tag1] [tag2]
To search for all posts by a user or all posts with a specific tag, start typing and choose from the suggestion list. Do not use a plus or minus sign with a tag, e.g., +[tag1].
  • Ask a question

HTTP response code "400, error: Data supplied is missing critical information. all objectives must have keys" when trying to connect android application to Tradeoff Analytics API

310002CJS4 gravatar image
Question by ssabouni  (1) | Dec 08, 2016 at 05:49 PM watsontradeoff-analyticsandroid application

I am trying to connect my android application to use the Tradeoff Analytics API. Here is part of the code I have used to do this:

     private void showDilemma(final Dilemma dilemma) {
         runOnUiThread(new Runnable() {
             @Override public void run() {
                 tradeoffTextView.setText(dilemma.toString());
             }
         });
     }
 
     private class WatsonTask extends AsyncTask<String, Void, String> {
         @Override
         protected String doInBackground(String... params) {
             showDilemma(tradeoffService.dilemmas(problem).execute());
 
             return "processing tasks done";
         }
 
         @Override
         protected void onPostExecute(String result) {
             tradeoffTextView.setText("Tradeoff Analytics Status: " + result);
         }
 
     }
 
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
         setSupportActionBar(toolbar);
 
         tradeoffButton = (Button) findViewById(R.id.tradeoffButton);
         tradeoffTextView = (TextView) findViewById(R.id.tradeoffTextView);
 
         tradeoffService = initTradeoffAnalytics();
         problem = new Problem("phone");
 
         String price = "price";
         String ram = "ram";
         String screen = "screen";
 
         // Define the objectives
         List<Column> columns = new ArrayList<Column>();
         problem.setColumns(columns);
 
         NumericColumn priceColumn = new NumericColumn();
         **priceColumn.setKey(price);**
         priceColumn.setGoal(Column.Goal.MIN);
         priceColumn.setObjective(true);
         priceColumn.range(0, 400);
         priceColumn.setFullName("Price");
         priceColumn.setFormat("number:2");
         columns.add(priceColumn);
 
         NumericColumn screenColumn = new NumericColumn();
         **priceColumn.setKey(screen);**
         priceColumn.setGoal(Column.Goal.MAX);
         priceColumn.setObjective(true);
         priceColumn.setFullName("Screen");
         priceColumn.setFormat("number:2");
         columns.add(screenColumn);
 
         NumericColumn ramColumn = new NumericColumn();
         **priceColumn.setKey(ram);**
         priceColumn.setGoal(Column.Goal.MAX);
         priceColumn.setFullName("RAM");
         priceColumn.setFormat("number:2");
         columns.add(ramColumn);
 
         // Define the options to choose
         List<Option> options = new ArrayList<Option>();
         problem.setOptions(options);
 
         HashMap<String, Object> galaxySpecs = new HashMap<String, Object>();
         galaxySpecs.put(price, 50);
         galaxySpecs.put(ram, 45);
         galaxySpecs.put(screen, 5);
         options.add(new Option("1", "Galaxy S4").values(galaxySpecs));
 
         HashMap<String, Object> iphoneSpecs = new HashMap<String, Object>();
         iphoneSpecs.put(price, 99);
         iphoneSpecs.put(ram, 40);
         iphoneSpecs.put(screen, 4);
         options.add(new Option("2", "iPhone 5").values(iphoneSpecs));
 
         HashMap<String, Object> optimusSpecs = new HashMap<String, Object>();
         optimusSpecs.put(price, 10);
         optimusSpecs.put(ram, 300);
         optimusSpecs.put(screen, 5);
         options.add(new Option("3", "LG Optimus G").values(optimusSpecs));
 
         tradeoffButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 WatsonTask task = new WatsonTask();
                 task.execute(new String[]{});
 
             }
         });
 }

When I try to execute this code, the application is crashing and I am getting the following error message: E/WatsonService: POST https://gateway.watsonplatform.net/tradeoff-analytics/api/v1/dilemmas, status: 400, error: Data supplied is missing critical information. all objectives must have keys

I am not sure why I am getting this error message seeing as I have checked all the objectives ( price, ram and screen) and they each have a set key. The code is also very similar to that available in the online documentation so I am not sure where I have gone wrong. Any help would be much appreciated, thanks in advance :)

People who like this

  0
Comment
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster

1 reply

  • Sort: 
27000041J2 gravatar image

Answer by DavidAmid (644) | Dec 09, 2016 at 02:06 AM

You are setting the priceColumn each time (same goes for RAM) its a copy paste error

 THIS IS SCREEN COLUMN NumericColumn screenColumn = new NumericColumn();
 THIS IS NOT SCREEN COLUMN        **priceColumn.setKey(screen);**
 THIS IS NOT SCREEN COLUMN          priceColumn.setGoal(Column.Goal.MAX);
 THIS IS NOT SCREEN COLUMN          priceColumn.setObjective(true);
 THIS IS NOT SCREEN COLUMN          priceColumn.setFullName("Screen");
 THIS IS NOT SCREEN COLUMN          priceColumn.setFormat("number:2");
  THIS IS SCREEN COLUMN        columns.add(screenColumn);
Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster

Follow this question

103 people are following this question.

Answers

Answers & comments

Related questions

ANDROID APPLICATION TO CHAT WITH IBM BLUEMIX DEVICE 1 Answer

Can Tradeoff Analytics be used to evaluate the best possible grouping of independent problems? 5 Answers

Watson dialog API returns the same output every time 2 Answers

Watson value for date in predictive modeling 0 Answers

How can I integrate watson API in JSP? 1 Answer

  • Contact
  • Privacy
  • IBM Developer Terms of use
  • Accessibility
  • Report Abuse
  • Cookie Preferences

Powered by AnswerHub

Authentication check. Please ignore.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • API Connect
  • Analytic Hybrid Cloud Core
  • Application Performance Management
  • Appsecdev
  • BPM
  • Blockchain
  • Business Transaction Intelligence
  • CAPI
  • CAPI SNAP
  • CICS
  • Cloud Analytics
  • Cloud Automation
  • Cloud Object Storage
  • Cloud marketplace
  • Collaboration
  • Content Services (ECM)
  • Continuous Testing
  • Courses
  • Customer Experience Analytics
  • DB2 LUW
  • Data and AI
  • DataPower
  • Decision Optimization
  • DevOps Build
  • DevOps Services
  • Developers IBM MX
  • Digital Commerce
  • Digital Experience
  • Finance
  • Global Entrepreneur Program
  • Hadoop
  • Hybrid Cloud Core
  • Hyper Protect
  • IBM Cloud platform
  • IBM Design
  • IBM Forms Experience Builder
  • IBM Maximo Developer
  • IBM StoredIQ
  • IBM StoredIQ-Cartridges
  • IIDR
  • ITOA
  • InformationServer
  • Integration Bus
  • Internet of Things
  • Kenexa
  • Linux on Power
  • LinuxONE
  • MDM
  • Mainframe
  • Messaging
  • Node.js
  • ODM
  • Open
  • PartnerWorld Developer Support
  • PowerAI
  • PowerVC
  • Predictive Analytics
  • Product Insights
  • PureData for Analytics
  • Push
  • QRadar App Development
  • Run Book Automation
  • Search Insights
  • Security Core
  • Storage
  • Storage Core
  • Streamsdev
  • Supply Chain Business Network
  • Supply Chain Insights
  • Swift
  • UBX Capture
  • Universal Behavior Exchange
  • UrbanCode
  • WASdev
  • WSRR
  • Watson
  • Watson Campaign Automation
  • Watson Content Hub
  • Watson Marketing Insights
  • dW Answers Help
  • dW Premium
  • developerWorks Sandbox
  • developerWorks Team
  • Watson Health
  • More
  • Tags
  • Questions
  • Users
  • Badges