Results 1 to 2 of 2
  1. #1
    Curly is offline Member
    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Default Android App Crashes/Won't Install

    Hello.
    I am new to Java and making android apps (obviously). I made an app which gets your phone number and puts in the notification bar. When I run it in AVD it says my app has crashed. This is what LogCat says:
    Java Code:
    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
    This is my code:
    Java 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.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;
        	}
        }
    }
    I tried to install it on my phone using ASTRO and it recognises that I have set the vibration permission but when I press the install button it says 'Application not installed'.

    Any help is appreciated!
    Thanks :D
    -Curly

  2. #2
    AeneasTroy is offline Arma virumque cano
    Join Date
    Oct 2012
    Location
    Indianapolis
    Posts
    20
    Rep Power
    0

    Default Re: Android App Crashes/Won't Install

    There are a lot of build files that you need to mess with.

    And the java programs compile your programs even if there
    are errors that will make it crash in the emulator.

    There seem to be a lot of problems with this code.

    This is what I'm seeing:
    09-27 18:33:22.361: E/AndroidRuntime(475): Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()

    From here:
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    I barely know what I'm doing, but can you write it like this:
    NotificationManager nm;

    Java Code:
    public blah onCreate(State){
         super(something)
         nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
       
    }

Similar Threads

  1. Replies: 7
    Last Post: 09-21-2012, 02:47 PM
  2. Can not install Android ADT on Eclipse.
    By Pojahn_M in forum Android
    Replies: 4
    Last Post: 01-28-2012, 12:27 PM
  3. android dev install help
    By droidus in forum New To Java
    Replies: 0
    Last Post: 11-14-2011, 08:04 PM
  4. Replies: 5
    Last Post: 11-26-2010, 07:04 AM
  5. Java crashes
    By Nicole in forum Advanced Java
    Replies: 2
    Last Post: 04-06-2009, 08:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •