what is the error 'List<String> storyMapList = new ArrayList(); for (Object story :…
- User
what is the error 'List storyMapList = new ArrayList(); for (Object story : storiesWithTests) { if (story instanceof String) { storyMapList.put((String) story); } } resultMap.put("storyList", storyMapList);' cannot find symbol [ERROR] symbol: method put(java.lang.String)
- Assistant
The error message you are encountering is due to the use of the
putmethod on aListobject, butputis not a valid method for aListin Java. Instead, you should use theaddmethod to add elements to aList.Here's a corrected version of your code:
List<String> storyMapList = new ArrayList<>(); for (Object story : storiesWithTests) { if (story instanceof String) { storyMapList.add((String) story); // Use add instead of put } } resultMap.put("storyList", storyMapList);Explanation of the Changes:
- Changed
puttoadd: SinceArrayListimplements theListinterface, you should useadd()to add items to the list. - Generic Type for ArrayList: It's good practice to specify the generic type when creating an instance of
ArrayList. In this case, I specifiedArrayList<String>().
After making these changes, your code should compile without the "cannot find symbol" error related to the
putmethod. - Changed
- User
java difference between lists
- Assistant
- User
elements in backlogCsvList - List storiesWithTests
- Assistant
- User
'List totalNumberOfTestsForStories = com.tcs.stest.alm.entity.backlog.BlogTcaseMappingFactory.findTotalTestsForStories(session, backlogCsvList, project.getId()); resultMap.put("totalNumberOfTestsForStories", totalNumberOfTestsForStories[0]); resultMap.put("averageNumberOfTestsPerStories", totalNumberOfTestsForStories[0]/backlogCsvList.size());' array required, but java.util.List found
- Assistant
The error message you're seeing indicates that you're trying to access the first element of a as if it were an array. In Java, is an interface that does not support array-style indexing using square brackets (). Instead, you need to use the method to retrieve elements from a .
- User
'List totalNumberOfTestsForStories = com.tcs.stest.alm.entity.backlog.BlogTcaseMappingFactory.findTotalTestsForStories(session, backlogCsvList, project.getId()); if (!totalNumberOfTestsForStories.isEmpty()) { int totalTests = (int) totalNumberOfTestsForStories.get(0); double averageTests = (double) totalTests / backlogCsvList.size(); resultMap.put("totalNumberOfTestsForStories", totalTests); resultMap.put("averageNumberOfTestsPerStories", averageTests); } else { resultMap.put("totalNumberOfTestsForStories", 0); resultMap.put("averageNumberOfTestsPerStories", 0.0); }' incompatible types: java.lang.Object cannot be converted to int
- Assistant
- User
'public static java.util.List findTotalTestsForStories(org.hibernate.Session session, List backlog_integration_ids, java.lang.Long projectPk) throws Exception { java.lang.StringBuffer queryBuffer = new java.lang.StringBuffer();
queryBuffer.append("SELECT count(*) "); queryBuffer.append("FROM dp_domain2.blog_tcase_mapping "); queryBuffer.append("WHERE backlog_integration_id IN (:backlog_integration_ids) "); queryBuffer.append("AND project_fk = :projectPk "); queryBuffer.append("GROUP BY backlog_integration_id"); org.hibernate.Query query = session.createSQLQuery(queryBuffer.toString()); query.setParameter("projectPk", projectPk); query.setParameter("backlog_integration_ids", backlog_integration_ids); return query.list(); }' return int - Assistant
- User
the query will return only count return only that number not int
- Assistant