<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jayway Team Blog &#187; tricks</title>
	<atom:link href="http://blog.jayway.com/tag/tricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jayway.com</link>
	<description>Sharing Experience</description>
	<lastBuildDate>Sat, 11 Feb 2012 10:33:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Fixing WP7 app not starting after project rename</title>
		<link>http://blog.jayway.com/2011/10/12/fixing-wp7-app-not-starting-after-project-rename/</link>
		<comments>http://blog.jayway.com/2011/10/12/fixing-wp7-app-not-starting-after-project-rename/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 19:43:04 +0000</pubDate>
		<dc:creator>Andreas Hammar</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[windows phone]]></category>
		<category><![CDATA[windows phone 7]]></category>
		<category><![CDATA[wp7dev]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=10396</guid>
		<description><![CDATA[If your Windows Phone 7 project isn’t starting at all – you’re not even hitting App.xaml.cs, you’ve probably renamed the app project. Fix: Set the startup object on the app project’s properties page In the .csproj file, this corresponds to the SilverlightAppEntry element: &#60;SilverlightAppEntry&#62;PhotoDiary.App&#60;/SilverlightAppEntry&#62; I would call it a bug, that you cannot rename a [...]]]></description>
			<content:encoded><![CDATA[<p>If your Windows Phone 7 project isn’t starting at all – you’re not even hitting App.xaml.cs, you’ve probably renamed the app project.</p>
<p><strong>Fix</strong>: Set the <em>startup object</em> on the app project’s properties page</p>
<p><a href="http://blog.jayway.com/wordpress/wp-content/uploads/2011/10/startup_object.jpg" rel="lightbox"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="startup_object" border="0" alt="startup_object" src="http://blog.jayway.com/wordpress/wp-content/uploads/2011/10/startup_object_thumb.jpg" width="484" height="202" /></a></p>
<p>In the .csproj file, this corresponds to the <em>SilverlightAppEntry </em>element:</p>
<pre class="brush: xml; first-line: 1;">

&lt;SilverlightAppEntry&gt;PhotoDiary.App&lt;/SilverlightAppEntry&gt;

</pre>
<p>I would call it a bug, that you cannot rename a project and have the <em>SilverlightAppEntry</em> update accordingly. But luckily, the work-around is simple. </p>
<p>Have a nice day!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2011/10/12/fixing-wp7-app-not-starting-after-project-rename/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Sneaky throw</title>
		<link>http://blog.jayway.com/2010/01/29/sneaky-throw/</link>
		<comments>http://blog.jayway.com/2010/01/29/sneaky-throw/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 15:10:03 +0000</pubDate>
		<dc:creator>Jan Kronquist</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[jayview]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=4517</guid>
		<description><![CDATA[The latest issue of our magazine Jayview is out with brand new look and feel. My contribution was a cool piece of code that gets rid of those annoying exceptions. However, during layouting the link to the source disappeared. Credit should of course go to Reinier Zwitserloot and his mail on Java Posse. public class [...]]]></description>
			<content:encoded><![CDATA[<p>The latest issue of <a href="http://jayway.com/jayculture/jayview">our magazine Jayview</a> is out with brand new look and feel. My contribution was a cool piece of code that gets rid of those annoying exceptions. However, during layouting the link to the source disappeared. Credit should of course go to <a href="http://zwitserloot.com/">Reinier Zwitserloot</a> and <a href="http://www.mail-archive.com/javaposse@googlegroups.com/msg05984.html">his mail on Java Posse</a>. </p>
<pre class="brush:java">
public class Sneak {
    public static RuntimeException sneakyThrow(Throwable t) {
        if ( t == null ) throw new NullPointerException("t");
        Sneak.&lt;RuntimeException&gt;sneakyThrow0(t);
        return null;
    }

    @SuppressWarnings("unchecked")
    private static &lt;T extends Throwable&gt; void sneakyThrow0(Throwable t) throws T {
        throw (T)t;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2010/01/29/sneaky-throw/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Layout resources in Android</title>
		<link>http://blog.jayway.com/2009/03/26/layout-resources-in-android/</link>
		<comments>http://blog.jayway.com/2009/03/26/layout-resources-in-android/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 15:51:59 +0000</pubDate>
		<dc:creator>Mattias Rosberg</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Embedded]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=1382</guid>
		<description><![CDATA[One thing that often confuses developers new to the Android platform is the handling of layout resources. The xml files describing the layouts are magically transfered into a more efficient binary format behind the scenes and hidden away - leaving the developer with a static reference to the resources via the R.java file. By using [...]]]></description>
			<content:encoded><![CDATA[<p>One thing that often confuses developers new to the Android platform is the handling of layout resources. The xml files describing the layouts are magically transfered into a more efficient binary format behind the scenes and hidden away - leaving the developer with a static reference to the resources via the R.java file.</p>
<p>By using the<code> setContentView(int layoutResId)</code> method of the <code>Activity</code> class your layout will be displayed on the screen. Behind the scenes the Android platform is creating all the view objects contained in your layout xml file provided to the <code>setContentView(int layoutResId)</code> method. This process of creating view objects out of layout resources is referred to as layout inflation.</p>
<p>So far so good. This means that before the <code>setContentView(int layoutResId)</code> method is called the <code>findViewById(int resId)</code> method will return null for any view references in the layout, causing some potential <code>NullpointerExceptions</code>. </p>
<pre class="java">@Override
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> onCreate<span style="color: #66cc66;">&#40;</span>Bundle savedInstanceState<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006600;">onCreate</span><span style="color: #66cc66;">&#40;</span>savedInstanceState<span style="color: #66cc66;">&#41;</span>;
&nbsp;
   EditText addressField = <span style="color: #66cc66;">&#40;</span>EditText<span style="color: #66cc66;">&#41;</span> findViewById<span style="color: #66cc66;">&#40;</span>R.<span style="color: #006600;">id</span>.<span style="color: #006600;">address</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//To early!! Will return null</span>
   setContentView<span style="color: #66cc66;">&#40;</span>R.<span style="color: #006600;">layout</span>.<span style="color: #006600;">main</span><span style="color: #66cc66;">&#41;</span>;
   <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AButton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Button</span></a> button = <span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AButton+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Button</span></a><span style="color: #66cc66;">&#41;</span> findViewById<span style="color: #66cc66;">&#40;</span>R.<span style="color: #006600;">id</span>.<span style="color: #006600;">launchMap</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
   addressField.<span style="color: #006600;">setText</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Some Text&quot;</span><span style="color: #66cc66;">&#41;</span>;	<span style="color: #808080; font-style: italic;">//NullPointerException</span>
   button.<span style="color: #006600;">setText</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Some other text&quot;</span><span style="color: #66cc66;">&#41;</span>;	<span style="color: #808080; font-style: italic;">//No problem</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>To avoid these errors it's a good habit to place the <code>setContentView(int layoutResId)</code> method call at the very top of the <code>onCreate()</code> method.</p>
<p>In some cases you will have to do the layout inflation by yourself, i.e. when you want to set a custom view to a <code>Dialog</code> or a <code>Toast</code>. To inflate a view you use the <code>LayoutInflater</code> class. There's a number of different ways to get a handle to a <code>LayoutInflater</code>:</p>
<pre class="java">LayoutInflater inflater = <span style="color: #66cc66;">&#40;</span>LayoutInflater<span style="color: #66cc66;">&#41;</span>context.<span style="color: #006600;">getSystemService</span><span style="color: #66cc66;">&#40;</span>
      <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AContext+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Context</span></a>.<span style="color: #006600;">LAYOUT_INFLATER_SERVICE</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
LayoutInflater inflater = LayoutInflater.<span style="color: #006600;">from</span><span style="color: #66cc66;">&#40;</span>context<span style="color: #66cc66;">&#41;</span>;</pre>
<p>To actually create the view object you use the inflate() method of the LayoutInflater. In the most straightforward form this method has the signature:</p>
<pre class="java"><span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AView+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">View</span></a>  inflate<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> resource, ViewGroup root<span style="color: #66cc66;">&#41;</span></pre>
<p>Note that the resource is referring to a layout xml file resource, NOT the id of the view object that you want to inflate. First inflate the layout resource and then get a handle to the view object by using the <code>findViewById(int resId)</code> method.</p>
<p>The second attribute allows you to specify a <code>ViewGroup</code> object to be the root view of the inflated object(s) specified by your layout xml file. This means that the inflated view object(s) are attached as child views on the specified root <code>ViewGroup</code> object. Setting this value to null will simply return the inflated view object(s) without attaching them to a root view. </p>
<pre class="java">EditText fooField = <span style="color: #66cc66;">&#40;</span>EditText<span style="color: #66cc66;">&#41;</span> findViewById<span style="color: #66cc66;">&#40;</span>R.<span style="color: #006600;">id</span>.<span style="color: #006600;">foo</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//To early!! Will return null</span>
LinearLayout myRoot = <span style="color: #000000; font-weight: bold;">new</span> LinearLayout<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AView+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">View</span></a> itemView = inflater.<span style="color: #006600;">inflate</span><span style="color: #66cc66;">&#40;</span>R.<span style="color: #006600;">layout</span>.<span style="color: #006600;">layout_details</span>, myRoot<span style="color: #66cc66;">&#41;</span>;  <span style="color: #808080; font-style: italic;">//from layout_details.xml</span>
EditText barField = <span style="color: #66cc66;">&#40;</span>EditText<span style="color: #66cc66;">&#41;</span> findViewById<span style="color: #66cc66;">&#40;</span>R.<span style="color: #006600;">id</span>.<span style="color: #006600;">bar</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//Now we have an object</span></pre>
<p>In this example the inflate method returns the mRoot object with the view objects contained in the layout_details.xml file attached as child views. So itemView and myRoot is actually referring to the same physical object. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2009/03/26/layout-resources-in-android/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

