从我的MainActivity,当我按下按钮时,我必须打开另一个扩展AppCompacActivity的活动。问题是我的应用程序因为未处理的异常而被粉碎。这是代码
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);
}
});
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() {...}
}
此代码已被修改,因为在它的原始实现中,它正在扩展ActionBarActivity(现已弃用),所以我通过用ActionCompatActivity替换ActionBarActivity来修改代码。
错误代码只是:threadid = 1:线程退出未捕获的异常(group = 0x41da6438)
你可以帮帮我吗?尝试块似乎无助于我找到解决方案。 编辑:我有堆栈跟踪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)
答案 0 :(得分:1)
尝试在清单中添加此主题:
android:theme="@style/Theme.AppCompat" >
activity
代码中的
<activity
android:name=".GeofenceMainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat" />