我的应用在AVD上运行时崩溃了。 1)通过pushbots完成了所有规定的事情。 2)jar文件添加。 3)扩展类但没有用。 我的应用程序崩溃了
错误日志是:
07-04 22:25:05.994: E/Trace(628): error opening trace file: No such file or directory (2)
07-04 22:25:06.152: D/AndroidRuntime(628): Shutting down VM
07-04 22:25:06.152: W/dalvikvm(628): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
07-04 22:25:06.172: E/AndroidRuntime(628): FATAL EXCEPTION: main
07-04 22:25:06.172: E/AndroidRuntime(628): java.lang.RuntimeException: Unable to instantiate application com.csconnect: java.lang.ClassNotFoundException: com.csconnect
07-04 22:25:06.172: E/AndroidRuntime(628): at android.app.LoadedApk.makeApplication(LoadedApk.java:501)
07-04 22:25:06.172: E/AndroidRuntime(628): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4124)
07-04 22:25:06.172: E/AndroidRuntime(628): at android.app.ActivityThread.access$1300(ActivityThread.java:130)
07-04 22:25:06.172: E/AndroidRuntime(628): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1255)
07-04 22:25:06.172: E/AndroidRuntime(628): at android.os.Handler.dispatchMessage(Handler.java:99)
07-04 22:25:06.172: E/AndroidRuntime(628): at android.os.Looper.loop(Looper.java:137)
07-04 22:25:06.172: E/AndroidRuntime(628): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-04 22:25:06.172: E/AndroidRuntime(628): at java.lang.reflect.Method.invokeNative(Native Method)
07-04 22:25:06.172: E/AndroidRuntime(628): at java.lang.reflect.Method.invoke(Method.java:511)
07-04 22:25:06.172: E/AndroidRuntime(628): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-04 22:25:06.172: E/AndroidRuntime(628): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-04 22:25:06.172: E/AndroidRuntime(628): at dalvik.system.NativeStart.main(Native Method)
07-04 22:25:06.172: E/AndroidRuntime(628): Caused by: java.lang.ClassNotFoundException: com.csconnect
07-04 22:25:06.172: E/AndroidRuntime(628): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-04 22:25:06.172: E/AndroidRuntime(628): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-04 22:25:06.172: E/AndroidRuntime(628): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-04 22:25:06.172: E/AndroidRuntime(628): at android.app.Instrumentation.newApplication(Instrumentation.java:967)
07-04 22:25:06.172: E/AndroidRuntime(628): at android.app.LoadedApk.makeApplication(LoadedApk.java:496)
07-04 22:25:06.172: E/AndroidRuntime(628): ... 11 more
最明显的文件是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.csconnect"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="20" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<permission android:name="com.csconnect.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.csconnect.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:name="com.csconnect"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.csconnect.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.csconnect.MESSAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.pushbots.push.PBMsg"/>
<activity android:name="com.pushbots.push.PBListener"/>
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.csconnect" />
</intent-filter>
</receiver>
<receiver android:name="com.pushbots.push.MsgReceiver" />
<service android:name="com.pushbots.push.GCMIntentService" />
<service android:name="org.openudid.OpenUDID_service" >
<intent-filter>
<action android:name="org.openudid.GETUDID" />
</intent-filter>
</service>
<activity
android:name="com.csconnect.SecondActivity"
android:label="@string/title_activity_second" >
</activity>
<!-- GCM connects to Google Services. -->
</application>
</manifest>
主要活动文件是:
package com.csconnect;
import com.pushbots.push.Pushbots;
import android.app.Activity;
public class MainActivity extends Activity {
public String PUSHBOTS_APPLICATION_ID = "---#the application ID#---";
public String SENDER_ID="-----#the sender ID-----#";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Pushbots.init(this, SENDER_ID,PUSHBOTS_APPLICATION_ID);
Button inboxbutton = (Button) findViewById(R.id.button1);
inboxbutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this , SecondActivity.class);
startActivity(intent);
}
});
}
}
答案 0 :(得分:0)
错误的方式:
右键单击主项目,选择Properties -> Java Build Path -> Projects -> Add...
,这将Android库项目添加为Android主项目构建路径中的依赖项目,这不起作用。如果在主项目中定义了所有必需的Android相关资源,则在编译时不会出现任何错误,但在运行应用程序时,您将获得问题中描述的异常。
正确的方式:
右键单击主项目,选择Properties -> Android
,在“库”部分中,在此处添加Android库项目。查看官方开发指南Referencing a library project。这应该解决你所有的问题。另请注意,您必须使用相对路径引用实际的Android库项目,如Library Project - Development considerations中所述。
答案 1 :(得分:0)
我遇到了同样的问题。我以正确的方式添加了库,但是有相同的问题。我的解决方案是将android-support-v4.jar更新为android-support-v13.jar。之后它完美无缺!!