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.app.Activity;
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(R.id.restaurants);
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        final EditText restaurantName = (EditText) findViewById(R.id.name);
    	final EditText restaurantAddress = (EditText) findViewById(R.id.addr);
    	final RadioGroup restaurantType = (RadioGroup) findViewById(R.id.types);
    	final Button saveRestaurantInfo = (Button) findViewById(R.id.save);
        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, R.id.restaurants, 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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
Today, unlike web development, the mobile landscape is complex enough for a software engineer and Android is posing more challenging environment thanks to its fragmentation issues on hardware and software fronts.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …

569 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