Having Big Problems With Android Project

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. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        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() {

			@Override
			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) {
					restaurantName.setText("");
					restaurantName.setFocusable(true);
					restaurantAddress.setText("");
					restaurantType.clearCheck();
				}
				// 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";
					else 
						deliveryType = "Delivery";
					
					String restaurantInfo = restName + " - " + restAddr + " - " + deliveryType;
					//restaurantArray.add(restaurantInfo);
					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.

Thanks,
AppDevRookie
LVL 1
InquisitiveProgrammerAsked:
Who is Participating?
 
themrrobertCommented:
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
0
 
themrrobertCommented:
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)

http://www.groupsrv.com/computers/about618983.html

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.
0
 
InquisitiveProgrammerAuthor Commented:
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.
0
 
Peter KwanAnalyst ProgrammerCommented:
I think the logic for the if clause should be:

if ("".equals(restName) || "".equals(restAddr) || foodDeliveryType == -1) {
0
 
InquisitiveProgrammerAuthor Commented:
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) 
					clearFields();
				else {
					// Determine which radio group button has been selected.
					if (takeOut.isChecked())
						deliveryType = "Take-Out";
					else if (sitDown.isChecked())
						deliveryType = "Sit-Down";
					else 
						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.
0
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.

All Courses

From novice to tech pro — start learning today.