0
04-18 10:43:01.765: I/System.out(23278): MANUAL HOURS === 9:8
04-18 10:43:01.820: I/System.out(23278): ---GpsOnOff.detectGps()
04-18 10:43:01.835: D/AndroidRuntime(23278): Shutting down VM
04-18 10:43:01.835: W/dalvikvm(23278): threadid=1: thread exiting with uncaught exception (group=0x40018578)
04-18 10:43:01.851: E/AndroidRuntime(23278): FATAL EXCEPTION: main
04-18 10:43:01.851: E/AndroidRuntime(23278): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.security/com.example.security.Colect_data_from_usr_activity}: android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@40538820 is not valid; is your activity running?
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.app.ActivityThread.startActivityNow(ActivityThread.java:1491)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at com.example.security.StartInspection$3.onClick(StartInspection.java:72)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.view.View.performClick(View.java:2485)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.view.View$PerformClick.run(View.java:9080)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.os.Handler.handleCallback(Handler.java:587)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.os.Handler.dispatchMessage(Handler.java:92)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.os.Looper.loop(Looper.java:130)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.app.ActivityThread.main(ActivityThread.java:3687)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at java.lang.reflect.Method.invokeNative(Native Method)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at java.lang.reflect.Method.invoke(Method.java:507)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at dalvik.system.NativeStart.main(Native Method)
04-18 10:43:01.851: E/AndroidRuntime(23278): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@40538820 is not valid; is your activity running?
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.view.ViewRoot.setView(ViewRoot.java:532)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.view.Window$LocalWindowManager.addView(Window.java:424)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.app.Dialog.show(Dialog.java:241)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at com.example.security.Colect_data_from_usr_activity.showGPSOnDialog(Colect_data_from_usr_activity.java:195)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at com.example.security.Colect_data_from_usr_activity.detectGps(Colect_data_from_usr_activity.java:172)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at com.example.security.Colect_data_from_usr_activity.onCreate(Colect_data_from_usr_activity.java:95)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-18 10:43:01.851: E/AndroidRuntime(23278):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
04-18 10:43:01.851: E/AndroidRuntime(23278):    ... 15 more

