I don't understand what I do wrong. I'd like to iterate list in jsp. (In class it's working)          public static void main(String[] args) throws ClassNotFoundException {     List&lt;SprawdzanieCen&gt; PaS = SprawdzanieCenLista.PS();      for (SprawdzanieCen ob : PaS ) {         System.out.println("nrFaktury: "+ob.nrFaktury);     } }   But as I wrote I'd like to do it in jsp jsp code is as follows:          &lt;%  out.println("Lets Start"); List&lt;SprawdzanieCen&gt; PaS = SprawdzanieCenLista.PS(); for (SprawdzanieCen s : PaS) {     s.nrFaktury; }  %&gt;   I do not understand why "nrFaktury" is underline on red. Hot to iterate this list. Help,
121706
I just started learning JSP technology, and came across a wall.  How do you output HTML from a method in &lt;%! ... %> JSP declaration block?  This doesn't work:  &lt;%!  void someOutput() {     out.println("Some Output"); } %&gt; ... &lt;% someOutput(); %&gt;   Server says there's no &ldquo;out&rdquo;.  U: I do know how to rewrite code with this method returning a string, but is there a way to do this inside &lt;%! void () {  } %> ? Though it may be non-optimal, it's still interesting.
17824
I had one batch class in which i am passing some data required for creating object record.But when i call that batch class from parent class variables are initialized but start method are not called as there is no record to query i also tried with iterable object but not able to do that.My code is as below  global class testBatchClass implements Database.Batchable&lt;SObject&gt;,Database.Stateful{     public List&lt;sObject&gt; sObjectList;     public string objectName;     public String dataList;      public testBatchClass(String objectName,String inputdata){          String listType = 'List&lt;'+objectName+'&gt;';         system.debug('list type value is'+listType);         List&lt;SObject&gt; castRecords = (List&lt;SObject&gt;)Type.forName(listType).newInstance();         this.sObjectList = castRecords;         this.objectName = objectName;         this.dataList = inputdata;      }     global Iterable&lt;SObject&gt; start(Database.BatchableContext batchableContext) {         return new sObjectList{};     }     global void execute(Database.BatchableContext batchableContext, List&lt;sobject&gt; scope){          List&lt;OpportunityRenewal__mdt&gt; mdtList = new List&lt;OpportunityRenewal__mdt&gt;([Select id,Api_Name_of_Fields__c,Sobject_Name__c from TestFileUploadCustomSetting1__mdt where Sobject_Name__c=:objectName]);         List&lt;String&gt; fieldName = new List&lt;String&gt;();         for(OpportunityRenewal__mdt md : mdtList){             if(md.Sobject_Name__c == objectName){                 fieldName = md.Api_Name_of_Fields__c.Split(',');                 break;             }         }         List&lt;String&gt; dataRowsSplit= dataList.split(',');         dataRowsSplit.remove(0);         for(String eachRow: dataRowsSplit){             List&lt;String&gt; splitString = eachRow.Split(',');             sObject sobj = Schema.getGlobalDescribe().get(objectName).newSObject();             for(Integer i=0; i &lt;= splitString.Size(); i++){                 sobj.put(fieldName[i],splitString[i]);             }             scope.add(sobj);         }         if(scope != Null &amp;&amp; scope.Size() &gt; 0){             upsert scope;         }     }      global void finish(Database.BatchableContext batchableContext) {} }   Thanks
2603
I have been bitten by something unexpected recently. I wanted to make something like that:  try :      thing.merge(iterable) # this is an iterable so I add it to the list except TypeError :      thing.append(iterable) # this is not iterable, so I add it   Well, It was working fine until I passed an object inheriting from Exception which was supposed to be added.  Unfortunetly, an Exception is iterable. The following code does not raise any TypeError:  for x in Exception() :     print 1   Does anybody know why?
52560
I am getting "Error System.QueryException: List has no rows for assignment to SObject".   Line 1: Account ac = [select id from Account where name='testaccount' limit 1] Line 2: if(ac != null) {           //do something         }   I got the above error in line 2 if there is no record.   Any help?
83735
private void activateRecords(long[] stuff) {     ...     api.activateRecords(Arrays.asList(specIdsToActivate));   }   Shouldn't this call to Arrays.asList return a list of Longs?  Instead it is returning a List&lt;long[]&gt;  public static &lt;T&gt; List&lt;T&gt; asList(T... a)   The method signature is consistent with the results, the varargs throws the entire array into the list.  It's the same as new ArrayList(); list.add(myArray)  And yes, I know it's meant to be used like this: Arrays.asList(T t1, T t2, T t3)  I guess what I'm getting at, is instead of the varargs form, why can't I just have my old asList method (at least I think this is how it used to work) that would take the contents and put them individually into a list?  Any other clean way of doing this?
46641
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady); var listTitle = []; var listUrl = []; var listIsActive = []; var listOrder = [];  function sharePointReady(){ var siteUrl = mysite;     var clientContext = new SP.ClientContext(siteUrl); var oList = clientContext.get_web().get_lists().getByTitle('Privacy Statements');  var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml(''); this.collListItem = oList.getItems(camlQuery);  clientContext.load(collListItem);  clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));         }    function onQuerySucceeded(sender, args) {  var listItemEnumerator = collListItem.getEnumerator();   while (listItemEnumerator.moveNext()) {     var oListItem = listItemEnumerator.get_current();     listTitle.push(oListItem.get_item('Title'));     listUrl.push(oListItem.get_item('PrivacyStatementUrls').get_url());      listIsActive.push(oListItem.get_item('IsActive'));     listOrder.push(oListItem.get_item('SortOrder'));    } sessionStorage.setItem('Title', JSON.stringify(listTitle)); sessionStorage.setItem('Url', JSON.stringify(listUrl)); sessionStorage.setItem('IsActive', JSON.stringify(listIsActive)); sessionStorage.setItem('Order', JSON.stringify(listOrder)); var retrievedTitle = sessionStorage.getItem("Title"); var arTitle = JSON.parse(retrievedTitle); var retrievedUrl = sessionStorage.getItem("Url"); var arUrl = JSON.parse(retrievedUrl); var retrievedIsActive = sessionStorage.getItem("IsActive"); var arIsAct = JSON.parse(retrievedIsActive); var retrievedOrd = sessionStorage.getItem("Order"); var arOrd = JSON.parse(retrievedOrd);  var test = '' for(x=0; x&lt;arTitle.length+1;x++) {      for(i=0; i&lt;arTitle.length+1;i++)     {          if(arIsAct[i] == true){             if(arOrd[i] == x){                 test +='&lt;a href="'+arUrl[i]+'"&gt;'+arTitle[i]+'&lt;/a&gt;&lt;br&gt;';             }            }      } }  document.getElementById('test').innerHTML = test; }  function onQueryFailed(sender, args) {  alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); }   I am trying to use caching with sessionstorage when getting items from a list, so it doesn't have to keep querying the list over and over again. It can just check with the sessionstorage and if its in the list there is no need to get the item but if its not in sessionstorage get the item from the list. I am not sure how to do this, my code above shows my attempt
122930
I'm comparing two list given in the list to see if the item.name exists in both for loop. If not then add into a list to show the error for the missing names.  set&lt;id&gt; setAssetIds = new set&lt;id&gt;(); list&lt;Asset_Store__c&gt;  assets = [select id,name......]; for(Asset_Store__c item : assets ) {     setAssetIds.add(item.id);  }   list&lt;Meter__c&gt;  meters = [select id,name......where id in : setAssetIds];  //now comparing the two lists for(Asset_Store__c a : assets) {    for(Meter__c m : meters)    {      if(a.Name != m.Name)      {        //not matched...        break;      }     } }   the problem with the above approach is that, its not finding the correct name.
85933
I was writing a toString() for a class in Java the other day by manually writing out each element of the class to a String and it occurred to me that using reflection it might be possible to create a generic toString() method that could work on ALL classes. I.E. it would figure out the field names and values and send them out to a String.  Getting the field names is fairly simple, here is what a co-worker came up with:  public static List initFieldArray(String className) throws ClassNotFoundException {      Class c = Class.forName(className);     Field field[] = c.getFields();     List&lt;String&gt; classFields = new ArrayList(field.length);      for (int i = 0; i &lt; field.length; i++) {         String cf = field[i].toString();         classFields.add(cf.substring(cf.lastIndexOf(".") + 1));     }      return classFields; }   Using a factory I could reduce the performance overhead by storing the fields once, the first time the toString() is called. However finding the values could be a lot more expensive.  Due to the performance of reflection this may be more hypothetical then practical. But I am interested in the idea of reflection and how I can use it to improve my everyday programming.
108218
This is an extension of question from . I just want to verify if the following is actually safe enough for production use.  List&lt;string&gt; lists = new List&lt;string&gt;(); //Code to retrieve lists from DB     foreach (string list in lists) {     Button btn = new Button();     btn.Click += new EventHandler(delegate { MessageBox.Show(list); }); }   I only run through the above once per startup. For now it seems to work alright. As Jon has mentioned about counterintuitive result in some case. So what do I need to watch out here? Will it be ok if the list is run through more than once?
18599
I want to return two objects from a Java method and was wondering what could be a good way of doing so?  The possible ways I can think of are: return a HashMap (since the two Objects are related) or return an ArrayList of Object objects.  To be more precise, the two objects I want to return are (a) List of objects and (b) comma separated names of the same.  I want to return these two Objects from one method because I dont want to iterate through the list of objects to get the comma separated names (which I can do in the same loop in this method).  Somehow, returning a HashMap does not look a very elegant way of doing so.
66803
I am trying to call my Apex class from a trigger:  trigger newCrossSellAccounts on Account (before insert) {    crossSellModule.insertAfterAccount2(trigger.new); }   On the class I have:  public void insertAfterAccount2(list&lt;account&gt; accountList){   When I try to save trigger I get error:  Method does not exist or incorrect signature: crossSellModule.insertAfterAccount2(LIST&lt;Account&gt;) at line 2 column 4    Now from  it says .new "Returns a list of the new versions of the sObject records." I tried to change the function on class to:  public void insertAfterAccount2(sObject&lt;account&gt; accountList){   But I get error:  Invalid type: sObject&lt;account&gt;    Should I loop thru and create a list in trigger first? Or is there are workaround. Also, how one would test such trigger/class combination?
20509
I have a small code example I want to include in the Javadoc comment for a method.    /**  * -- ex: looping through List of Map objects --  * &lt;code&gt;  * for (int i = 0; i &lt; list.size(); i++) {  *      Map map = (Map)list.get(i);  *      System.out.println(map.get("wordID"));  *      System.out.println(map.get("word"));  * }  * &lt;/code&gt;  *   * @param query - select statement  * @return List of Map objects  */   The problem is the code example shows up in the Javadoc with no line breaks making it hard to read.    -- ex: looping through List of Map objects -- for (int i = 0; i list.size(); i++) { Map map = (Map)list.get(i); System.out.println(map.get("wordID")); System.out.println(map.get("word")); }  Parameters query - - select statement  Returns: List of Map objects    I guess I am wrong in assuming the code tag would handle line breaks.  What is the best way to format code examples in Javadoc comments ?
73349
When I use an Iterator of Object I use a while loop (as written in every book learning Java, as Thinking in Java of Bruce Eckel):  Iterator it=...  while(it.hasNext()){     //... }   but sometime i saw than instead somebody use the for loop:  Iterator it=... for (Iterator it=...; it.hasNext();){     //... }   I don't' understand this choice:    I use the for loop when I have a collection with ordinal sequence (as array) or with a special rule for the step (declared generally as a simple increment counter++).  I use the while loop when the loop finishes with I have'nt this constraints but only a logic condition for exit.   It's a question of style-coding without other cause or it exists some other logic (performance, for example) that I don't' know?  Thanks for every feedback
129
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?  What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?
122089
I try to add an item to my sharepoint list from a custom web part. Is there any mistake in my code?  [WebMethod]         public static string AjouterDemande()         {             SPList ListeDemandeConge = SPContext.Current.Site.RootWeb.Lists["DEMANDE CONGÉ"];             SPListItem ListItem = ListeDemandeConge.Items.Add();             ListItem["CODE"] = code;             ListItem["DEMANDEUR"] = Utilisateur.LoginName;             ListItem["DATE DEMANDE"] = DateTime.Today.Date;             ListItem["DATE FIN"] = EndDateD;             ListItem["DATE DEPART"] = StartDateD;             ListItem["DUREE"] = int.Parse(DayCount);             ListItem["PREMIER RESPONSABLE"] = Employe.FirstSuperior.LoginName;             ListItem["DEUXIEME RESPONSABLE"] = Employe.SecondSuperior.LoginName;             ListItem["PRESENCE PRES"] = Boolean.Parse(FirstRespPresent);             ListItem["SOLDE CONGE"] = Conge.SoldeAnneeConge;             ListItem["MOIS"] = int.Parse(StartDateTab[1]);             ListItem["ANNEE"] = int.Parse(StartDateTab[0]);             ListItem["JOURS APPROUVEES"] = 0;             ListItem.Update();             ListeDemandeConge.Update();             return "true";          }   When I use F10 to process debugging step by step and get to my listitem.update(), it went out without giving any error.
47611
I want to use a Java file SaveProp which is written in a package user. The class file has been placed in WEBINF/classes. Below are the two lines which cause the issue.  jsp:useBean id="user" class="user.SaveProp" scope="session"  jsp:setProperty name="user" property="*"   It throws:  The value for the useBean class attribute user.SaveProp is invalid   I'm using Tomcat 6.0.
29728
In other words, can I do something like  for() {     for {        for {        }     } }   Except N times? In other words, when the method creating the loops is called, it is given some parameter N, and the method would then create N of these loops nested one in another?  Of course, the idea is that there should be an "easy" or "the usual" way of doing it. I already have an idea for a very complicated one.