1

Action Sherlock Barアプリ(Android)にを入れて、デバイス4.2.2で正常に実行できますが、Android 4.1.2にインストールしようとすると、クラッシュします...

これはスタックトレースです:

03-01 17:42:00.953: E/AndroidRuntime(15780): FATAL EXCEPTION: Timer-0
03-01 17:42:00.953: E/AndroidRuntime(15780): java.lang.IllegalStateException: Not on the main thread
03-01 17:42:00.953: E/AndroidRuntime(15780):    at maps.ap.q.b(Unknown Source)
03-01 17:42:00.953: E/AndroidRuntime(15780):    at maps.au.e.b(Unknown Source)
03-01 17:42:00.953: E/AndroidRuntime(15780):    at maps.z.ag.moveCamera(Unknown Source)
03-01 17:42:00.953: E/AndroidRuntime(15780):    at com.google.android.gms.maps.internal.IGoogleMapDelegate$Stub.onTransact(IGoogleMapDelegate.java:83)
03-01 17:42:00.953: E/AndroidRuntime(15780):    at android.os.Binder.transact(Binder.java:326)
03-01 17:42:00.953: E/AndroidRuntime(15780):    at com.google.android.gms.maps.internal.IGoogleMapDelegate$a$a.moveCamera(Unknown Source)
03-01 17:42:00.953: E/AndroidRuntime(15780):    at com.google.android.gms.maps.GoogleMap.moveCamera(Unknown Source)
03-01 17:42:00.953: E/AndroidRuntime(15780):    at com.axousis.realweather.MainActivity$2.gotLocation(MainActivity.java:134)
03-01 17:42:00.953: E/AndroidRuntime(15780):    at com.axousis.realweather.util.MyLocation$GetLastLocation.run(MyLocation.java:92)
03-01 17:42:00.953: E/AndroidRuntime(15780):    at java.util.Timer$TimerImpl.run(Timer.java:284)

コード:

public class MainActivity extends MySuperClass{

    private GoogleMap mapa = null;
    private int vista = 0;
    private Button checkButton; 
    private LatLng myCoords;
    private ProgressDialog pleaseWaitDialog;
    private LoadTask loadTask;
    private List<Marcador> marcadores = new ArrayList<Marcador>();
    private Geocoder geocoder;
    private SharedPreferences settings;
    private AutoCompleteTextView editTextAddress;

    private ActionBar actionBar;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.activity_main);

        actionBar = getSupportActionBar();

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            BitmapDrawable bg = (BitmapDrawable)getResources().getDrawable(R.drawable.bg_striped);
            bg.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
            getSupportActionBar().setBackgroundDrawable(bg);

            BitmapDrawable bgSplit = (BitmapDrawable)getResources().getDrawable(R.drawable.bg_striped_split_img);
            bgSplit.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
            getSupportActionBar().setSplitBackgroundDrawable(bgSplit);
        }




        // Retrieve the shared preferences
        settings = getSharedPreferences(APP_PREFERENCES, Context.MODE_PRIVATE);

        //Init geocoder google
        geocoder = new Geocoder(this, Locale.getDefault());      

        //Inicializamos la busqueda de la posicion
        LocationResult locationResult = new LocationResult(){
            @Override
            public void gotLocation(Location location){
                //Got the location!
                location.getLongitude();
                location.getLatitude();
                myCoords = new LatLng(location.getLatitude(),location.getLongitude());

                //Move camera
                LatLng userLocation = MAP_INITIAL_LAT_LON;              
                if (myCoords!=null) {
                    userLocation = myCoords;
                }                       
                CameraUpdate posicionInicial = CameraUpdateFactory.newLatLngZoom(userLocation, MAP_INITIAL_ZOOM_LEVEL);
                mapa.moveCamera(posicionInicial);

            }
        };
        MyLocation myLocation = new MyLocation();
        myLocation.getLocation(this, locationResult);

        //Cargamos el mapa
        mapa = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
        mapa.setMyLocationEnabled(true);
....

クラッシュはに表示されます

mapa.moveCamera(posicionInicial);

どうしてか分かりません...

私は私のアンドロイド4.2.2でそれが動作することを知っているだけですが、私のアンドロイド4.1.2ではそれはクラッシュします...

何か案が?

4

1 に答える 1

0

メイン スレッドから UI 要素にアクセスしようとしています。

これを試して

MainActivity.this.runOnUiThread(new Runnable() {

            @Override
            public void run() {
               mapa.moveCamera(posicionInicial);
            }
        });
于 2013-03-01T19:59:28.680 に答える