• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps App crashes from start- didn't used to happen

cr5315

Android Enthusiast
I was working on my app and I added a dialog box that would start a phone call if the user chose to start a call. I finished it and decided to test it on my phone. It installed and right away I got the message saying that the app had stopped responding. I took the new code out and it still wouldn't boot. I'll post my code below.
I'm not sure what the problem is, it was working fine before I added the code, but now it won't start. I'll try it with the emulator soon.
 
Here's the code.

crossingActivity.java
Code:
package com.bba.crossing;



import android.app.Activity;
import android.app.AlertDialog;

import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;


public class crossingActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
    
    Button sermonButton = (Button) findViewById(R.id.Button01);
    sermonButton.setOnClickListener(new View.OnClickListener(){
    	public void onClick(View v) {
    		Uri uri = Uri.parse("http://www.thecrossing.net/sermonpopup.shtml");
    	    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    	    startActivity(intent);
    	}
    	});
    {
}

    Button imageButton = (Button) findViewById(R.id.ImageButton01);
    imageButton.setOnClickListener(new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			Uri uri = Uri.parse("http://thecrossing.net/index.html");
			Intent intent = new Intent(Intent.ACTION_VIEW, uri);
			startActivity(intent);
		}
	});
   
    Button quincyButton = (Button) findViewById(R.id.Button02);
    quincyButton.setOnClickListener(new View.OnClickListener(){
    	public void onClick(View v) {
    		Uri uri = Uri.parse("http://www.thecrossing.net/quincy.shtml");
    		Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    		startActivity(intent);
	}
	});{}
	Button macombButton = (Button) findViewById(R.id.Button03);
	macombButton.setOnClickListener(new View.OnClickListener(){
		public void onClick(View v) {
			Uri uri = Uri.parse("http://www.thecrossing.net/macomb.shtml");
			Intent intent = new Intent(Intent.ACTION_VIEW, uri);
			startActivity(intent);
	}
	});{}
	Button kirkButton = (Button) findViewById(R.id.Button04);
	kirkButton.setOnClickListener(new View.OnClickListener(){
		public void onClick(View v) {
			Uri uri = Uri.parse("http://www.thecrossing.net/kirksville.shtml");
		    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		    startActivity(intent);
		}
	});{}
	Button nineButton = (Button) findViewById(R.id.Button05);
	nineButton.setOnClickListener(new View.OnClickListener(){
		public void onClick(View v) {
			Uri uri = Uri.parse("http://www.thecrossing.net/929.shtml");
		    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		    startActivity(intent);
		}
	});{}
	Button contactButton = (Button) findViewById(R.id.Button07);
	contactButton.setOnClickListener(new View.OnClickListener(){
		public void onClick(View v) {
			final CharSequence[] ChurchCampus = {"Quincy", "Macomb", "Kirksville", "929"};

	        AlertDialog.Builder ab=new AlertDialog.Builder(crossingActivity.this);
			ab.setTitle("Which campus?");
			ab.setSingleChoiceItems(ChurchCampus, -1, new DialogInterface.OnClickListener() {
	            public void onClick(DialogInterface dialog, int whichButton) {
	            }
	        })
	        .setPositiveButton("Call", new DialogInterface.OnClickListener() {
	            public void onClick(DialogInterface dialog, int whichButton) {
	            	if (ChurchCampus.equals("Quincy")){
	            		try {
	            			   Intent callIntent = new Intent(Intent.ACTION_CALL);
	            			   callIntent.setData(Uri.parse("tel:+2172246374"));
	            			   startActivity(callIntent);
	            			} catch (Exception e) {
	            			   Log.e("CrossingApp", "Failed to start call", e);
	            			}
	            	} else if (ChurchCampus.equals("Macomb")){
	            		try {
	            			   Intent callIntent = new Intent(Intent.ACTION_CALL);
	            			   callIntent.setData(Uri.parse("tel:+3092785117"));
	            			   startActivity(callIntent);
	            			} catch (Exception e) {
	            			   Log.e("CrossingApp", "Failed to start call", e);
	            			}
	            	} else if (ChurchCampus.equals("Kirksville")){
	            		try {
	            			   Intent callIntent = new Intent(Intent.ACTION_CALL);
	            			   callIntent.setData(Uri.parse("tel:+6606656000"));
	            			   startActivity(callIntent);
	            			} catch (Exception e) {
	            			   Log.e("CrossingApp", "Failed to start call", e);
	            			}
	            	} else if (ChurchCampus.equals("929")){
	            		try {
	            			   Intent callIntent = new Intent(Intent.ACTION_CALL);
	            			   callIntent.setData(Uri.parse("tel:+2172140929"));
	            			   startActivity(callIntent);
	            			} catch (Exception e) {
	            			   Log.e("CrossingApp", "Failed to start call", e);
	            			}
	            	}
	        }})
	        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
	            public void onClick(DialogInterface dialog, int whichButton) {
	            	// on cancel button action
	            }
	        });
	        ab.show();
		}
	});
	Button aboutButton = (Button) findViewById(R.id.Button08);
	aboutButton.setOnClickListener(new View.OnClickListener(){
		public void onClick(View v) {
			// prepare the alert box
            AlertDialog.Builder alertbox = new AlertDialog.Builder(crossingActivity.this);
 
            // set the message to display
            alertbox.setMessage("The Crossing version 0.5 BETA");
 
       
            alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {     
                }
            });
 
            // show it
            alertbox.show();
		}
	});
		}
	;
    }

