-1

Depuis mon MainActivity, lorsque j'appuie sur un bouton, je dois ouvrir une autre activité qui étend AppCompacActivity. Le problème est que mon application est écrasée à cause d'une exception non gérée. Voici le codeL'extension AppCompActivity donne une exception non interceptée

Code MainProgram:

Button NextButton = (Button)findViewById(R.id.next_button); 
    NextButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Intent intent = new Intent(getApplicationContext(), GeofenceMainActivity.class); 
      startActivity(intent); 
     } 
    }); 

Code GeofenceMainActivity:

package com.clb.apokalos.todolistas; 

import android.app.PendingIntent; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.util.Log; 
import android.view.View; 
import android.widget.Button; 
import android.widget.Toast; 

import com.google.android.gms.common.ConnectionResult; 
import com.google.android.gms.common.api.GoogleApiClient; 
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks; 
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener; 
import com.google.android.gms.common.api.ResultCallback; 
import com.google.android.gms.common.api.Status; 
import com.google.android.gms.location.Geofence; 
import com.google.android.gms.location.GeofencingRequest; 
import com.google.android.gms.location.LocationServices; 
import com.google.android.gms.location.GeofencingApi; 
import com.google.android.gms.maps.model.LatLng; 

import java.util.ArrayList; 
import java.util.Map; 

/** 
* Demonstrates how to create and remove geofences using the GeofencingApi. Uses an IntentService 
* to monitor geofence transitions and creates notifications whenever a device enters or exits 
* a geofence. 
* 
* This sample requires a device's Location settings to be turned on. It also requires 
* the ACCESS_FINE_LOCATION permission, as specified in AndroidManifest.xml. 
* 
* Note that this Activity implements ResultCallback<Status>, requiring that 
* {@code onResult} must be defined. The {@code onResult} runs when the result of calling 
* {@link GeofencingApi#addGeofences(GoogleApiClient, GeofencingRequest, PendingIntent)} addGeofences()} or 
* {@link com.google.android.gms.location.GeofencingApi#removeGeofences(GoogleApiClient, java.util.List)} removeGeofences()} 
* becomes available. 
*/ 
public class GeofenceMainActivity extends AppCompatActivity implements 
     ConnectionCallbacks, OnConnectionFailedListener, ResultCallback<Status> { 

    //variables here. 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     ... 
    } 

    protected synchronized void buildGoogleApiClient() {...} 

    @Override 
    protected void onStart() {...} 

    @Override 
    protected void onStop() {...} 

    @Override 
    public void onConnected(Bundle connectionHint) {...} 

    @Override 
    public void onConnectionFailed(ConnectionResult result) {...} 

    @Override 
    public void onConnectionSuspended(int cause) {...} 

    private GeofencingRequest getGeofencingRequest() {...} 

    public void addGeofencesButtonHandler(View view) {...} 

    public void removeGeofencesButtonHandler(View view) {...} 

    private void logSecurityException(SecurityException securityException) {...} 

    public void onResult(Status status) {...} 

    private PendingIntent getGeofencePendingIntent() {...} 

    public void populateGeofenceList() {...} 

    private void setButtonsEnabledState() {...} 
} 

Ce code a été modifié depuis dans sa mise en œuvre originale, il prolongeait ActionBarActivity (maintenant dépréciée), j'ai donc modifié le code en remplaçant ActionBarActivity par AppCompatActivity.

Le code d'erreur est juste: ThreadID = 1: fil sortant à l'exception uncaught (groupe = 0x41da6438)

Pourriez-vous me aider? Essayez les blocs ne semble pas m'aider à trouver une solution.

EDIT: J'ai le stacktrace

01-16 16:45:11.597 31258-31258/com.clb.apokalos.todolistas W/System.err: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 
01-16 16:45:11.597 31258-31258/com.clb.apokalos.todolistas W/System.err:  at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:112) 
01-16 16:45:11.597 31258-31258/com.clb.apokalos.todolistas W/System.err:  at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:148) 
01-16 16:45:11.597 31258-31258/com.clb.apokalos.todolistas W/System.err:  at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:60) 
01-16 16:45:11.597 31258-31258/com.clb.apokalos.todolistas W/System.err:  at com.clb.apokalos.todolistas.GeofenceMainActivity.onCreate(GeofenceMainActivity.java:81) 
01-16 16:45:11.597 31258-31258/com.clb.apokalos.todolistas W/System.err:  at android.app.Activity.performCreate(Activity.java:5024) 
01-16 16:45:11.597 31258-31258/com.clb.apokalos.todolistas W/System.err:  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 
01-16 16:45:11.607 31258-31258/com.clb.apokalos.todolistas W/System.err:  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2042) 
01-16 16:45:11.607 31258-31258/com.clb.apokalos.todolistas W/System.err:  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2103) 
01-16 16:45:11.607 31258-31258/com.clb.apokalos.todolistas W/System.err:  at android.app.ActivityThread.access$600(ActivityThread.java:137) 
01-16 16:45:11.607 31258-31258/com.clb.apokalos.todolistas W/System.err:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1211) 
01-16 16:45:11.607 31258-31258/com.clb.apokalos.todolistas W/System.err:  at android.os.Handler.dispatchMessage(Handler.java:99) 
01-16 16:45:11.607 31258-31258/com.clb.apokalos.todolistas W/System.err:  at android.os.Looper.loop(Looper.java:137) 
01-16 16:45:11.607 31258-31258/com.clb.apokalos.todolistas W/System.err:  at android.app.ActivityThread.main(ActivityThread.java:4842) 
01-16 16:45:11.607 31258-31258/com.clb.apokalos.todolistas W/System.err:  at java.lang.reflect.Method.invokeNative(Native Method) 
01-16 16:45:11.607 31258-31258/com.clb.apokalos.todolistas W/System.err:  at java.lang.reflect.Method.invoke(Method.java:511) 
01-16 16:45:11.607 31258-31258/com.clb.apokalos.todolistas W/System.err:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842) 
01-16 16:45:11.607 31258-31258/com.clb.apokalos.todolistas W/System.err:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
01-16 16:45:11.607 31258-31258/com.clb.apokalos.todolistas W/System.err:  at dalvik.system.NativeStart.main(Native Method) 
01-16 16:45:11.607 31258-31258/com.clb.apokalos.todolistas W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41da6438) 
+2

Postez le stacktrace complet logcat .. – rafsanahmad007

+1

appelle le super onCreate() et lui passe le savedInstanceState dans la méthode onCreate() de la seconde activi ty. –

+0

@DushyantSuthar, c'était déjà fait par le code. J'ai ajouté ce morceau ici de toute façon. – Apokalos

Répondre

1

essayer d'ajouter ce thème dans votre manifeste:

android:theme="@style/Theme.AppCompat" > 

dans activity tag

<activity 
     android:name=".GeofenceMainActivity" 
     android:label="@string/app_name" 
     android:theme="@style/Theme.AppCompat" /> 
+0

Ça a marché! Je vous remercie! – Apokalos