Java 扩展应用紧性会产生未捕获的异常

Java 扩展应用紧性会产生未捕获的异常,java,android,uncaught-exception,android-actionbaractivity,appcompatactivity,Java,Android,Uncaught Exception,Android Actionbaractivity,Appcompatactivity,在MainActivity中,当我按下按钮时,我必须打开另一个扩展AppCompacActivity的活动。问题是,由于一个未处理的异常,我使我的应用程序崩溃。这是密码 main程序代码: Button NextButton = (Button)findViewById(R.id.next_button); NextButton.setOnClickListener(new View.OnClickListener() { @Override public

在MainActivity中,当我按下按钮时,我必须打开另一个扩展AppCompacActivity的活动。问题是,由于一个未处理的异常,我使我的应用程序崩溃。这是密码

main程序代码:

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);
        }
    });
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() {...}
}
GeoFenceMain活动代码:

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);
        }
    });
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() {...}
}

尝试在清单中添加此主题:

android:theme="@style/Theme.AppCompat" >
活动中
标记

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


post完整的logcat stacktrace..调用super onCreate()并在第二个活动的onCreate()方法中将savedInstanceState传递给它。@DushyantSuthar,代码已经完成了。无论如何,我已经在这里添加了那个片段。@rafsanahmad007我的问题是我不能有任何例外。我试图在所有onCreate方法中放置一个try/catch块,但是什么也没有发生,因为异常结果仍然未捕获。我没有把stacktrace放在这里,因为我没有它。你确定吗?因为我在你添加的代码中看不到它。