main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>





<ScrollView android:id="@+id/ScrollView01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"><LinearLayout android:orientation="vertical" android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent"><ImageButton android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/ImageButton01" android:background="@drawable/logo"></ImageButton>
<Button android:layout_height="wrap_content" android:text="@string/Button01" android:layout_width="fill_parent" android:id="@+id/Button01"></Button>
<Button android:layout_height="wrap_content" android:text="@string/Button02" android:layout_width="fill_parent" android:id="@+id/Button02"></Button>
<Button android:layout_height="wrap_content" android:text="@string/Button03" android:layout_width="fill_parent" android:clickable="true" android:id="@+id/Button03"></Button>
<Button android:layout_height="wrap_content" android:text="@string/Button04" android:layout_width="fill_parent" android:id="@+id/Button04"></Button>
<Button android:layout_height="wrap_content" android:text="@string/Button05" android:layout_width="fill_parent" android:id="@+id/Button05"></Button>
<Button android:layout_height="wrap_content" android:text="@string/Button08" android:layout_width="fill_parent" android:id="@+id/Button07"></Button>
<Button android:layout_height="wrap_content" android:text="@string/Button09" android:layout_width="fill_parent" android:id="@+id/Button08"></Button>
<Button android:layout_height="wrap_content" android:text="@string/button07" android:layout_width="fill_parent" android:id="@+id/Button06"></Button>
</LinearLayout>
</ScrollView>

strings.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">The Crossing</string>
    <string name="Button01">Current Sermon Series</string>
    <string name="Button02">Quincy Campus</string>
    <string name="Button03">Macomb Campus</string>
    <string name="Button04">Kirksville Campus</string>
    <string name="Button05">929</string>
    <string name="button07">Sunday Services: 9:00 AM and 10:45 AM</string>
    <string name="Button08">Contact</string>
    <string name="Button09">About</string>
</resources>

Crossing Manifest.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.bba.crossing"
      android:versionCode="1" android:versionName="0.5">
    <application android:label="@string/app_name" android:icon="@drawable/icon" android:debuggable="true">
        <activity android:name=".crossingActivity" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
<permission android:name="android.permission.PHONE_CALL"></permission>
</manifest>
 
I'm not sure if this is it, but you're shooting an intent that requires android.permission.INTERNET (anything that goes to a URL) I'd check there,

but I'm pretty sure this is the problem:
where you have
Code:
	});
    {
}

keep the });
but remove the two curly braces

