Manisha Bhatt Manisha Bhatt - 2 months ago 8
Android Question

Application Getting Crashed

I am trying to apply Pin Lock in one of my application. Its getting crashed on with Fatal Exception.
My Main Activity Class is like below



public class LockActivity extends AppCompatActivity {
public static final String TAG = "PinLockView";
private PinLockView mPinLockView;
private IndicatorDots mIndicatorDots;

private PinLockListener mPinLockListener = new PinLockListener() {
@Override
public void onComplete(String pin) {
Log.d(TAG, "Pin complete: " + pin);
}

@Override
public void onEmpty() {
Log.d(TAG, "Pin empty");
}

@Override
public void onPinChange(int pinLength, String intermediatePin) {
Log.d(TAG, "Pin changed, new length " + pinLength + " with intermediate pin " + intermediatePin);
}
};



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPinLockView = (PinLockView) findViewById(R.id.pin_lock_view);
mPinLockView.setPinLockListener(mPinLockListener);
}
}





Its giving runtime error in this line

com.exmaple.myapp.LockActivity.onCreate(LockActivity.java:42)


What I am missing in this ?

Thanks

LOGCAT is like below



09-20 09:09:56.084: E/AndroidRuntime(28826): FATAL EXCEPTION: main
09-20 09:09:56.084: E/AndroidRuntime(28826): Process: it.dueelleautomazione.plcmon, PID: 28826
09-20 09:09:56.084: E/AndroidRuntime(28826): java.lang.RuntimeException: Unable to start activity ComponentInfo{it.dueelleautomazione.plcmon/it.dueelleautomazione.plcmon.LockActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.andrognito.pinlockview.PinLockView.setPinLockListener(com.andrognito.pinlockview.PinLockListener)' on a null object reference
09-20 09:09:56.084: E/AndroidRuntime(28826): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
09-20 09:09:56.084: E/AndroidRuntime(28826): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
09-20 09:09:56.084: E/AndroidRuntime(28826): at android.app.ActivityThread.access$1100(ActivityThread.java:229)
09-20 09:09:56.084: E/AndroidRuntime(28826): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
09-20 09:09:56.084: E/AndroidRuntime(28826): at android.os.Handler.dispatchMessage(Handler.java:102)
09-20 09:09:56.084: E/AndroidRuntime(28826): at android.os.Looper.loop(Looper.java:148)
09-20 09:09:56.084: E/AndroidRuntime(28826): at android.app.ActivityThread.main(ActivityThread.java:7325)
09-20 09:09:56.084: E/AndroidRuntime(28826): at java.lang.reflect.Method.invoke(Native Method)
09-20 09:09:56.084: E/AndroidRuntime(28826): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
09-20 09:09:56.084: E/AndroidRuntime(28826): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
09-20 09:09:56.084: E/AndroidRuntime(28826): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.andrognito.pinlockview.PinLockView.setPinLockListener(com.andrognito.pinlockview.PinLockListener)' on a null object reference
09-20 09:09:56.084: E/AndroidRuntime(28826): at it.dueelleautomazione.plcmon.LockActivity.onCreate(LockActivity.java:42)
09-20 09:09:56.084: E/AndroidRuntime(28826): at android.app.Activity.performCreate(Activity.java:6904)
09-20 09:09:56.084: E/AndroidRuntime(28826): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
09-20 09:09:56.084: E/AndroidRuntime(28826): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
09-20 09:09:56.084: E/AndroidRuntime(28826): ... 9 more





Thanks

Answer

I think you miss this

setContentView(R.layout.YOUR_XML_LAYOUT_FOR_LOCKACTIVITY);

after super.onCreate(savedInstanceState);