14 Replies - 1959 Views - Last Post: 08 October 2012 - 04:31 PM

#1 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

Android App Crashes

Posted 27 September 2012 - 08:50 AM

Hello. I am new to Java so I'm sorry if I'm a n00b.
I am making an app that tells you your phone number in the notification bar. I tested it in AVD but I get 'The application Phone Number (process com.CurlyFries.phonenumber) has stopped unexpectedly. Please try again.' when ever I launch the app. This is my code:
package com.CurlyFries.phonenumber;

import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.view.Menu;
import android.view.View;
import android.view.View.onclickListener;
import android.widget.Button;

public class MainActivity extends Activity implements onclickListener {

	public String getMyPhoneNumber(){
		   TelephonyManager mTelephonyMgr;
		   mTelephonyMgr = (TelephonyManager)
		    getSystemService(Context.TELEPHONY_SERVICE);
		   return mTelephonyMgr.getLine1Number();
		 }
	
	static final int uniqueID = 16573892;
	
	static boolean note = true;
	
	NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
		 
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button stat = (Button)findViewById(R.id.menu_settings);
        stat.setonclickListener(this);
        
    }
    
    public void onclick(View v) {
    	// TODO Auto-generated method stub
    	if (note == true){
    	Intent intent = new Intent(this, MainActivity.class);
    	PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
    	String title = getMyPhoneNumber();
    	Notification n = new Notification(R.drawable.ic_launcher, null, System.currentTimeMillis());
    	n.setLatestEventInfo(this, title, null, pi);
    	n.defaults = Notification.DEFAULT_ALL;
    	nm.notify(uniqueID, n);
    	note = false;
    	}
    	
    	if (note == false);{
    		nm.cancel(uniqueID);
    		note = true;
    	}
    }
}



Any help will be appreciated.
Thanks in advance :D

Is This A Good Question/Topic? 0
  • +

Replies To: Android App Crashes

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10595
  • View blog
  • Posts: 39,252
  • Joined: 27-December 08

Re: Android App Crashes

Posted 27 September 2012 - 10:59 AM

Moved to Android.

Please post your stack trace from the Logcat on Eclipse.
Was This Post Helpful? 0
  • +
  • -

#3 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

Re: Android App Crashes

Posted 27 September 2012 - 11:34 AM

Quote

Moved to Android.

Thanks!

Quote

Please post your stack trace from the Logcat on Eclipse.

09-27 18:33:22.311: D/AndroidRuntime(475): Shutting down VM
09-27 18:33:22.311: W/dalvikvm(475): threadid=1: thread exiting with uncaught exception (group=0x40015560)
09-27 18:33:22.361: E/AndroidRuntime(475): FATAL EXCEPTION: main
09-27 18:33:22.361: E/AndroidRuntime(475): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.CurlyFries.phonenumber/com.CurlyFries.phonenumber.MainActivity}: java.lang.IllegalStateException: System services not available to Activities before onCreate()
09-27 18:33:22.361: E/AndroidRuntime(475): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
09-27 18:33:22.361: E/AndroidRuntime(475): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-27 18:33:22.361: E/AndroidRuntime(475): 	at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-27 18:33:22.361: E/AndroidRuntime(475): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-27 18:33:22.361: E/AndroidRuntime(475): 	at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 18:33:22.361: E/AndroidRuntime(475): 	at android.os.Looper.loop(Looper.java:123)
09-27 18:33:22.361: E/AndroidRuntime(475): 	at android.app.ActivityThread.main(ActivityThread.java:3683)
09-27 18:33:22.361: E/AndroidRuntime(475): 	at java.lang.reflect.Method.invokeNative(Native Method)
09-27 18:33:22.361: E/AndroidRuntime(475): 	at java.lang.reflect.Method.invoke(Method.java:507)
09-27 18:33:22.361: E/AndroidRuntime(475): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-27 18:33:22.361: E/AndroidRuntime(475): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-27 18:33:22.361: E/AndroidRuntime(475): 	at dalvik.system.NativeStart.main(Native Method)
09-27 18:33:22.361: E/AndroidRuntime(475): Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
09-27 18:33:22.361: E/AndroidRuntime(475): 	at android.app.Activity.getSystemService(Activity.java:3536)
09-27 18:33:22.361: E/AndroidRuntime(475): 	at com.CurlyFries.phonenumber.MainActivity.<init>(MainActivity.java:29)
09-27 18:33:22.361: E/AndroidRuntime(475): 	at java.lang.Class.newInstanceImpl(Native Method)
09-27 18:33:22.361: E/AndroidRuntime(475): 	at java.lang.Class.newInstance(Class.java:1409)
09-27 18:33:22.361: E/AndroidRuntime(475): 	at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
09-27 18:33:22.361: E/AndroidRuntime(475): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
09-27 18:33:22.361: E/AndroidRuntime(475): 	... 11 more


Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10595
  • View blog
  • Posts: 39,252
  • Joined: 27-December 08