EDIT: there was a bit more than that, try this file instead (edited yours)
Code:
public class crossingActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
    
    Button sermonButton = (Button) findViewById(R.id.Button01);
    sermonButton.setOnClickListener(new View.OnClickListener(){
    	public void onClick(View v) {
    		Uri uri = Uri.parse("http://www.thecrossing.net/sermonpopup.shtml");
    	    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    	    startActivity(intent);
    	}
    	});
   

    Button imageButton = (Button) findViewById(R.id.ImageButton01);
    imageButton.setOnClickListener(new View.OnClickListener() {
		
		public void onClick(View v) {
			Uri uri = Uri.parse("http://thecrossing.net/index.html");
			Intent intent = new Intent(Intent.ACTION_VIEW, uri);
			startActivity(intent);
		}
	});
   
    Button quincyButton = (Button) findViewById(R.id.Button02);
    quincyButton.setOnClickListener(new View.OnClickListener(){
    	public void onClick(View v) {
    		Uri uri = Uri.parse("http://www.thecrossing.net/quincy.shtml");
    		Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    		startActivity(intent);
	}
	});

	Button macombButton = (Button) findViewById(R.id.Button03);
	macombButton.setOnClickListener(new View.OnClickListener(){
		public void onClick(View v) {
			Uri uri = Uri.parse("http://www.thecrossing.net/macomb.shtml");
			Intent intent = new Intent(Intent.ACTION_VIEW, uri);
			startActivity(intent);
	}
	});

	Button kirkButton = (Button) findViewById(R.id.Button04);
	kirkButton.setOnClickListener(new View.OnClickListener(){
		public void onClick(View v) {
			Uri uri = Uri.parse("http://www.thecrossing.net/kirksville.shtml");
		    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		    startActivity(intent);
		}
	});

	Button nineButton = (Button) findViewById(R.id.Button05);
	nineButton.setOnClickListener(new View.OnClickListener(){
		public void onClick(View v) {
			Uri uri = Uri.parse("http://www.thecrossing.net/929.shtml");
		    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		    startActivity(intent);
		}
	});

	Button contactButton = (Button) findViewById(R.id.Button07);
	contactButton.setOnClickListener(new View.OnClickListener(){
		public void onClick(View v) {
			final CharSequence[] ChurchCampus = {"Quincy", "Macomb", "Kirksville", "929"};

	        AlertDialog.Builder ab=new AlertDialog.Builder(crossingActivity.this);
			ab.setTitle("Which campus?");
			ab.setSingleChoiceItems(ChurchCampus, -1, new DialogInterface.OnClickListener() {
	            public void onClick(DialogInterface dialog, int whichButton) {
	            }
	        })
	        .setPositiveButton("Call", new DialogInterface.OnClickListener() {
	            public void onClick(DialogInterface dialog, int whichButton) {
	            	if (ChurchCampus.equals("Quincy")){
	            		try {
	            			   Intent callIntent = new Intent(Intent.ACTION_CALL);
	            			   callIntent.setData(Uri.parse("tel:+2172246374"));
	            			   startActivity(callIntent);
	            			} catch (Exception e) {
	            			   Log.e("CrossingApp", "Failed to start call", e);
	            			}
	            	} else if (ChurchCampus.equals("Macomb")){
	            		try {
	            			   Intent callIntent = new Intent(Intent.ACTION_CALL);
	            			   callIntent.setData(Uri.parse("tel:+3092785117"));
	            			   startActivity(callIntent);
	            			} catch (Exception e) {
	            			   Log.e("CrossingApp", "Failed to start call", e);
	            			}
	            	} else if (ChurchCampus.equals("Kirksville")){
	            		try {
	            			   Intent callIntent = new Intent(Intent.ACTION_CALL);
	            			   callIntent.setData(Uri.parse("tel:+6606656000"));
	            			   startActivity(callIntent);
	            			} catch (Exception e) {
	            			   Log.e("CrossingApp", "Failed to start call", e);
	            			}
	            	} else if (ChurchCampus.equals("929")){
	            		try {
	            			   Intent callIntent = new Intent(Intent.ACTION_CALL);
	            			   callIntent.setData(Uri.parse("tel:+2172140929"));
	            			   startActivity(callIntent);
	            			} catch (Exception e) {
	            			   Log.e("CrossingApp", "Failed to start call", e);
	            			}
	            	}
	        }})
	        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
	            public void onClick(DialogInterface dialog, int whichButton) {
	            	// on cancel button action
	            }
	        });
	        ab.show();
		}
	});

	Button aboutButton = (Button) findViewById(R.id.Button08);
	aboutButton.setOnClickListener(new View.OnClickListener(){
		public void onClick(View v) {
			// prepare the alert box
            AlertDialog.Builder alertbox = new AlertDialog.Builder(crossingActivity.this);
 
            // set the message to display
            alertbox.setMessage("The Crossing version 0.5 BETA");
 
       
            alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {     
                }
            });
 
            // show it
            alertbox.show();
		}
	});
    }
}
 
I thought that it might need the internet permission, but I wasn't sure. Adding it didn't seem to do anything.
Your edited code didn't help either. I'm not sure what's going on.
I'll try the emulator tomorrow (current computer can't run it well enough).
 
Definitely try it through the emulator. You can set break points throughout your code and slowly walk through it line-by-line. Then you will be able to see the exact line that is causing the problem.
 
while trying it out on the emulator, have a logcat window open and you see the exception that is thrown.
 
Whenever I run it in the emulator, Eclipse installs the app and then a new tab opens, ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord,Intent) line 1622
and it says source not found. I directed it at android.jar but it didn't find what it was looking for. Is it making reference to the activity that the app launches with? Because I'm pretty sure my launch activity doesn't have 1622 lines.
 
I rebuilt the app from the ground up and I'm getting the same crashing problem. Eclipse also gave the error that I got in the above post.
 
I don't know exactly how this fixed it, but I reinstalled Eclipse and re-built the app from the ground up and now it's working.
 
Back
Top Bottom