Permalink
Browse files

Prevent a potential NPE

  • Loading branch information...
pilhuhn committed Jun 25, 2012
1 parent 51edf15 commit b68277c154d1f5b5c3f3ada3566cf94cbe0add38
Showing with 11 additions and 9 deletions.
  1. +2 −3 AndroidManifest.xml
  2. +9 −6 src/org/rhq/pocket/resource/ResourceActivity.java
View
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.rhq.pocket"
- android:versionCode="1"
- android:versionName="1.0"
+ android:versionCode="2"
+ android:versionName="0.2"
android:installLocation="preferExternal"
>
@@ -12,7 +12,6 @@
<supports-screens android:largeScreens="true"/>
<supports-screens android:xlargeScreens="true"/>
-
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
@@ -154,6 +154,12 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent;
+
+ if (item.getItemId()==R.id.pick_resource) {
+ pickResource();
+ return true;
+ }
+
switch (item.getItemId()) {
case R.id.list_alerts:
intent = new Intent(this, AlertActivity.class);
@@ -181,19 +187,16 @@ public boolean onOptionsItemSelected(MenuItem item) {
startActivity(intent);
return true;
case R.id.add_to_favorites:
- addToFavorites(resource.getResourceId());
- return true;
- case R.id.pick_resource:
- pickResource();
+ addToFavorites(resource);
return true;
}
return super.onOptionsItemSelected(item);
}
- private void addToFavorites(int resourceId) {
- if (resourceId==-1) {
+ private void addToFavorites(ResourceWithType resource) {
+ if (resource==null || resource.getResourceId()==-1) {
Toast.makeText(this, "Select a resource first", Toast.LENGTH_SHORT).show();
return;
}

0 comments on commit b68277c

Please sign in to comment.