Click Event     public void buttonOnClick(View v) { Button button=(Button) v; ((Button) v).setText("clicked");   Changes BackGround to an image  RelativeLayout rl = (RelativeLayout) findViewById(R.id.BackGround); rl.setBackgroundResource(R.drawable.mapwork);   Makes Certain Items Disapear  button.setVisibility(View.INVISIBLE); EditText mText2 = (EditText) findViewById(R.id.input); mText2.setVisibility(View.INVISIBLE);   Changes what is in the output if they put in a certain number  EditText mText = (EditText) findViewById(R.id.output); if("8" == mText.getText().toString()){     mText.setText("That does not work!"); } }   When I test the application the If statement never happens even when the requirements are met. I have tried look for an answer and have not found one. Thank you for helping.
93
I've been using the == operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug.  Is == bad? When should it and should it not be used? What's the difference?
66264
In visualforce page I have a custom picklist with the values "Show" and "Hide" and two command buttons(Button A &amp; Button B). When the picklist value is "Show", Button B needs to be displayed and when it's "Hide" then Button B needs to be hidden.  For that I have tried below code  Visualforce page :  &lt;apex:page showHeader="false" controller="picklistRenderController"&gt; &lt;apex:form &gt;     &lt;apex:pageBlock &gt;         &lt;apex:selectList value="{!selectId}" size="1"&gt;             &lt;apex:selectOptions value="{!display}"&gt;&lt;/apex:selectOptions&gt;             &lt;apex:actionSupport event="onchange" action="{!displayButton}" reRender="d"/&gt;         &lt;/apex:selectList&gt;         &lt;apex:pageBlockButtons location="bottom" id="d"&gt;             &lt;apex:commandButton action="{buttonA}" value="Button A"/&gt;             &lt;apex:commandButton action="{buttonB}" value="Button B" rendered="{!selectId=='show'}"/&gt;         &lt;/apex:pageBlockButtons&gt;      &lt;/apex:pageBlock&gt; &lt;/apex:form&gt; &lt;/apex:page&gt;   Controller is :  public class picklistRenderController {    public List&lt;selectoption&gt; display { get; set; }   public String selectId { get; set; }    public PageReference buttonB() {      return null;   }    public PageReference buttonA() {       return null;   }    public PageReference displayButton() {        return null;   }     public picklistRenderController()   {      display =new List&lt;selectoption&gt;();      display.add(new selectoption('none','-select-'));      display.add(new selectoption('show','show'));      display.add(new selectoption('hide','hide'));   } }   But I couldn't able to get this work. Please help me on this.
16290
This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through the resources here and use them to shape more specific questions. To browse all canonical questions and answers, navigate to the  tag. This question and answer is owned by the community! If you can improve it and make it more useful, you're welcome to edit it. I am building a trigger, a unit test, or other Apex code. I'm working with sObject records, and trying to access related record information. For example, I might have a structure like this: Account a = new Account(Name = 'Test'); insert a;  Opportunity o = new Opportunity(Name = 'Donation', AccountId = a.Id); insert o;  System.assertEquals(o.Account.Name, 'Test', 'Correct Account associated'); // Assertion fails!  Or, in a trigger, I might be aiming for something like this: trigger ContactTrigger on Contact (after insert) {     for (Contact c : Trigger.new) {         if (c.Account.Name == 'Test') {             // Take some action here         }      } }  Why doesn't this work? Why am I getting null values, or NullPointerExceptions?
38486
Okay, this should be super easy to do but I just can't find the way.  I have a background image with a solid colour layer on top of it, and I would like to add text on top of everything in such a way that the filling of the text is the image in the background. I have tried selecting the text shape and deleting that selection shape in the solid colour layer, but it just looks wrong.   Can anyone help me with this? Many thanks in advance.
45516
For some reason the layer selection and the Lock to Scene button disappeared in 3D View / Object Mode. I can't find an option to toggle the visibility.  As it is supposed to look like   How it currently looks like    File / New restores the visibility therefore it must be a setting within the .blend file. How can the layer selection be restored?
73978
I'm trying to work on the materials for my scene without touching the rest of the scene for now. When I try to switch between scenes by clicking the outlined thing, it automatically applies the selected material to the active object. Is this the wrong button? Should I be clicking something else in order to edit the material properties without applying it to my objects?   Thanks for the help in advance.
71023
I know it is so weird, but last night I set an image on my desktop background and delete the image, then I right-click on the desktop and press the desktop properties to change the style of background (center, stretch and etc) then the desktop properties stopped something like hanging on Windows.   Then a black window alerted something and I press yes without reading it. after that with right-click on the desktop I just see this:    Even some system applications don't work now. for example, I cannot take a screenshot.  Also, my pcmanfm-qt is dead completely, with the command line or clicking on the icon nothing happens.  I don't know what happens. and I have no idea how to fix it.
24218
Is this functionality going to be put into a later Java version?  Can someone explain why I can't do this, as in, the technical way Java's switch statement works?
18683
Frequently when I ask a question I have to include quite a bit of code for reference purposes.    It would be nice to be able to bold the important lines in the code.  For example this code:  &lt;DataTrigger Value="True"&gt;     &lt;DataTrigger.Binding&gt;         &lt;MultiBinding Converter="{StaticResource DisableWorkItemConverter}"&gt;             &lt;Binding ElementName="MainForm" Path="PickedWorkItemID"/&gt;             &lt;Binding Path="Id"/&gt;         &lt;/MultiBinding&gt;     &lt;/DataTrigger.Binding&gt;     &lt;Setter Property="IsEnabled" Value="False"/&gt;     &lt;Setter Property="IsSelected" Value="False"/&gt; &lt;/DataTrigger&gt;   Is not way long, but the important part (as seen in ) is the second to last line.  However, if I try to bold it, it ends up looking like this:  &lt;DataTrigger Value="True"&gt;     &lt;DataTrigger.Binding&gt;         &lt;MultiBinding Converter="{StaticResource DisableWorkItemConverter}"&gt;             &lt;Binding ElementName="MainForm" Path="PickedWorkItemID"/&gt;             &lt;Binding Path="Id"/&gt;         &lt;/MultiBinding&gt;     &lt;/DataTrigger.Binding&gt;     &lt;Setter Property="IsEnabled" Value="False"/&gt;     **&lt;Setter Property="IsSelected" Value="False"/&gt;** &lt;/DataTrigger&gt;   Not what I was going for.  It would be nice to be able to draw attention to specific lines of code when needed.    (One suggestion of a different color background sounds nice too (ie a yellow background to draw the eye to the relevant code.)  If there is some other way to bold in code please let me know.
1905
I ran into an interesting (and very frustrating) issue with the equals() method today which caused what I thought to be a well tested class to crash and cause a bug that took me a very long time to track down.   Just for completeness, I wasn't using an IDE or debugger - just good old fashioned text editor and System.out's. Time was very limited and it was a school project.  Anyhow -   I was developing a basic shopping cart which could contain an ArrayList of Book objects. In order to implement the addBook(), removeBook(), and hasBook() methods of the Cart, I wanted to check if the Book already existed in the Cart. So off I go -  public boolean equals(Book b) {     ... // More code here - null checks     if (b.getID() == this.getID()) return true;     else return false; }   All works fine in testing. I create 6 objects and fill them with data. Do many adds, removes, has() operations on the Cart and everything works fine. I read that you can either have equals(TYPE var) or equals(Object o) { (CAST) var } but assumed that since it was working, it didn't matter too much.  Then I ran into a problem - I needed to create a Book object with only the ID in it from within the Book class. No other data would be entered into it. Basically the following:  public boolean hasBook(int i) {     Book b = new Book(i);     return hasBook(b); }  public boolean hasBook(Book b) {     // .. more code here     return this.books.contains(b); }   All of a sudden, the equals(Book b) method no longer works. This took a VERY long time to track down without a good debugger and assuming the Cart class was properly tested and correct. After swaapping the equals() method to the following:  public boolean equals(Object o) {     Book b = (Book) o;     ... // The rest goes here    }   Everything began to work again. Is there a reason the method decided not to take the Book parameter even though it clearly  was  a Book object? The only difference seemed to be it was instantiated from within the same class, and only filled with one data member. I'm very very confused. Please, shed some light?
104989
I'm trying to hide an inputfield on visualforce page based on some condition. So, i started with below code, but unable to hide the inputfield on page load itself.  Both the alert messages displayed before and after the js code are executing well. but, the component is not hiding from the page(able to grey it out successfully with the below code, but not hiding it). Could not use rerender functionality, as my section contains rich text area., and rerender is not working for components containing rich text area.  My code below:      &lt;apex:page id="pageid" standardcontroller="account"&gt;   &lt;apex:form id="formid"&gt;       &lt;apex:pageblock id="pbid"&gt;           &lt;apex:pageblocksection id="pbsid"&gt;               &lt;apex:inputfield id="phoneid" value="{!account.phone}"/&gt;           &lt;/apex:pageblocksection&gt;       &lt;/apex:pageblock&gt;   &lt;/apex:form&gt;    &lt;script&gt;      alert('d2 opens now');      try{          document.getElementById("pageid:formid:pbid:pbsid:phoneid").visible=false;          }catch(e){          alert(e)          }          alert('d2 opens now1');   &lt;/script&gt; &lt;/apex:page&gt;   Thanks in advance, Friend!!!
50897
I am writing a chess game using Java and Swing, And I wanted to get the tile position on which a mouse clicked. I searched through internet, but all of them were really off, and never accurate. When I clicked on a tile's first half, it said it was tile 1, but on the second half, it said it was tile 2, but it was still tile 1. So I was wondering, how can I do it? My tile size is (75, 75) This is the code I've written for tileX: Math.floor((double)evt.getX() / 75), and this is the code I've written for tileY: Math.floor((double)evt.getY() / 75). Code for drawing: ImageIcon l_winter = new ImageIcon(&quot;/Users/user/NetBeansProjects/chess/src/b/bibe/assets/winter/light.gif&quot;);         ImageIcon d_winter = new ImageIcon(&quot;/Users/user/NetBeansProjects/chess/src/b/bibe/assets/winter/dark.gif&quot;);         ImageIcon l_wood = new ImageIcon(&quot;/Users/user/NetBeansProjects/chess/src/b/bibe/assets/wood/light.png&quot;);         ImageIcon d_wood = new ImageIcon(&quot;/Users/user/NetBeansProjects/chess/src/b/bibe/assets/wood/dark.png&quot;);         String theme = th;         int color = 0;         for (int i = 0; i &lt; 600; i = i + 75) {             for (int j = 0; j &lt; 600; j = j + 75) {                 JLabel panel = new JLabel();                 panel.setText(null);                 panel.setSize(75, 75);                 if (color == 0) {                     if (theme.equals(&quot;wood&quot;)) {                         panel.setIcon(l_wood);                     } else if (theme.equals(&quot;winter&quot;)) {                         panel.setIcon(l_winter);                     } else {                         panel.setText(&quot;notexture&quot;);                     }                     //panel.setBackground(new Color(white[0], white[1], white[2]));                     color = 1;                 } else {                     if (theme.equals(&quot;wood&quot;)) {                         panel.setIcon(d_wood);                     } else if (theme.equals(&quot;winter&quot;)) {                         panel.setIcon(d_winter);                     } else {                         panel.setText(&quot;notexture&quot;);                     }                     //panel.setBackground(new Color(black[0], black[1], black[2]));                     color = 0;                 }                 panel.setLocation(j, i);                 getContentPane().add(panel);             }         if (color == 0) {             color = 1;         } else {                color = 0;             }         }
114969
If I scroll from an answer back to the question the questions text isn't visible any more:    After scrolling it again the text appears partially:    Sometimes the answer will appear with a very small font:    Source code doesn't appear in full width neither:    and when I scroll, the grey background covers the source code completely:    This makes the app totally unusable.  Galaxy S2, Android 4.0.3. App version 1.0.51
63280
When I vote using the Android app, the button highlights briefly in orange as expected and then returns to the normal black (so both vote buttons are the same color). I expected the highlighting to remain in place to show my vote.  The post score reflects my vote, and if I tap the vote button again it cancels my vote (and updates the score again).  So my vote is there; it's just not shown.  If I vote, navigate back to the list of questions, and then return to the page where I voted, my vote shows in orange and is persistent. Votes I've previously cast show up and are persistent on first view; it's only new ones that behave like this.  By its nature, it's hard to take a meaningful screenshot.  I don't use the app a lot, so I don't know how new this is. My phone says I'm up to date (1.0.77).
8502
I'm working on a simple 2D game. I've finished the mobile phone version.  However, my boss wants the game to works on his RT. I'm doing the "conversion" but my buttons are in the wrong places, because I hard-coded the screen size, like this:   texture = game.Content.Load&lt;Texture2D&gt;("StartScreen");  mainFrame = new Rectangle(0, 0, game.GraphicsDevice.Viewport.Width, game.GraphicsDevice.Viewport.Height);   // button definitions  startbrect = new Rectangle(300, 258, 88, 88);  startbtext = game.Content.Load&lt;Texture2D&gt;("bplay");   In this example, mainframe is fine, but startbrect isn't, because I defined the size to match a Windows phone's screen. How can I handle responsive design when all Windows 8 phones' screens are different? Is there a formula or macro to calculate each time the good size?
115316
I was toggling between layout views (Default, Animation, etc) and I accidentally got this:    I don't know how to simply restore the "Default" layout... or any layout. Many of the interface elements are gone and I was able to bring back some by clicking "maximize area" in one of the tool bars  So, anyone knows a way of restoring the default layout without using the layout button? thanks in advance!  (I've tried searching and apparently no-one had this problem before...)
83460
I have a page where a few textboxes cannot be empty before clicking a Save button.    &lt;TextBox...                  &lt;TextBox.Text&gt;                     &lt;Binding Path ="LastName" UpdateSourceTrigger="PropertyChanged"&gt;                          &lt;Binding.ValidationRules&gt;                             &lt;local:StringRequiredValidationRule /&gt;                         &lt;/Binding.ValidationRules&gt;                                                   &lt;/Binding&gt;                 &lt;/TextBox.Text&gt;   My rule works, I have a red border around my textbox until I enter a value.  I now want to add this validation rule to my other text boxes.  How do I disable the Save button until the page has no validation errors?  I'm not sure what to check.