1. Are you ready for the Galaxy S20? Here is everything we know so far!

Application is not getting open

Discussion in 'Android Development' started by Ganesh, Dec 31, 2009.

  1. Ganesh

    Ganesh Newbie
    Thread Starter

    Hello Everyone,


    I am trying to just diplay single image on canvas the code is like following...

    package com.displayImage;
    import android.app.Activity;
    import android.content.Context;
    import android.graphics.drawable.Drawable;
    import android.os.Bundle;
    public class DisplayImage extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Context context = null;
    Drawable helloworldImg= context.getResources().getDrawable(R.drawable.helloworld);
    helloworldImg.setBounds(0, 0, helloworldImg.getIntrinsicWidth(), helloworldImg.getIntrinsicHeight()/2);
    }
    }




    But I am getting following display message and application gets closed (On emulator and device also)

    "The application DisplayImage (process.com.displayImage) has stopped unexpectedly"
     


  2. eclipsed4utoo

    eclipsed4utoo Android Enthusiast

    Whay are you setting the Context to null then trying to use it? Most likely, you are getting a NullReference Exception because you are trying to use the null context.

    To get the current application context, use this...

    Code (Text):
    1.  
    2. Context myContext = getApplicationContext();
    3.  
     
  3. Ganesh

    Ganesh Newbie
    Thread Starter

    Hello eclipsed4utoo,,

    I will try with
    Context myContext = getApplicationContext();

    Thank you in advance







    [​IMG]
     
Loading...
Similar Threads - Application getting open
  1. andrey2211
    Replies:
    0
    Views:
    267
  2. Kavinraj M
    Replies:
    3
    Views:
    415
  3. akaskhu
    Replies:
    2
    Views:
    276
  4. Samsung
    Replies:
    0
    Views:
    175
  5. SeanRouxWTB
    Replies:
    0
    Views:
    217
  6. Senchi007
    Replies:
    4
    Views:
    295
  7. TheOuz
    Replies:
    0
    Views:
    381
  8. Kris94
    Replies:
    4
    Views:
    490
  9. Noobmaster
    Replies:
    1
    Views:
    457
  10. psaulius
    Replies:
    1
    Views:
    270

Share This Page

Loading...