如果实现 GooglePlayServicesClient.ConnectionCallbacks/OnConnectionFailedListener,则找不到主要活动类
Posted
技术标签:
【中文标题】如果实现 GooglePlayServicesClient.ConnectionCallbacks/OnConnectionFailedListener,则找不到主要活动类【英文标题】:Main activity class not found if implements GooglePlayServicesClient.ConnectionCallbacks/OnConnectionFailedListener 【发布时间】:2013-12-27 15:53:33 【问题描述】:我按照谷歌doc 关于定位服务开发了一个示例应用程序。 运行它时,我发现 MainActivity 类崩溃,但如果我删除位置回调 GooglePlayServicesClient.ConnectionCallbacks 和 GooglePlayServicesClient.OnConnectionFailedListener 的实现,它就会启动。
我使用的是 android Studio,我很确定我已经很好地配置了 Google Play 服务和 AVD (Nexus 7 Google API 19)。
这是主要活动:
package com.demo.app;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.location.LocationClient;
import com.google.android.gms.location.LocationRequest;
public class MainActivity extends ActionBarActivity implements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener
// Handles to UI widgets
private TextView mLatLng;
private TextView mAddress;
private ProgressBar mActivityIndicator;
private TextView mConnectionState;
private TextView mConnectionStatus;
// A request to connect to Location Services
private LocationRequest mLocationRequest;
// Stores the current instantiation of the location client in this object
private LocationClient mLocationClient;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null)
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
// Get handles to the UI view objects
mLatLng = (TextView) findViewById(R.id.lat_lng);
mAddress = (TextView) findViewById(R.id.address);
mActivityIndicator = (ProgressBar) findViewById(R.id.address_progress);
mConnectionState = (TextView) findViewById(R.id.text_connection_state);
mConnectionStatus = (TextView) findViewById(R.id.text_connection_status);
/*
* Create a new location client, using the enclosing class to
* handle callbacks.
*/
//mLocationClient = new LocationClient(this, this, this);
@Override
public boolean onCreateOptionsMenu(Menu menu)
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
@Override
public boolean onOptionsItemSelected(MenuItem item)
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings)
return true;
return super.onOptionsItemSelected(item);
@Override
public void onConnected(Bundle bundle)
@Override
public void onDisconnected()
@Override
public void onConnectionFailed(ConnectionResult connectionResult)
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment
public PlaceholderFragment()
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
例外是:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfocom.demo.app/com.demo.app.MainActivity: java.lang.ClassNotFoundException: com.demo.app.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.demo.app- 2.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2591)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
at android.app.ActivityThread.access$2300(ActivityThread.java:126)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4633)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.demo.app.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.demo.app-2.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
[...]
【问题讨论】:
您遇到的具体错误是什么? 你解决过这个问题吗? 你在使用过时的 Holoeverywhere 主题吗? 这是怎么回事?对 2013 年的一个问题的社区赏金? @devmao,你还需要这方面的帮助吗? 其实不是,都是过时的东西 【参考方案1】:确保此 Extras 文件夹中的软件包已安装或更新到较新版本的 sdk,例如(Google Play 服务、Google 存储库等)
【讨论】:
以上是关于如果实现 GooglePlayServicesClient.ConnectionCallbacks/OnConnectionFailedListener,则找不到主要活动类的主要内容,如果未能解决你的问题,请参考以下文章
浅拷贝与深拷贝的实现方式区别;deepcopy如果你来设计,如何实现
如果我实现了decisionPolicyFor navigationAction,WKWebView 为空,如果我删除该函数,则正确加载