我正在尝试在我的某个应用程序中应用Pin Lock。它已经被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);
}
}
崩溃了。
我的主要活动类如下所示
com.exmaple.myapp.LockActivity.onCreate(LockActivity.java:42)
在此行中给出运行时错误
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
我在这里缺少什么?
LOGCAT如下所示
09-18 09:09:44.615 2684-2684/notes.ronak.com.a22k16 E/AndroidRuntime: FATAL EXCEPTION: main
Process: notes.ronak.com.a22k16, PID: 2684
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1351)
at android.content.res.Resources.getDrawable(Resources.java:804)
at android.content.res.Resources.getDrawable(Resources.java:771)
at notes.ronak.com.a22k16.Timetable$MyListAdapter.getView(Timetable.java:140)
at android.widget.AbsListView.obtainView(AbsListView.java:2346)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1280)
at android.widget.ListView.onMeasure(ListView.java:1188)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18788)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1630)
at android.view.View.measure(View.java:18788)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
at android.view.View.measure(View.java:18788)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1216)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
由于
答案 0 :(得分:0)
我想你错过了这个
setContentView(R.layout.YOUR_XML_LAYOUT_FOR_LOCKACTIVITY);
在super.onCreate(savedInstanceState);
之后