Colect_data_from_usr_activity.java

  public class Colect_data_from_usr_activity extends Activity {
 Dialog dialog;
 Button cnf_exit,cnf_cancel;

 private CheckBox chk1, chk2,chk3,chk4,chk5;
 Button  btn_sbmt;
 String address="";
 String adr1,adr2;
 private int mYear;
 private int mMonth;
 private int mDay;
 private TextView edt_date,edt_time,txt_location,edt_note,txt_buildingname;
 private int mhour,mminute,msecond;

 static final int TIME_DIALOG_ID = 1;
 static final int DATE_DIALOG_ID = 0;
 LocationManager loc_mgr ;   
 MyLocationListener location_listener;   

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.collect_data_frm_user_layout);

    dialog = new Dialog(ActGroup.group);
    dialog.setContentView(R.layout.confirmexit);
    dialog.setTitle(Html.fromHtml("<font color='white'>Exit</font>"));

    dialog.show();

    cnf_exit=(Button) dialog.findViewById(R.id.cnf_exit);
    cnf_cancel =(Button) dialog.findViewById(R.id.cnf_cancel);
    cnf_exit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    cnf_cancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            dialog.cancel();
        }
    });


    SimpleDateFormat date_format = new SimpleDateFormat("dd-MMM-yy");
    SimpleDateFormat time_format = new SimpleDateFormat("HH:mm:ss a");
    Date date = new Date();
    getWindow().setSoftInputMode(
    WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    loc_mgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    detectGps();

   /*   Bundle bundle = getIntent().getExtras();
    String strloc = bundle.getString("lctn");
    System.out.println("======>>>>" + strloc);
  */    

    addListenerOnChkIos();
    addListenerOnButton();

    txt_location = (TextView)findViewById(R.id.txt_location);
    txt_location.setText(address);
    txt_buildingname = (TextView)findViewById(R.id.textView_Building_name);
    txt_buildingname.setText(Tracker.building_name);

    edt_note = (TextView) findViewById(R.id.editText_note);
         edt_date = (TextView) findViewById(R.id.txtvw_date);

      Date d = new Date();
  java.text.DateFormat df = android.text.format.DateFormat.getDateFormat(getApplicationContext());
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    edt_date.setText(date_format.format(date));

    edt_time=(TextView) findViewById(R.id.editText_time);
    edt_time.setText(time_format.format(date));

      edt_date.setOnClickListener(new View.OnClickListener() {
       public void onClick(View v) {
           showDialog(DATE_DIALOG_ID);
       }
   });

    final Calendar c = Calendar.getInstance();
    mYear = c.get(Calendar.YEAR);
    mMonth = c.get(Calendar.MONTH);
    mDay = c.get(Calendar.DAY_OF_MONTH);
    mhour = c.get(Calendar.HOUR);
    mminute = c.get(Calendar.MINUTE);
    msecond = c.get(Calendar.SECOND);

    }        

 private void updateDate() {
    edt_date.setText(new StringBuilder()
           .append(mDay).append("/")
           .append(mMonth + 1).append("/")
           .append(mYear).append(" "));
            showDialog(DATE_DIALOG_ID);
  }

   //-------------------------------------------update time---------------------//    
  public void updatetime()
  {
 edt_time.setText(new StringBuilder()
               .append(pad(mhour)).append(":")
                  .append(pad(mminute))); 
  }
  private void detectGps() {
// TODO Auto-generated method stub
System.out.println("---GpsOnOff.detectGps()");
if(loc_mgr.isProviderEnabled(LocationManager.GPS_PROVIDER))
{
    trackGPS();
}
else
{
    showGPSOnDialog();
}  }

   public void showGPSOnDialog() {
// TODO Auto-generated method stub
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("GPS is disabled in your device. Would you like to enable it?")
.setCancelable(false)
.setPositiveButton("Settings",
        new DialogInterface.OnClickListener(){
    public void onClick(DialogInterface dialog, int id){
        Intent callGPSSettingIntent = new Intent(
                android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        startActivityForResult(callGPSSettingIntent,55);
    }
});
alertDialogBuilder.setNegativeButton("Cancel",new DialogInterface.OnClickListener(){
    public void onClick(DialogInterface dialog, int id){
        dialog.cancel();
    }
});
AlertDialog alert = alertDialogBuilder.create();
alert.show();
 }


 protected void showLastKnownLocation() {

Location location = loc_mgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);

if (location == null) {
    System.out.println("LOCATION GPS NULL");
    location = loc_mgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}

if(location!=null)
{
    String message = String.format(
            "Last Location \n Longitude: %1$s \n Latitude: %2$s",
            location.getLongitude(), location.getLatitude()
            );
    System.out.println(message);
    getAddress(location.getLatitude(),location.getLongitude());
}
else
{
    System.out.println("LOCATION NULL");
}}

   @Override  
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
detectGps();
 }

 public void trackGPS() {
// TODO Auto-generated method stub
showLastKnownLocation();
location_listener = new MyLocationListener();
loc_mgr.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,location_listener);
 }

 private void getAddress(double latitude,double longitude) {
// TODO Auto-generated method stub
try {
    Geocoder geocoder = new Geocoder(Colect_data_from_usr_activity.this);
    try {
        List<Address> arr =  geocoder.getFromLocation(latitude,longitude,1);
    if(arr.size() !=0 && arr != null)
    {
    for (int i = 0; i < arr.get(0).getMaxAddressLineIndex(); i++) {
    System.out.println("ADDRESSSS   "+arr.get(0).getAddressLine(i));
                if(i == 0)
                {
                    adr1 = arr.get(0).getAddressLine(i);
                }else if(i == 1)
                {
                    adr2 = arr.get(0).getAddressLine(i);
                }
                address += arr.get(0).getAddressLine(i)+"\n";
            }
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.println("--- GETADRES EXCEPTION");
    }
} catch (Exception e) {
    // TODO: handle exception
    System.out.println(e.toString());
}} 
  public class MyLocationListener implements LocationListener
  {
public void onLocationChanged(Location location) {
    // TODO Auto-generated method stub
    if(location != null)
    {
        getAddress(location.getLatitude(), location.getLongitude());
    }
    else
    {
        System.out.println("--- location null;");
    }
}

@Override
public void onProviderDisabled(String provider) {
    // TODO Auto-generated method stub
    System.out.println("GpsOnOff.MyLocationListener.onProviderDisabled()");
}

@Override
public void onProviderEnabled(String provider) {
    // TODO Auto-generated method stub
    System.out.println("GpsOnOff.MyLocationListener.onProviderEnabled()");
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub
    System.out.println("GpsOnOff.MyLocationListener.onStatusChanged()");
}}

  private void CheckEnableGPS(){
String provider = Settings.Secure.getString(getContentResolver(),
        Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(provider.contains("gps")){
    //GPS Enabled
    System.out.println("PROVIDE -- "+provider);
    //  Toast.makeText(Start_hr_activity.this, "GPS Enabled: " + provider,
    //          Toast.LENGTH_LONG).show();
}else{
    //Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
    Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    startActivity(intent);
}
}

 private static String pad(int c) 
  {
 if (c >= 10)
      return String.valueOf(c);
 else
      return "0" + String.valueOf(c);
 }

  //Datepicker dialog generation  
  private DatePickerDialog.OnDateSetListener mDateSetListener =
  new DatePickerDialog.OnDateSetListener() {
    public void onDateSet(DatePicker view, int year, 
                         int monthOfYear, int dayOfMonth) {
       mYear = year;
       mMonth = monthOfYear;
       mDay = dayOfMonth;
      updateDate();
   } 
 };

 // Timepicker dialog generation
  private TimePickerDialog.OnTimeSetListener mTimeSetListener =
  new TimePickerDialog.OnTimeSetListener() {

public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

    mhour = hourOfDay;
    mminute = minute;
    updatetime();
       }
   };
 @Override
 protected Dialog onCreateDialog(int id) {
   switch (id) {
   case DATE_DIALOG_ID:
       return new DatePickerDialog(this,
               mDateSetListener, mYear, mMonth,mDay);
   case TIME_DIALOG_ID:
       return new TimePickerDialog(this,
               mTimeSetListener, mhour, mminute, false);
        }
   return null;
 }

  public void addListenerOnChkIos() {

chk1 = (CheckBox) findViewById(R.id.checkBox_windowopen);
chk1.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {

    if (((CheckBox) v).isChecked()) {
            }

        }
    });
}

  public void addListenerOnButton() {

    chk1 = (CheckBox) findViewById(R.id.checkBox_windowopen);
    chk2 = (CheckBox) findViewById(R.id.checkBox_dooropen);
    chk3 = (CheckBox) findViewById(R.id.checkBox_employeeonsite);
    chk4 = (CheckBox) findViewById(R.id.checkBox_glassbroken);
    chk5 = (CheckBox) findViewById(R.id.checkBox_doorbroken);

    btn_sbmt = (Button) findViewById(R.id.button_sbmt);
    btn_sbmt.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {

    String str_1 = String.valueOf(chk1);
    String str_2 = String.valueOf(chk2);
    String str_3 = String.valueOf(chk3);
    String str_4 = String.valueOf(chk4);
    String str_5 = String.valueOf(chk5);

    String str_dt = edt_date.getText().toString();
    String str_tm = edt_time.getText().toString();
    System.out.println("********_--------________--- "+ str_tm);

    String str_loct = txt_location.getText().toString();
    str_loct.valueOf(txt_location.getText().toString());

    String str_note = edt_note.getText().toString();
    String incidents="";

    if(chk1.isChecked())
     {
        incidents += chk1.getText().toString()+"\n";
     }

    if(chk2.isChecked())
     {
        incidents += chk2.getText().toString()+"\n";
     }
    if(chk3.isChecked())
     {
        incidents += chk3.getText().toString()+"\n";
     }
    if(chk4.isChecked())
     {
        incidents += chk4.getText().toString()+"\n";
     }

    if(chk5.isChecked())
     {
        incidents += chk5.getText().toString()+"\n";
     }

    Bundle b=new Bundle();
    b.putString("c1", incidents);
    b.putString("date", str_dt);
    b.putString("time", str_tm);
    b.putString("lctn",str_loct);
    b.putString("note", str_note);
    b.putString("adr1", adr1);
    b.putString("adr2", adr2);
    loc_mgr.removeUpdates(location_listener);
Intent intnt = new Intent(v.getContext(), Colected_data_result_activity.class);
intnt.putExtras(b);
View view = ActGroup.group.getLocalActivityManager().startActivity("Colected_data_result_activity", intnt.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
ActGroup.group.replaceView(view);
//  Toast.makeText(Report.this, result.toString(),Toast.LENGTH_LONG).show();
        }
    });
}
  @Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    dialog.show();
}
}

