这是我的logcat。
07-03 17:17:01.085 24875-24875/com.example.faisal.fuel_share E/Trace: error opening trace file: No such file or directory (2)
07-03 17:17:01.165 24875-24921/com.example.faisal.fuel_share E/dalvikvm:
Could not find class 'android.app.AppOpsManager', referenced from method
com.google.android.gms.internal.zzacw.zzg
07-03 17:17:18.901 24875-24875/com.example.faisal.fuel_share E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException: Activity must not be null
at com.google.android.gms.common.internal.zzac.zzb(Unknown Source)
at com.google.android.gms.internal.zzaav.<init>(Unknown Source)
at com.google.android.gms.internal.zzaaw.zzs(Unknown Source)
at com.google.android.gms.tasks.zzh$zza.zzw(Unknown Source)
at com.google.android.gms.tasks.zzh.addOnCompleteListener(Unknown Source)
at com.example.faisal.fuel_share.FYP_DAO.GetHelpDB.singup(GetHelpDB.java:68)
at com.example.faisal.fuel_share.FYP_DAO.GetHelpDB.<init>(GetHelpDB.java:35)
at com.example.faisal.fuel_share.GetHelp.singUp(GetHelp.java:82)
at com.example.faisal.fuel_share.GetHelp.access$000(GetHelp.java:18)
at com.example.faisal.fuel_share.GetHelp$1.onClick(GetHelp.java:42)
at android.view.View.performClick(View.java:4209)
at android.view.View$PerformClick.run(View.java:17360)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
这是我的代码..
public class GetHelp extends Activity {
private EditText emailid, nameid, passwordid, phonenoid;
/*protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
*/
private TextInputLayout inputlayoutname, inputlayoutemail,
inputlayoutpassword, inputlayoutphoneno;
Button submit;
GetHelpDB ghDb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gethelp);
initComponents();
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
singUp();
}
});
}
private void singUp() {
boolean isValid = true;
if (nameid.getText().toString().isEmpty()) {
inputlayoutname.setError("Name is Mandatory");
isValid = false;
} else {
inputlayoutname.setErrorEnabled(false);
}
if (emailid.getText().toString().isEmpty()) {
inputlayoutemail.setError("Email is Mandatory");
isValid = false;
} else {
inputlayoutemail.setErrorEnabled(false);
}
if (passwordid.getText().toString().trim().length() < 8) {
inputlayoutpassword.setError("Minimum 8 Character Required");
isValid = false;
} else {
inputlayoutpassword.setErrorEnabled(false);
}
if (phonenoid.getText().toString().isEmpty()) {
inputlayoutphoneno.setError("Phone Number is Mandatory");
isValid = false;
} else {
inputlayoutphoneno.setErrorEnabled(false);
}
if (isValid) {
Toast.makeText(GetHelp.this, "welcome", Toast.LENGTH_SHORT).show();
GetHelpBean gb=new GetHelpBean();
gb.setNameid(nameid.getText().toString());
gb.setEmailid(emailid.getText().toString());
gb.setPasswordid(passwordid.getText().toString());
gb.setPhonenoid(phonenoid.getText().toString());
ghDb=new GetHelpDB(gb);
/* Intent i=new Intent(this, GetHelpProfile.class);
i.putExtra("GetHelp", gb);
startActivity(i); */
}
}
private void initComponents() {
nameid = (EditText) findViewById(R.id.nameid);
emailid = (EditText) findViewById(R.id.emailid);
passwordid = (EditText) findViewById(R.id.passwordid);
phonenoid = (EditText) findViewById(R.id.phonenoid);
inputlayoutname = (TextInputLayout) findViewById(R.id.inputlayoutname);
inputlayoutemail = (TextInputLayout) findViewById(R.id.inputlayoutemail);
inputlayoutpassword = (TextInputLayout) findViewById(R.id.inputlayoutpassword);
inputlayoutphoneno = (TextInputLayout) findViewById(R.id.inputlayoutphoneno);
submit = (Button) findViewById(R.id.submit);
}
}
答案 0 :(得分:1)
您尚未声明并初始化context.Declare为Context context;
并在context=GetHelp.this;
方法中将其初始化为onCreate
。
这导致你的NPE。