0

I'm coming from : How to create jar for Android Library Project

which is an accepted answer so i assume it would work as intented. BUT :

I have a project A with a library B attached to it (Properties->Android->Library->Add)

The library B is declared as a library (Properties->Android->Library->Is library checked) and i have followed the step described by Commonsware in the original thread linked above (meaning, my classes are in a jar in my library and src folder is empty to ensure my library will not be modified like an open source one)

I have declared activities from my library B in the manifest of A. And there is no activity nor ressources with the same name in B and A.

I am using it in A like this :

Intent i = new Intent(MainActivity.this.getApplicationContext(), com.dmdsante.mydmdpost.activity.MdpMainActivity.class);
i.putExtra("access_token", "test");
startActivity(i);

And i get the following error :

06-24 14:25:49.826: E/AndroidRuntime(14778): FATAL EXCEPTION: main
06-24 14:25:49.826: E/AndroidRuntime(14778): Process: com.example.ids, PID: 14778
06-24 14:25:49.826: E/AndroidRuntime(14778): java.lang.NullPointerException
06-24 14:25:49.826: E/AndroidRuntime(14778): at com.dmdsante.mydmdpost.activity.MdpMainActivity$GetConfig.onPostExecute(MdpMainActivity.java:303)
06-24 14:25:49.826: E/AndroidRuntime(14778): at com.dmdsante.mydmdpost.activity.MdpMainActivity$GetConfig.onPostExecute(MdpMainActivity.java:1)
06-24 14:25:49.826: E/AndroidRuntime(14778): at android.os.AsyncTask.finish(AsyncTask.java:632)
06-24 14:25:49.826: E/AndroidRuntime(14778): at android.os.AsyncTask.access$600(AsyncTask.java:177)
06-24 14:25:49.826: E/AndroidRuntime(14778): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
06-24 14:25:49.826: E/AndroidRuntime(14778): at android.os.Handler.dispatchMessage(Handler.java:102)
06-24 14:25:49.826: E/AndroidRuntime(14778): at android.os.Looper.loop(Looper.java:136)
06-24 14:25:49.826: E/AndroidRuntime(14778): at android.app.ActivityThread.main(ActivityThread.java:5017)
06-24 14:25:49.826: E/AndroidRuntime(14778): at java.lang.reflect.Method.invokeNative(Native Method)
06-24 14:25:49.826: E/AndroidRuntime(14778): at java.lang.reflect.Method.invoke(Method.java:515)
06-24 14:25:49.826: E/AndroidRuntime(14778): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-24 14:25:49.826: E/AndroidRuntime(14778): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-24 14:25:49.826: E/AndroidRuntime(14778): at dalvik.system.NativeStart.main(Native Method)

line 303 refers to btn_devenez_evaluateur.setText("test"); in this sample of code from the library B :

setContentView(com.dmdsante.mydmdpost.R.layout.mdp_activity_main);
btn_devenez_evaluateur = (Button) findViewById(com.dmdsante.mydmdpost.R.id.btn_devenez_evaluateur);
btn_devenez_evaluateur.setText("test");

When i am using B as a library but in a classic way (meaning no jar and classes in src folder), all works fine. What am i doing wrong ?

EDIT : manifest.xml from project A :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.ids"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="19" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.GET_TASKS" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:icon="@drawable/ic_launcher"
        android:allowBackup="true"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.ids.MainActivity"
            android:launchMode="singleTask" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.dmdsante.mydmdpost.activity.MdpMainActivity"
            android:windowSoftInputMode="stateHidden" >
        </activity>
        <activity
            android:name="com.dmdsante.mydmdpost.activity.MdpSearchActivity"
            android:windowSoftInputMode="stateHidden" >
        </activity>
        <activity
            android:name="com.dmdsante.mydmdpost.listview.MdpPlatformListViewActivity"
            android:windowSoftInputMode="stateHidden" >
        </activity>
        <activity
            android:name="com.dmdsante.mydmdpost.activity.MdpLookupActivity" >
        </activity>
        <activity
            android:name="com.dmdsante.mydmdpost.activity.MdpFullScreenViewActivity" >
        </activity>
    </application>

</manifest>
Community
  • 1
  • 1
JJO
  • 31
  • 4
  • paste your manifest file of A project too. – rupesh Jun 24 '14 at 12:44
  • 2
    If you see the logs more closely, you will find that what you have done is working. However, it is the code inside the MdpMainActivity from library that is giving NullPointerExpection on line 303. – jagmohan Jun 24 '14 at 12:45
  • I have edited to add the manifest.xml – JJO Jun 24 '14 at 13:08
  • @jagmohan : I know about this. This is why i have linked line 303 of my library (i have edited this to better understanding). It seems that the layout cannot be found even if i explicitly call the layout with package name.R – JJO Jun 24 '14 at 13:10
  • It is because btn_devenez_evaluateur is null, its widget is not fetching properly – rajpara Jun 24 '14 at 13:13
  • @rajpara : Yes i know that too. How to fix it then ? because i call the layout AND the button in an explicit way so what can i do now ? – JJO Jun 24 '14 at 13:17

0 Answers0