Application is not getting open

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

  1. Ganesh

    Ganesh Member
    15

    Dec 25, 2009
    18
    0
    15
    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"
     

    Advertisement
  2. eclipsed4utoo

    eclipsed4utoo Well-Known Member
    43

    Nov 12, 2009
    435
    27
    43
    Software Developer
    Florence, SC
    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 Member
    15

    Dec 25, 2009
    18
    0
    15
    Hello eclipsed4utoo,,

    I will try with
    Context myContext = getApplicationContext();

    Thank you in advance







    [​IMG]
     

Share This Page

Loading...