(SOLVED) Calling A Public Method Causes NullPointerException - Android
<p>Ahm, Hey everyone, I just want to ask what is the problem in the program I am creating. Here is the Snippet Codes</p>

<p><strong>PlayActivity.class</strong></p>

<pre><code>//more codes here
 public void stFLabel(int numFace, Context ct) {

    try {
        if(numFace &gt; 0)
            faceLebel.setText("Face Hint : I See You Human");
        else
            faceLebel.setText("Face Hint : Where Are You?");
    }
    catch(NullPointerException e)
    {
        e.printStackTrace();
            Log.d(TAG, "stFLabel Has Error");
        }
    }
//more codes here
</code></pre>

<p>*<strong><em>CameraPreview.class</em>*</strong></p>

<pre><code>//More codes
...
PlayActivity pacT = new PlayActivity();
...
//More Codes
..
public void pausy(int numFace) {
pacT.stFLabel(numFace, mContext);
}
</code></pre>

<p><strong>LOGCAT</strong></p>

<pre><code>04-05 16:11:26.150: D/FaceDetection(27929): face detected: 1 Face 1 Location X: 65Y: -1
04-05 16:11:26.150: W/System.err(27929): java.lang.NullPointerException
04-05 16:11:26.150: W/System.err(27929):    at com.delihente.faceplay.PlayActivity.stFLabel(PlayActivity.java:90)
04-05 16:11:26.150: W/System.err(27929):    at com.delihente.faceplay.CameraPreview.pausy(CameraPreview.java:62)
04-05 16:11:26.150: W/System.err(27929):    at com.delihente.faceplay.CameraPreview$1.onFaceDetection(CameraPreview.java:53)
04-05 16:11:26.150: W/System.err(27929):    at android.hardware.Camera$EventHandler.handleMessage(Camera.java)
04-05 16:11:26.150: W/System.err(27929):    at android.os.Handler.dispatchMessage(Handler.java)
04-05 16:11:26.150: W/System.err(27929):    at android.os.Looper.loop(Looper.java)
04-05 16:11:26.150: W/System.err(27929):    at android.app.ActivityThread.main(ActivityThread.java)
04-05 16:11:26.150: W/System.err(27929):    at java.lang.reflect.Method.invokeNative(Native Method)
04-05 16:11:26.150: W/System.err(27929):    at java.lang.reflect.Method.invoke(Method.java:511)
04-05 16:11:26.150: W/System.err(27929):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
04-05 16:11:26.150: W/System.err(27929):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
04-05 16:11:26.150: W/System.err(27929):    at dalvik.system.NativeStart.main(Native Method)
04-05 16:11:26.150: D/(27929): stFLabel Has Error
</code></pre>

<p><strong>MORE INFO :</strong></p>

<pre><code>PlayAcvitiy.class extends Activity (Main Class)
CameraPreview.class - The camera preview class provided by google android development
faceLebel = TextView on PlayAcvitiy.class
mContext = PlayActivity.class Context
</code></pre>

<p>I want to know what is causing the NullPointerException (A Fix will be Better),
I have read almost 3 pages of google search about my problem but none of it has helped me.
and also, please don't mention to change the method to static because It cannot be because it changes the TextView Label when the CameraPreview.class detects/Undetects Faces..
Thanks in Advance!</p>

<p>EDIT : I have also read so many related questions here, but none of them seem to help</p>

<p>EDIT 2 : <strong>Problem Solved</strong>, thanks to all, specially to PrafulBhatnagar, I have learned that Using a method in the Main Activity needs a reference to its context. Thanks Everyone!</p>
