In this app I'm dynamically creating a counter object with a LinearLayout, TextView , and two Buttons, I want the onClickListener inside the class since that seems like the best solution.   The only thing I can think of is that I'm somehow getting the ID creation wrong. What are the best practices when dynamically creating things?  A screenshot of the app and all code is included.  public class Counter implements View.OnClickListener {      private final int subButtonId = View.generateViewId();  ...      private void createSubButton() {          subButton = new Button(context);         subButton.setLayoutParams(new LinearLayout.LayoutParams(buttonWidth, LinearLayout.LayoutParams.MATCH_PARENT, 0.5f));         subButton.setText("-");         subButton.setTextSize(buttonTextSize);         subButton.setId(subButtonId);         subButton.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL);         container.addView(subButton);          sub = mainContainer.findViewById(subButtonId);         sub.setOnClickListener(new MyOnClickListener() {             @Override             public void onClick(View v) {                 subCount();                 disp.setText(count.toString());             }         });     }  }  class MyOnClickListener implements View.OnClickListener {       public MyOnClickListener() {      }      @Override     public void onClick(View v) {      } }   Counter Class:    Main Class:   Logcat:   Image of App:
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?
101466
I have the following situation I think would be best to show in sample program code.  I have a Java class that extends JPanel.  In this class are two objects which are two more JPanels.  In one of the JPanel objects is a JTable object.  I added a listener to this JTable that detects a double click.  When it detects a double click, I want to fire a method in the top class.  How do I reference this method in Java?  public class TopPanel extends JPanel {    JPanel OnePanel;   JPanel TwoPanel;    public void MethodToFire;  }  public class OnePanel extends JPanel {    JTable TheTable;  }  public class TheTable extends JTable {    public TheTable {     this.addMouseListener(new MouseAdapter(){       public void mouseClicked(MouseEvent e){           if (e.getClickCount() == 2){ SYNTAX CALLING THE METHOD IN TopPanel  }       }     } );   } }
39132
I created a custom button for custom object to place in the related list. The custom object has two look-ups, one for case and one for account. This button, when clicked, should open in a new window to save a record of the custom object, with the default values for each look-up to populate automatically depending on the record where the button was clicked. It works for every record so far, except one case. It then throws the error: A problem with the Onclick Javascript for this button or link was encountered: Unexpected identifier.  I couldn't find any differences between records where it works and doesn't.  Code:  window.open('a2U/e?CF00N600000037HI4={!Account.Name}&amp;CF00N600000037HI4_lkid={!Account.Id}&amp;retURL=%2F{!Account.Id}&amp;CF00N600000037HI5={!Case.CaseNumber}&amp;CF00N600000037HI5_lkid={!Case.Id}&amp;retURL=%2F{!Case.Id}','','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=yes,location=yes,status=yes');
15895
how can i check wrong id  public with sharing class ContactDetailController {      private ApexPages.StandardController standardController;     public string conId{get;set;}       public ContactDetailController(ApexPages.StandardController standardController)      {        this.standardController = standardController;        conId = ApexPages.CurrentPage().getParameters().get('Id');         if(standardController.getId()==null)         {             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter Id on the Address Bar'));         }           //this.standardController.addFields(new List&lt;String&gt; {'FirstName','lastname','mobilephone','Accountid','otherphone','title','fax','Department','Email','Birthdate','AssistantName','Reportstoid','Assistantphone','leadsource','OtherStreet','MailingCity','othercity','MailingState','otherstate', });          // getDescribe that retrive whole fields of the particular object         Schema.DescribeSObjectResult r = Contact.sObjectType.getDescribe();         List&lt;String&gt;apiNames =  new list&lt;String&gt;();         for(string apiName : r.fields.getMap().keySet()){             apiNames.add(apiName);         }         System.debug(apiNames);         this.standardController.addFields(apiNames);      }     public PageReference ValidateId()     try{                Id realContId = standardController.getId();                if(Schema.Contact.SObjectType != realContId.getSobjectType())||                {                     ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, 'Id specified is not an Contact id!'));                     return null;                }          }         catch (Exception e)         {             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error, 'Bad id specified!'));            return null;          } }      public PageReference Edit()     {         PageReference errorPage = new PageReference('/apex/ContactInsert?id='+conId);         errorPage.setRedirect(true);         return errorPage;     }       public PageReference cloneButton()     {         // Record being cloned         Contact con = (Contact) standardController.getRecord();          // Custom clone logic         Contact clonedcon = new Contact();         clonedcon.FirstName = con.FirstName;         clonedcon.lastName = con.lastName;          clonedcon.mobilephone = con.mobilephone;         clonedcon.Accountid = con.Accountid;         clonedcon.otherphone = con.otherphone;         clonedcon.title = con.title;         clonedcon.fax = con.fax;         clonedcon.Department = con.Department;         clonedcon.Email = con.Email;         clonedcon.Birthdate = con.Birthdate;         clonedcon.AssistantName = con.AssistantName;          clonedcon.Reportstoid = con.Reportstoid;         clonedcon.Assistantphone = con.Assistantphone;         clonedcon.leadsource = con.leadsource;         clonedcon.OtherStreet= con.OtherStreet;         clonedcon.MailingCity = con.MailingCity;         clonedcon.othercity = con.othercity;         clonedcon.MailingState = con.MailingState;         clonedcon.otherstate = con.otherstate;         clonedcon.MailingPostalCode = con.MailingPostalCode;         clonedcon.otherpostalcode = con.otherpostalcode;         clonedcon.MailingCountry = con.MailingCountry;          clonedcon.othercountry = con.othercountry;         clonedcon.Languages__c = con.Languages__c;         clonedcon.Level__c = con.Level__c;         clonedcon.Description= con.Description;          insert clonedcon;         PageReference errorPage = new PageReference('/apex/ContactInsert?id='+conId);          errorPage.setRedirect(true);         return errorPage;           //return new PageReference('/' +clonedcon.id+ '/e' );         // Redirect to the new cloned record         //return new PageReference('/'+clonedcon.Id);         return null;     }  }   getting error     Id value 0012800000CyJVI is not valid for the Contact standard   controller   is there any way to check my Id is correct or not. and show error in VF page using apex:pagemessage
84342
I have a JFrame. This JFrame contains a JButton. I click the JButton and 10 JTextFields are created.  the problem: I cannot see them until "I force a repaint()" by resizing the window. Only then do I see the JTextFields created.  CODE:  JPanel points = new JPanel();  //Creating the JTextFields: for (int i=0; i&lt;10; i++) {     JTextField textField = new JTextField();     points.add(textField); }  repaint(); this.repaint(); super.repaint(); points.repaint();     THANK YOU - after the for loop, I just called points.validate() and it worked...
9792
Yesterday I had a two-hour technical phone interview (which I passed, woohoo!), but I completely muffed up the following question regarding dynamic binding in Java.  And it's doubly puzzling because I used to teach this concept to undergraduates when I was a TA a few years ago, so the prospect that I gave them misinformation is a little disturbing...  Here's the problem I was given:  /* What is the output of the following program? */  public class Test {    public boolean equals( Test other ) {     System.out.println( "Inside of Test.equals" );     return false;   }    public static void main( String [] args ) {     Object t1 = new Test();     Object t2 = new Test();     Test t3 = new Test();     Object o1 = new Object();      int count = 0;     System.out.println( count++ );// prints 0     t1.equals( t2 ) ;     System.out.println( count++ );// prints 1     t1.equals( t3 );     System.out.println( count++ );// prints 2     t3.equals( o1 );     System.out.println( count++ );// prints 3     t3.equals(t3);     System.out.println( count++ );// prints 4     t3.equals(t2);   } }   I asserted that the output should have been two separate print statements from within the overridden equals() method: at t1.equals(t3) and t3.equals(t3).  The latter case is obvious enough, and with the former case, even though t1 has a reference of type Object, it is instantiated as type Test, so dynamic binding should call the overridden form of the method.  Apparently not.  My interviewer encouraged me to run the program myself, and lo and behold, there was only a single output from the overridden method: at the line t3.equals(t3).  My question then is, why?  As I mentioned already, even though t1 is a reference of type Object (so static binding would invoke Object's equals() method), dynamic binding should take care of invoking the most specific version of the method based on the instantiated type of the reference.  What am I missing?
323
I'm having issues with creating a pretty simple test Utility Class. I want to create two records: an account and a related child contact. The error I see in the developer console is:     Variable does not exist: a.ID   My code, based on the Salesforce Apex Workbook, is as follows. I've played around with various things, but it's not working. Where am I going wrong? Thanks in advance.  @isTest public class AccountSaveTestSuite {      public static Account createOneAccount(){           Account testAccount = createAcct('ABC Computing inc.');              Contact testContact = createContact();          return testAccount;             }      // Helper methods //     //        private static Account createAcct(string accountName) {          Account a = new Account(             Name=accountName);         insert a;         return a;     }      private static Contact createContact(){         Contact c = new Contact (             FirstName = 'Jane'              , LastName = 'Smith'             , Account = a.ID); // *** Error is here ***         insert c;         return c;      }  }
54099
I'm using a JComboBox with an ItemListener on it. When the value is changed, the itemStateChanged event is called twice. The first call, the ItemEvent is showing the original item selected. On the second time, it is showing the item that has been just selected by the user. Here's some tester code:  public Tester(){      JComboBox box = new JComboBox();     box.addItem("One");     box.addItem("Two");     box.addItem("Three");     box.addItem("Four");      box.addItemListener(new ItemListener(){         public void itemStateChanged(ItemEvent e){             System.out.println(e.getItem());         }     });      JFrame frame = new JFrame();     frame.getContentPane().add(box);     frame.pack();     frame.setVisible(true); }   So when I changed the Combo box once from "One" to "Three" the console shows:  One Three   Is there a way I can tell using the ItemEvent maybe, that it's the second item (ie. the user selected item)? And if someone can explain why it gets called twice, that would be nice too!  Thanks
32675
I have a VF page that is the 'edit' page for a certain object. I have a button 'Clone'. Upon clicking this button, I wish to be redirected to a new edit page with all the previous objects fields still intact (except for a few that should be cleared and set to default). Note that this new object should not be inserted until I click 'Save'. The Id of the object should be different compared to the previous object, so that on Save, the previous object is not overwritten.   I am thinking I will split this up into two parts, an apex method, and a javascript method for resetting the fields:  &lt;apex:commandButton action="{!saveAsTemplate}" onclick="initTemplate();" value="Clone" /&gt;   The javascript portion is easy enough, but I'm having trouble of figuring out what to do on the apex side, besides for setting the id of the record to null.
29674
Why do we need an init() method in servlet? Can't we use the constructor to initialization?
1582
I have a &lt;lightning:recordViewForm in a custom lightning component.  When I hardcode the recordId attribute it works, but when I pass an attribute in it fails without any error messages in either the console or the debug log.  Component  &lt;aura:handler name="init" value="{!this}" action="{!c.doInit}" /&gt; &lt;aura:attribute name="recordId" type="Id"&gt;&lt;/aura:attribute&gt;  &lt;lightning:recordViewForm recordId="{! v.recordId }" objectApiName="MyCustomObject__c"&gt;      &lt;lightning:outputField fieldName="Name" /&gt;  &lt;/lightning:recordViewForm&gt;   JavaScript Controller  doInit : function(cmp, event, helper) {      // var recordId = helper.getQueryStringParameter('recordId');      cmp.set("v.recordId", "a0C4E000003YMkmUAG"); }   The above does not work, even if I put the recordId directly into the attribute.  It only works when I set the Id in the recordId attribute of the &lt;lightning:recordViewForm like below:  &lt;lightning:recordViewForm recordId="a0C4E000003YMkmUAG" objectApiName="MyCustomObject__c"&gt;      &lt;lightning:outputField fieldName="Name" /&gt;  &lt;/lightning:recordViewForm&gt;
89069
In the javadoc it says that EventListener is      "A tagging interface that all event listener interfaces must extend."   Why is that? What's the significance of making a custom listener implement EventListner? Is there any special handling for EventListner somewhere?
65745
I have created an Apex InterfaceFactory that the user can use to get an instance of a specified implementation of an interface. For this I use the System.Type class. The actual name of the class can be set in a custom setting. I wanted to be able to pass some parameters to the constructor of the dynamically instantiated class. In short; this is the code I'm talking about:  public static MyInterface GetMyInterfaceImplementationByClassName(String settingName){     String implementationClassName;     Type t;     MyInterface implementation = null;      //get the actual class name from the custom setting     Interface_Implementations__c settings = Interface_Implementations__c.getInstance(settingName);      //just make sure there actually is a className found     if (settings != null &amp;&amp; settings.Class__c != null) {         implementationClassName = settings.Class__c;         //get the type object for the class name retrieved from the custom setting         t = Type.forName(implementationClassName);         //this line is where my question comes in; how can I pass parameters here         implementation = (MyInterface)t.newInstance();     }      return implementation; }
108855
I am using lightning:recordEditForm and lightning:inputField for creating a new record. this component is being used inside a lightning community builder. When i click the submit button, i am able to create a new record in my custom object. However i need the created record ID as i need to pass it in the URL for the next page.
105844
In a lightning component I display a list of articles (Article__c custom object) so I ca see, for example, the name of the article, the price, and a button that I'd like redirect to another component which display the details of the article selected.   For now I'm just trying to get the id of the article, in a basic alert in javascript, but I doesn't work : it says the id is null.   Here is a part of the component :  &lt;aura:handler name="init" value="{!this}" action="{!c.doInit}" /&gt; &lt;aura:attribute name="wrappers" type="ListeArticlesWrapper" /&gt; &lt;aura:attribute name="articles" type="Article__c" /&gt;  &lt;aura:attribute name="Detail" type="String"/&gt; &lt;aura:registerEvent name="navigate" type="c:NavigateToDetail"/&gt;  &lt;div class="page"&gt;     &lt;h1&gt;Liste des articles&lt;/h1&gt;     &lt;div class="slds"&gt;         &lt;table class="slds-table slds-table--bordered slds-table--cell-buffer"&gt;             &lt;thead&gt;                 &lt;tr class="slds-text-heading--label"&gt;                     &lt;th scope="col" class="head"&gt;&lt;/th&gt;                     &lt;th scope="col" class="head"&gt;Nom&lt;/th&gt;                     &lt;th scope="col" class="head"&gt;Type&lt;/th&gt;                     &lt;th scope="col" class="head"&gt;Prix&lt;/th&gt;                     &lt;th scope="col" class="head"&gt;&lt;/th&gt;                 &lt;/tr&gt;             &lt;/thead&gt;             &lt;tbody&gt;                 &lt;aura:iteration items="{!v.wrappers}" var="wrap"&gt;                     &lt;tr&gt;                         &lt;td class="cell"&gt;                             &lt;ui:inputCheckbox value="{!wrap.selected}" /&gt;                         &lt;/td&gt;                         &lt;td class="cell"&gt;                            &lt;ui:outputText value="{!wrap.art.Name}" /&gt;                         &lt;/td&gt;                         &lt;td class="cell"&gt;                             &lt;ui:outputText value="{!wrap.art.Type__c}" /&gt;                         &lt;/td&gt;                         &lt;td class="cell"&gt;                             &lt;ui:outputText value="{!wrap.art.Prix__c}" /&gt;                         &lt;/td&gt;                         &lt;td class="cell"&gt;                             &lt;button class="slds-button slds-button--neutral slds-not-selected"                                      onclick="{!c.getDetail}" data="{!wrap.art.Id}"&gt;Details&lt;/button&gt;                         &lt;/td&gt;                     &lt;/tr&gt;                 &lt;/aura:iteration&gt;             &lt;/tbody&gt;         &lt;/table&gt;   The associated controller js (with the function getDetail)  ({ doInit : function(component, event, helper) {     helper.init(component, event); },  getArticles : function(component, event, helper) {     helper.getArticles(component, event); },  getDetail : function(component, event, helper){     var id = event.target.getAttribute("data-data") || event.target.parentNode.getAttribute("data-data")     alert('detail article : id = ' + id); //it gives me null } })   Thanks !  EDIT  And the wrapper class in case you wonder what is the "art" :  public with sharing class ListeArticlesWrapper { //wrapper pour récupérer les articles selectionnés @AuraEnabled public Article__c art {get; set;}  @AuraEnabled public Boolean selected {get; set;} }
90280
I am using LWCs to display lightning cards in a list.  The list shows information about Programs.  Each Program card has a button, and this button needs to take the user to the 'new object' screen of the Application object.  Here is my code:   applyToProgram(event) {     // The recordTypeId is coming from the .html     // I have verified that the value is correct.     var rtId = event.target.id;      // How do I use rtId below?     this[NavigationMixin.Navigate]({         type: 'standard__objectPage',         attributes: {             objectApiName: 'Application__c',             actionName: 'new',             nooverride: '1',             recordTypeId: rtId  // This does not work         }     }); }   This is not working.  The user is presented with the 'new object' screen for the object's default record type and NOT the one specified in rtId.  I tried putting 'nooverride' and 'recordTypeId' in the state:{} argument, and I also renamed 'recordTypeId' to just 'recordType'.  None of these worked.  Can anyone help me with the correct syntax?  Is this even possible in LWCs?  Thanks, Jeff
53255
In my spring application context file, I have something like:  &lt;util:map id="someMap" map-class="java.util.HashMap" key-type="java.lang.String" value-type="java.lang.String"&gt;     &lt;entry key="some_key" value="some value" /&gt;     &lt;entry key="some_key_2" value="some value" /&gt;    &lt;/util:map&gt;   In java class, the implementation looks like:  private Map&lt;String, String&gt; someMap = new HashMap&lt;String, String&gt;(); someMap = (HashMap&lt;String, String&gt;)getApplicationContext().getBean("someMap");   In Eclipse, I see a warning that says:  Type safety: Unchecked cast from Object to HashMap  What did I do wrong? How do I resolve the issue?