我的应用程序工作正常但是当我从最近的任务列表中将其滑出并再次运行时会发生此错误。
05-18 22:51:28.240: E/AndroidRuntime(2364): FATAL EXCEPTION: main
05-18 22:51:28.240: E/AndroidRuntime(2364): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.vaccinationsystem/com.example.vaccinationsystem.GenUserFunction}: java.lang.NullPointerException
05-18 22:51:28.240: E/AndroidRuntime(2364): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
05-18 22:51:28.240: E/AndroidRuntime(2364): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
05-18 22:51:28.240: E/AndroidRuntime(2364): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-18 22:51:28.240: E/AndroidRuntime(2364): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
05-18 22:51:28.240: E/AndroidRuntime(2364): at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 22:51:28.240: E/AndroidRuntime(2364): at android.os.Looper.loop(Looper.java:137)
05-18 22:51:28.240: E/AndroidRuntime(2364): at android.app.ActivityThread.main(ActivityThread.java:5103)
05-18 22:51:28.240: E/AndroidRuntime(2364): at java.lang.reflect.Method.invokeNative(Native Method)
05-18 22:51:28.240: E/AndroidRuntime(2364): at java.lang.reflect.Method.invoke(Method.java:525)
05-18 22:51:28.240: E/AndroidRuntime(2364): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
05-18 22:51:28.240: E/AndroidRuntime(2364): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-18 22:51:28.240: E/AndroidRuntime(2364): at dalvik.system.NativeStart.main(Native Method)
05-18 22:51:28.240: E/AndroidRuntime(2364): Caused by: java.lang.NullPointerException
05-18 22:51:28.240: E/AndroidRuntime(2364): at com.android.internal.os.LoggingPrintStream.println(LoggingPrintStream.java:298)
05-18 22:51:28.240: E/AndroidRuntime(2364): at com.example.vaccinationsystem.GenUserFunction.Alerts(GenUserFunction.java:286)
05-18 22:51:28.240: E/AndroidRuntime(2364): at com.example.vaccinationsystem.GenUserFunction.onCreate(GenUserFunction.java:82)
05-18 22:51:28.240: E/AndroidRuntime(2364): at android.app.Activity.performCreate(Activity.java:5133)
05-18 22:51:28.240: E/AndroidRuntime(2364): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-18 22:51:28.240: E/AndroidRuntime(2364): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
我没有从最近的列表中刷过0来这样做,所以它正常工作,但之后会崩溃。 我的GenUserFunction:
package com.example.vaccinationsystem;
public class GenUserFunction extends Activity implements OnClickListener {
Button bVRC, bRC, bFB, bMap, bNews, bAlters;
TextView tvNotification;
String userId;
SoapObject request;
PropertyInfo p_userId;
SoapSerializationEnvelope envelope;
HttpTransportSE httpTransport;
SoapPrimitive response;
LinearLayout alertboxLayout;
int countNotification = 0;
int totalDifference;
ArrayList<String> listRec;
String s;
PendingIntent piService1;
Intent Service1;
AlarmManager alarmManager1;
private static final String METHOD_NAME = "Alerts";
private static final String NAMESPACE = "http://org.fyp.ws";
private static final String SOAP_ACTION = "http://org.fyp.ws/Alerts";
private static final String URL = StaticIP.ipAddress
+ "GeneralUserServices?wsdl";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// // full Screen
// requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.general_user);
initialize();
userId = getIntent().getExtras().getString("user_id");
Toast.makeText(getApplicationContext(), userId, Toast.LENGTH_LONG)
.show();
// stopService(new Intent(this, BackgroundServices.class));
// Service1 = new Intent(getApplicationContext() ,
// BackgroundServices.class);
// Service1.putExtra("user_Id", userId);
// piService1 = PendingIntent.getService(getApplicationContext() , 0 ,
// Service1 , PendingIntent.FLAG_UPDATE_CURRENT);
// alarmManager1 = (AlarmManager)
// getApplicationContext().getSystemService(getApplicationContext().ALARM_SERVICE);
// alarmManager1.cancel(piService1);
// alarmManager1.setRepeating(AlarmManager.RTC_WAKEUP ,
// System.currentTimeMillis() , 11000 , piService1);
Alerts();
}
@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
MenuInflater blowUp = getMenuInflater();
blowUp.inflate(R.menu.cool_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.aboutUs:
Toast.makeText(getApplicationContext(), "About Us",
Toast.LENGTH_LONG).show();
break;
case R.id.logout:
Toast.makeText(getApplicationContext(), "Logout",
Toast.LENGTH_SHORT).show();
// stopService(new Intent(this, BackgroundServices.class));
// alarmManager1.cancel(piService1);
Editor editor = Splash.sharedpreferences.edit();
editor.remove("login_check");
editor.commit();
Intent i = new Intent("android.intent.action.LOGIN");
startActivity(i);
finish();
break;
case R.id.exit:
finish();
break;
}
return false;
}
public void initialize() {
bVRC = (Button) findViewById(R.id.bVRC);
bRC = (Button) findViewById(R.id.bRC);
bFB = (Button) findViewById(R.id.bFB);
bMap = (Button) findViewById(R.id.bMaps);
bNews = (Button) findViewById(R.id.bNews);
bAlters = (Button) findViewById(R.id.bAlerts);
tvNotification = (TextView) findViewById(R.id.tvNotification);
// alertboxLayout = (LinearLayout) findViewById(R.id.abc);
bVRC.setOnClickListener(this);
bRC.setOnClickListener(this);
bFB.setOnClickListener(this);
bMap.setOnClickListener(this);
bNews.setOnClickListener(this);
bAlters.setOnClickListener(this);
listRec = new ArrayList<String>();
request = new SoapObject(NAMESPACE, METHOD_NAME);
p_userId = new PropertyInfo();
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
httpTransport = new HttpTransportSE(URL);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bVRC:
Intent intentVCR = new Intent(
"android.intent.action.VIEWCHILDRECORD");
intentVCR.putExtra("user_id", userId);
startActivity(intentVCR);
break;
case R.id.bRC:
Intent intentRC = new Intent("android.intent.action.REGCHILD");
intentRC.putExtra("user_id", userId);
startActivity(intentRC);
break;
case R.id.bFB:
Intent intentFB = new Intent("android.intent.action.FEEDBACK");
intentFB.putExtra("user_id", userId);
startActivity(intentFB);
break;
case R.id.bMaps:
Intent intentMap = new Intent(
"android.intent.action.VACCINATIONMAP");
intentMap.putExtra("user_id", userId);
startActivity(intentMap);
break;
case R.id.bNews:
Intent intentNews = new Intent("android.intent.action.NEWSRECORD");
intentNews.putExtra("user_id", userId);
startActivity(intentNews);
break;
case R.id.bAlerts:
customDialogbox a = new customDialogbox(GenUserFunction.this,
listRec);
a.show();
break;
default:
break;
}
}
public void Alerts() {
p_userId.setName("userId");// Define the variable name in the web
p_userId.setValue(userId);// Define value for fname variable
p_userId.setType(String.class);// Define the type of the variable
request.addProperty(p_userId);// Pass properties to the variable
envelope.setOutputSoapObject(request);
try {
httpTransport.call(SOAP_ACTION, envelope);
response = (SoapPrimitive) envelope.getResponse();
// Toast.makeText(getApplicationContext(), response.toString(),
// Toast.LENGTH_LONG).show();
String[] row = response.toString().split("`");
for (int i = 0; i < row.length; i++) {
String[] record = row[i].split("~");
// totalDifference = 0;
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String curDate = df.format(c.getTime()).toString();
String visitDate = record[1];
java.util.Date cD = df.parse(curDate);
java.util.Date vD = df.parse(visitDate);
Calendar cCurDate = Calendar.getInstance();
cCurDate.setTime(cD);
cCurDate.add(Calendar.DAY_OF_YEAR, 0);
java.util.Date newCurDate = cCurDate.getTime();
Calendar cNotificationStartVisitDate = Calendar.getInstance();
cNotificationStartVisitDate.setTime(vD);
cNotificationStartVisitDate.add(Calendar.DAY_OF_YEAR, -15);
java.util.Date notificationStartDate = cNotificationStartVisitDate
.getTime();
Calendar cOrignalVisitDate = Calendar.getInstance();
cOrignalVisitDate.setTime(vD);
cOrignalVisitDate.add(Calendar.DAY_OF_YEAR, 0);
java.util.Date newOriDateVisitDate = cOrignalVisitDate
.getTime();
totalDifference = 0;
if (notificationStartDate.before(newCurDate)) {
while (newOriDateVisitDate.after(newCurDate)) {
cOrignalVisitDate.add(Calendar.DAY_OF_YEAR, -1);
newOriDateVisitDate = cOrignalVisitDate.getTime();
totalDifference++;
s = "left";
}
while (newOriDateVisitDate.before(newCurDate)) {
cOrignalVisitDate.add(Calendar.DAY_OF_YEAR, +1);
newOriDateVisitDate = cOrignalVisitDate.getTime();
totalDifference++;
s = "ago";
}
countNotification++;
listRec.add(row[i] + "~" + String.valueOf(totalDifference)
+ "~" + s);
}
}
if (countNotification > 0) {
tvNotification.setVisibility(View.VISIBLE);
tvNotification.setText(String.valueOf(countNotification));
}
// Toast.makeText(getApplicationContext(),
// String.valueOf(listRec.size()), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
// TODO: handle exception
System.out.println(e.getMessage());
}
}
}
答案 0 :(得分:0)
我猜并且坚信错误在System.out.println(e.getMessage());
只需将其替换为e.printStackTrace()
....
这是我的猜测....如果不只是在这里发布或在代码中标记为行号286?
THX