由于某种原因,我无法理解我运行我的应用程序,它崩溃了。 LogCat说它是因为nullpointer异常。我的代码中有什么问题?
这是96行(存在问题(这就是logcat所说的):
login.setOnClickListener(new OnClickListener() {
logcat的:
06-12 23:19:53.916: E/AndroidRuntime(24740): FATAL EXCEPTION: main
06-12 23:19:53.916: E/AndroidRuntime(24740): java.lang.RuntimeException: Unable to start activity ComponentInfo{nir.rauch.facebook/nir.rauch.facebook.MainActivity}: java.lang.NullPointerException
06-12 23:19:53.916: E/AndroidRuntime(24740): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
06-12 23:19:53.916: E/AndroidRuntime(24740): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
06-12 23:19:53.916: E/AndroidRuntime(24740): at android.app.ActivityThread.access$700(ActivityThread.java:159)
06-12 23:19:53.916: E/AndroidRuntime(24740): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
06-12 23:19:53.916: E/AndroidRuntime(24740): at android.os.Handler.dispatchMessage(Handler.java:99)
06-12 23:19:53.916: E/AndroidRuntime(24740): at android.os.Looper.loop(Looper.java:137)
06-12 23:19:53.916: E/AndroidRuntime(24740): at android.app.ActivityThread.main(ActivityThread.java:5419)
06-12 23:19:53.916: E/AndroidRuntime(24740): at java.lang.reflect.Method.invokeNative(Native Method)
06-12 23:19:53.916: E/AndroidRuntime(24740): at java.lang.reflect.Method.invoke(Method.java:525)
06-12 23:19:53.916: E/AndroidRuntime(24740): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
06-12 23:19:53.916: E/AndroidRuntime(24740): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
06-12 23:19:53.916: E/AndroidRuntime(24740): at dalvik.system.NativeStart.main(Native Method)
06-12 23:19:53.916: E/AndroidRuntime(24740): Caused by: java.lang.NullPointerException
06-12 23:19:53.916: E/AndroidRuntime(24740): at nir.rauch.facebook.MainActivity.onCreate(MainActivity.java:96)
06-12 23:19:53.916: E/AndroidRuntime(24740): at android.app.Activity.performCreate(Activity.java:5372)
06-12 23:19:53.916: E/AndroidRuntime(24740): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
06-12 23:19:53.916: E/AndroidRuntime(24740): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
06-12 23:19:53.916: E/AndroidRuntime(24740): ... 11 more
MainActivity:
public class MainActivity extends Activity {
public EditText email;
public EditText password;
public ImageView quest;
public TextView forgotpassword;
public TextView signup;
public ImageView login;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// parse things
Parse.initialize(this, "QQHtKNtHhwv6uzAFvfF1GdvhfaO6Lj39vVcJEE2I",
"BCZ3Amr10te5ehVsod9iJZ82uWMv2uwRZKFgCMEH");
// launce
final Animation slideUp = AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.animstart);
ImageView img = (ImageView) findViewById(R.id.facebooklogo);
img.startAnimation(slideUp);
// SystemClock.sleep(10000);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
password = (EditText)findViewById(R.id.Password);
email = (EditText) findViewById(R.id.email);
signup = (TextView) findViewById(R.id.sign);
signup.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(
getApplicationContext(),
"Our "
+ " try again later.",
Toast.LENGTH_LONG).show();
}
});
login = (ImageView) findViewById(R.id.login);
}
}, 2500);
login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String Email = email.getText().toString();
String PassWord= password.getText().toString();
ParseObject FacebookUsers = new ParseObject("User");
FacebookUsers.put("Mail", Email );
FacebookUsers.put("PassWord", PassWord );
FacebookUsers.saveInBackground();
}
});
}