最新的日志猫

04-18 11:49:34.414: D/AndroidRuntime(27731): Shutting down VM
04-18 11:49:34.414: W/dalvikvm(27731): threadid=1: thread exiting with uncaught exception (group=0x40018578)
04-18 11:49:34.453: E/AndroidRuntime(27731): FATAL EXCEPTION: main
04-18 11:49:34.453: E/AndroidRuntime(27731): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.security/com.example.security.Colect_data_from_usr_activity}: java.lang.NullPointerException
04-18 11:49:34.453: E/AndroidRuntime(27731):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at android.app.ActivityThread.startActivityNow(ActivityThread.java:1491)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at com.example.security.StartInspection$3.onClick(StartInspection.java:72)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at android.view.View.performClick(View.java:2485)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at android.view.View$PerformClick.run(View.java:9080)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at android.os.Handler.handleCallback(Handler.java:587)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at android.os.Handler.dispatchMessage(Handler.java:92)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at android.os.Looper.loop(Looper.java:130)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at android.app.ActivityThread.main(ActivityThread.java:3687)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at java.lang.reflect.Method.invokeNative(Native Method)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at java.lang.reflect.Method.invoke(Method.java:507)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at dalvik.system.NativeStart.main(Native Method)
04-18 11:49:34.453: E/AndroidRuntime(27731): Caused by: java.lang.NullPointerException
04-18 11:49:34.453: E/AndroidRuntime(27731):    at com.example.security.Colect_data_from_usr_activity.detectGps(Colect_data_from_usr_activity.java:159)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at com.example.security.Colect_data_from_usr_activity.onCreate(Colect_data_from_usr_activity.java:66)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-18 11:49:34.453: E/AndroidRuntime(27731):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
04-18 11:49:34.453: E/AndroidRuntime(27731):    ... 15 more
4

2 回答 2

0

根据日志,该异常是由于向未在前台运行的活动添加了一个对话框。在 onCreate 中,该对话框构造函数应与当前正在运行的活动的上下文一起传递。但是,根据上面的代码,对话框构造函数将 activitygroup(ActGroup.group 返回 activitygroup ) 作为参数而不是上下文。

如果您仍想使用 ActGroup.group,则该对话框构造函数应包含 ActGroup.group.getCurrentActivity()。

于 2013-04-18T07:09:26.183 回答
0

您不能从内部显示对话框onCreate;这就是导致神秘异常的原因。窗口尚未创建。将detectGps调用(以及显示代码的其他对话框)移至onStart它应该可以工作。

但事实上,您应该覆盖onCreateDialog并使用showDialog来显示对话框。这允许活动在活动生命周期事件期间正确管理对话框。

于 2013-04-18T06:06:58.683 回答