Need help with my Java Android code
-
public static Intent getIntentForHome(Activity paramActivity, int paramInt) { if ((paramActivity == null) || (paramInt == -1)); Intent localIntent1; for (Object localObject = null; ; localObject = localIntent1) { ** return localObject;** localIntent1 = new Intent(paramActivity, HomesMapActivity.class); Intent localIntent2 = localIntent1.setAction("android.intent.action.VIEW"); Intent localIntent3 = localIntent1.putExtra("android.intent.extra.TEXT", paramInt); } }
the above method return the following error or warning: the error is on "return localObject;" Multiple markers at this line - Type mismatch: cannot convert from Object to Intent - Type mismatch: cannot convert from Object to Intent
-
public static Intent getIntentForHome(Activity paramActivity, int paramInt) { if ((paramActivity == null) || (paramInt == -1)); Intent localIntent1; for (Object localObject = null; ; localObject = localIntent1) { ** return localObject;** localIntent1 = new Intent(paramActivity, HomesMapActivity.class); Intent localIntent2 = localIntent1.setAction("android.intent.action.VIEW"); Intent localIntent3 = localIntent1.putExtra("android.intent.extra.TEXT", paramInt); } }
the above method return the following error or warning: the error is on "return localObject;" Multiple markers at this line - Type mismatch: cannot convert from Object to Intent - Type mismatch: cannot convert from Object to Intent
When I reviewed your code, I found the following things. I used line numbers for reference. 3: You close your if with a ; this will render your if useless. Change it to using curly braces. 5: You use a for loop with no clear start condition, end condition. 7: The first line of the for loop returns localObject which is of type Object and is null, this is where your error comes from. You return an Object but the signature of the Method says you will return an Intent. 9, 10, 11: Lines are useless as there is no way for the program to get to this code. Patrick Kalkman My latest article: Digest Authentication on WCF My Blog: SemanticArchitecture.net
modified on Thursday, April 21, 2011 3:56 PM
-
public static Intent getIntentForHome(Activity paramActivity, int paramInt) { if ((paramActivity == null) || (paramInt == -1)); Intent localIntent1; for (Object localObject = null; ; localObject = localIntent1) { ** return localObject;** localIntent1 = new Intent(paramActivity, HomesMapActivity.class); Intent localIntent2 = localIntent1.setAction("android.intent.action.VIEW"); Intent localIntent3 = localIntent1.putExtra("android.intent.extra.TEXT", paramInt); } }
the above method return the following error or warning: the error is on "return localObject;" Multiple markers at this line - Type mismatch: cannot convert from Object to Intent - Type mismatch: cannot convert from Object to Intent
I agree with Patrick. In the end of if statement replace ";" with "{" Your for loop, initialize localObject of type Object = null, NO END condition and assign localObject = localIntent Their is no meaning for this loop as you are returning on first run, you can remove the for loop and work normally. Yet with your problem, replace return statement after Intent localIntent3... and typecast it : return (Intent)localObject; This will free you from the error and if you code is proper, then will receive proper results. Hope this helps. Thanks & Regards,