Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Having Big Problems With Android Project

Posted on 2011-09-24
Medium Priority
Last Modified: 2012-06-22
This is my first Android project, and I'm having quite a bit of difficulty with it. First I will attach the code, then ask my questions:

package com.jaylefler.restaurants;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
import android.util.Log;

public class RestaurantList extends Activity {

	//private ArrayAdapter<String> dataAdapter;
	//final ArrayList<String> restaurantArray = new ArrayList<String>();
	//ListView myList = (ListView) findViewById(;
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        final EditText restaurantName = (EditText) findViewById(;
    	final EditText restaurantAddress = (EditText) findViewById(;
    	final RadioGroup restaurantType = (RadioGroup) findViewById(;
    	final Button saveRestaurantInfo = (Button) findViewById(;
        saveRestaurantInfo.setOnClickListener(new Button.OnClickListener() {

			public void onClick(View v) {
				String restName = restaurantName.getText().toString();
				String restAddr = restaurantAddress.getText().toString();
				String deliveryType = "";
				int foodDeliveryType = restaurantType.getCheckedRadioButtonId();
				// If text fields are blank or radio button isn't selected clear all fields. 
				if (restName == "" || restAddr == "" || foodDeliveryType == -1) {
				// Determine which radio group button has been selected based on the id. 
				else {
					if (foodDeliveryType == 0)
						deliveryType = "Take-Out";
					else if (foodDeliveryType == 1)
						deliveryType = "Sit-Down";
						deliveryType = "Delivery";
					String restaurantInfo = restName + " - " + restAddr + " - " + deliveryType;
					Log.d("JAY", "Restaurant Info reads: " + restaurantInfo + ".");
        //dataAdapter = new ArrayAdapter<String>(this,, restaurantArray);
       // myList.setAdapter(dataAdapter);

Open in new window

My first problem is, in my "if (restName == "" || ...." condition, for some reason the program is always performing this condition, even when restName and restAddr aren't blank).

Also, during the debugger phase, on the "restaurantName.setFocusable(true);" line I get a Class File Editor - Source not found error. I have no idea what this means.

I have more then just these problems, but they are keeping me from going further with this project.

Question by:InquisitiveProgrammer
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 13

Expert Comment

ID: 36594232
Well your first answer is most likely because you are doing 3 OR comparissons, so if any are true, the code will execute.

If either is blank, OR if foodDeliveryType == -1 then the code runs, so my guess is that one of those is true, the only logical answer.

Check the values of all 3 with the debugger or output each into the log before (and maybe after) running the if check to verify this.

As far as the second error, i've encountered it myself and it's usually due to a configuration error. Only experimenting and becoming very familiar with the plethora of options available to android developers will give you the knowledge needed to figure this out on your quickly, but here are a few sources which could point you in the right direction: (ie, many causes)

Try cleaning/updating the project (under "Android Tools")

Also, ensure that all of the source files have no X icon, and be sure your includes are complete, but most likely its a linking /config error.

Author Comment

ID: 36594247
I have checked the properties while the debugger was running and when none of the conditions were met, the code still ran.

As for the link you provided, that was dated 2009 and the "help" provided was outdated.
LVL 16

Expert Comment

by:Peter Kwan
ID: 36594250
I think the logic for the if clause should be:

if ("".equals(restName) || "".equals(restAddr) || foodDeliveryType == -1) {
LVL 13

Accepted Solution

themrrobert earned 2000 total points
ID: 36596093
pk's logic  should work, the java-like framework should let his code work.

However the issue you are facing with the code is the same issue that has existed with eclipse and android sdk since 2009. There isn't one magic solution to make it work.

Even if you posted your entire code in a zip file, I could try to get it to work, and i may or may not have any trouble getting it to work, and if i do encounter your issue, my fix may not be the same fix for you.

if you want to upload your project I am sure i can trace the cause of your #2 issue and get it working on my end, but unless i'm actually working on the project i can only point you in the direction of places to look.

Best of luck :) hope you get it solved, the information is out there, you shouldn't be stuck for long

Author Comment

ID: 36601456
Well, I'm not sure what I did, but I reinstalled Eclipse and the Android SDK and then imported the project and it was working fine.

In order to give points to someone, I hope that someone can answer this question:

I have a RadioGroup called restaurantType that has three buttons inside of it.

I know I can use restaurant.getCheckedRadioButtonId() in order to see if the radio buttons are checked

int foodDeliveryType = restaurantType.getCheckedRadioButtonId();
				// If any user requested info is missing, clear fields. 
				if (restName.isEmpty() || restAddr.isEmpty() || foodDeliveryType == -1) 
				else {
					// Determine which radio group button has been selected.
					if (takeOut.isChecked())
						deliveryType = "Take-Out";
					else if (sitDown.isChecked())
						deliveryType = "Sit-Down";
						deliveryType = "Delivery"; // only other available option

Open in new window

I want to know if I can reference the text fields of the radio buttons without having to reference the buttons themselves. takeOut and sitDown are references to two of the Buttons in the RadioGroup.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about a problem I had getting the GPS LocationListener working.
The case of the missing phone talks about the way a small electronic gadget (the mobile phone) has penetrated into our lives and has made us addicted to it.
This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to:…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question