I have merged two packages into one: this and this into one. The problem that I'm facing is that I can only declare one Application in android manifest. I have two applications to declare: AppController for Volley and ParseApplication for Parse package.
What should I do to declare only one application in Android Manifest? I'm still a newbie and trying to learn by merging some code that I find online for practice what I read or watch online.
Thank you !
Update: Here is the Appcontroller class:
Public class AppController extends Application {
public static final String TAG = AppController.class.getSimpleName();
private RequestQueue mRequestQueue;
private ImageLoader mImageLoader;
LruBitmapCache mLruBitmapCache;
private static AppController mInstance;
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
}
public static synchronized AppController getInstance() {
return mInstance;
}
public RequestQueue getRequestQueue() {
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}
return mRequestQueue;
}
public ImageLoader getImageLoader() {
getRequestQueue();
if (mImageLoader == null) {
getLruBitmapCache();
mImageLoader = new ImageLoader(this.mRequestQueue, mLruBitmapCache);
}
return this.mImageLoader;
}
public LruBitmapCache getLruBitmapCache() {
if (mLruBitmapCache == null)
mLruBitmapCache = new LruBitmapCache();
return this.mLruBitmapCache;
}
public <T> void addToRequestQueue(Request<T> req, String tag) {
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
getRequestQueue().add(req);
}
public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG);
getRequestQueue().add(req);
}
public void cancelPendingRequests(Object tag) {
if (mRequestQueue != null) {
mRequestQueue.cancelAll(tag);
}
}
}
public class ParseApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(this);
// Add your initialization code here
Parse.initialize(this, "ui3OHYCLF4wlTNZcbkPhRkiEN4yiURuRZxYnXMSX", "J60b54ajmUuDk7wu94GmX3DpBbJOrv5IzSuRd5V2");
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
// If you would like all objects to be private by default, remove this
// line.
defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.androidhive.listviewfeed"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission
android:name="info.androidhive.listviewfeed.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="info.androidhive.listviewfeed.permission.C2D_MESSAGE" />
<application
android:name="info.androidhive.listviewfeed.ParseApplication"
android:allowBackup="true"
android:label="@string/app_name">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Feed_Activity"></activity>
<activity android:name=".Login"></activity>
<activity android:name=".Welcome"></activity>
</application>
</manifest>
` Debug
10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: FATAL EXCEPTION: main 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: Process: info.androidhive.listviewfeed, PID: 1688 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.listviewfeed/info.androidhive.listviewfeed.Feed_Activity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.android.volley.RequestQueue info.androidhive.listviewfeed.app.AppController.getRequestQueue()' on a null object reference 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 10-31 11:00:03.570 1688-1688/info.androidhive.listvie wfeed E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:151) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5254) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:903) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.android.volley.RequestQueue info.androidhive.listviewfeed.app.AppController.getRequestQueue()' on a null object reference 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at info.androidhive.listviewfeed.Feed_Activity.onCreate(Feed_Activity.java:57) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5990) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at androi d.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:151) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5254) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at java.lang.refl ect.Method.invoke(Native Method) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 10-31 11:00:03.570 1688-1688/info.androidhive.listviewfeed E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Assuming that you only want one app and just want to use each of the activities and classes from the two merged packages, you can add all activity
declarations from the application
tag of the second package to the application
tag of the manifest
file of the first package.
Now only use the manifest
file of the first package, and change the app name and icon to whatever you like.
Hope that helps, otherwise please explain what you want to achieve in more detail.
I've fixed it by merging the ParseApplication
class into AppController
class and declaring only the AppController
as application
into the manifest
. Thank you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.