有人能告诉我这里的nullpointerexception是什么?它说它在第49行," cigstxt = currentUser.get(" inADay")。toString();"。 我不知道第49行怎么可能是nullpointer但是第50行不能。
public class Welcome extends RegisterInformationActivity { Button logout; String cigstxt; String moneysavedtxt; String notsmokedtxt; String timesavedtxt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.welcome); TextView cigs = (TextView)findViewById(R.id.days); TextView moneysaved = (TextView)findViewById(R.id.moneysaved); TextView timesaved = (TextView)findViewById(R.id.timesaved); TextView notsmoked = (TextView)findViewById(R.id.notsmoked); final ParseUser currentUser = ParseUser.getCurrentUser(); String struser = currentUser.getUsername().toString(); TextView txtuser = (TextView)findViewById(R.id.textView); txtuser.setText(struser); cigstxt = currentUser.get("inADay").toString(); moneysavedtxt = currentUser.get("days").toString(); notsmokedtxt = currentUser.get("inABox").toString(); timesavedtxt = currentUser.get("price").toString(); cigs.setText(String.valueOf(cigstxt)); moneysaved.setText(String.valueOf(moneysavedtxt)); timesaved.setText(String.valueOf(timesavedtxt)); notsmoked.setText(String.valueOf(notsmokedtxt)); logout = (Button)findViewById(R.id.btnlogout); logout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ParseUser.logOut(); finish(); } }); }}
logcat的:
04-28 21:30:48.196 20869-20869/com.lacher.quitsmoking_doitnow E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.lacher.quitsmoking_doitnow, PID: 20869
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lacher.quitsmoking_doitnow/com.lacher.quitsmoking_doitnow.Welcome}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2224)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2283)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5153)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.lacher.quitsmoking_doitnow.Welcome.onCreate(Welcome.java:49)
at android.app.Activity.performCreate(Activity.java:5312)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2181)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2283)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5153)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
这是一个parse.com数据库的问题,我搞砸了(删除了最后一个用户名)。代码一直很好。现在它完美无缺!