Re: Android App Crashes

Posted 27 September 2012 - 11:41 AM

Is the Activity in your manifest file?
Was This Post Helpful? 0
  • +
  • -

#5 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

Re: Android App Crashes

Posted 27 September 2012 - 11:48 AM

View Postmacosxnerd101, on 27 September 2012 - 11:41 AM, said:

Is the Activity in your manifest file?

Quote

I am new to Java so I'm sorry if I'm a n00b.

I don't think so...
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10595
  • View blog
  • Posts: 39,252
  • Joined: 27-December 08

Re: Android App Crashes

Posted 27 September 2012 - 11:50 AM

Quote

I am new to Java so I'm sorry if I'm a n00b.

I understand that, but you should be able to navigate your project directory to find a file named manifest.xml, open it, and see if your Activity is in there.

And if it isn't in there, you will have to do a little reading on where to add it. This tutorial is a good starting place. Happy coding.
Was This Post Helpful? 0
  • +
  • -

#7 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

Re: Android App Crashes

Posted 27 September 2012 - 12:05 PM

View Postmacosxnerd101, on 27 September 2012 - 11:50 AM, said:

Quote

I am new to Java so I'm sorry if I'm a n00b.

I understand that, but you should be able to navigate your project directory to find a file named manifest.xml, open it, and see if your Activity is in there.

And if it isn't in there, you will have to do a little reading on where to add it. This tutorial is a good starting place. Happy coding.

Well I know how to navigate...
I can't find the activity
Was This Post Helpful? 0
  • +
  • -

#8 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10595
  • View blog
  • Posts: 39,252
  • Joined: 27-December 08

Re: Android App Crashes

Posted 27 September 2012 - 12:09 PM

Then, like I said in my last post, you will have to add it to the manifest. I gave you a link on how to do that.
Was This Post Helpful? 0
  • +
  • -

#9 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

Re: Android App Crashes

Posted 27 September 2012 - 12:17 PM

View Postmacosxnerd101, on 27 September 2012 - 12:09 PM, said:

Then, like I said in my last post, you will have to add it to the manifest. I gave you a link on how to do that.

Thanks for the link but I don't really know what I'm looking for.
Was This Post Helpful? 0
  • +
  • -

#10 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10595
  • View blog
  • Posts: 39,252
  • Joined: 27-December 08

Re: Android App Crashes

Posted 27 September 2012 - 12:31 PM

You need to look to see how to include the Activity in the manifest file. This is XML, not Java. If the Activity isn't listed in the manifest, you won't be able to use it in your application. The link shows you how to list your Activity in the manifest. There are also plenty of other tutorials online that show you how to do this as well. You are going to have to do some reading here.
Was This Post Helpful? 0
  • +
  • -

#11 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

Re: Android App Crashes

Posted 27 September 2012 - 12:38 PM

I found this:
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

Is this what I am looking for?
Was This Post Helpful? 0
  • +
  • -

#12 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

Re: Android App Crashes

Posted 28 September 2012 - 07:24 AM

BUMP
Was This Post Helpful? -1
  • +
  • -

#13 blankwall  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 65
  • Joined: 12-July 12

Re: Android App Crashes

Posted 28 September 2012 - 11:34 AM

yyes that's your manifest file. it should have more then that but that is the main activity stuff. I'm not familiar with the number thing but if that's your only class your manifest looks.ok.
Was This Post Helpful? 0
  • +
  • -

#14 curlyfries1999  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 22-December 11

Re: Android App Crashes

Posted 28 September 2012 - 11:56 AM

View Postblankwall, on 28 September 2012 - 11:34 AM, said:

yyes that's your manifest file. it should have more then that but that is the main activity stuff. I'm not familiar with the number thing but if that's your only class your manifest looks.ok.

So do you know what my problem is?
Was This Post Helpful? 0
  • +
  • -

#15 ThriceSenses  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 22-March 10

Re: Android App Crashes

Posted 08 October 2012 - 04:31 PM

Perhaps line 4 of the logcat you posted could help you debug your issue, "09-27 18:33:22.361: E/AndroidRuntime(475): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.CurlyFries.phonenumber/com.CurlyFries.phonenumber.MainActivity}: java.lang.IllegalStateException: System services not available to Activities before onCreate()
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1