我有几个在 XML 中定义的对象,当我尝试处理它们时返回 null。我看到几个帖子说要清理项目,但这没有帮助。当我探索 ListView 对象时,所有的孩子都是空的?所以我对自己做错了什么有点茫然。这是我认为相关的代码,但如果您需要查看其他内容,请告诉我,我会发布。
TIA JB
<Button
android:id="@+id/btn_NextLift"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="30dp"
android:layout_marginBottom="40dp"
android:text="@string/str_BtnNxtTxt"
android:onClick="btn_NextLiftClick"
android:longClickable="true" />
在活动中:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.liftinterface);
...//More code....
...//Still in the OnCreate....
lstvw_LiftData = (ListView)findViewById(R.id.lstvw_LiftData);
...//Image below of this object.....
//Get a handle on our button
Button btn_Nxt = (Button)this.findViewById(R.id.btn_NextLift);
btn_Nxt.setOnLongClickListener(new OnLongClickListener()
{
public boolean onLongClick(View v)
{
SaveAdvance();
return true;
}
});
这只是我的 logcat 错误:
11-13 22:04:57.798: E/AndroidRuntime(787): FATAL EXCEPTION: main
11-13 22:04:57.798: E/AndroidRuntime(787): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.gpgvm.ironmike/org.gpgvm.ironmike.IcyArmActivity}: java.lang.NullPointerException
11-13 22:04:57.798: E/AndroidRuntime(787): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
11-13 22:04:57.798: E/AndroidRuntime(787): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-13 22:04:57.798: E/AndroidRuntime(787): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-13 22:04:57.798: E/AndroidRuntime(787): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-13 22:04:57.798: E/AndroidRuntime(787): at android.os.Handler.dispatchMessage(Handler.java:99)
11-13 22:04:57.798: E/AndroidRuntime(787): at android.os.Looper.loop(Looper.java:123)
11-13 22:04:57.798: E/AndroidRuntime(787): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-13 22:04:57.798: E/AndroidRuntime(787): at java.lang.reflect.Method.invokeNative(Native Method)
11-13 22:04:57.798: E/AndroidRuntime(787): at java.lang.reflect.Method.invoke(Method.java:507)
11-13 22:04:57.798: E/AndroidRuntime(787): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-13 22:04:57.798: E/AndroidRuntime(787): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-13 22:04:57.798: E/AndroidRuntime(787): at dalvik.system.NativeStart.main(Native Method)
11-13 22:04:57.798: E/AndroidRuntime(787): Caused by: java.lang.NullPointerException
11-13 22:04:57.798: E/AndroidRuntime(787): at org.gpgvm.ironmike.IcyArmActivity.onCreate(IcyArmActivity.java:83)
11-13 22:04:57.798: E/AndroidRuntime(787): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-13 22:04:57.798: E/AndroidRuntime(787): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
11-13 22:04:57.798: E/AndroidRuntime(787): ... 11 more