Wednesday, August 8, 2012

[android-developers] Error at setting up a larger library project Android

Want to start a standalone android project with a button in another project. First made a simple main app with a button that was referring to another project with Hello World with "is Library in Preferences". All according http://developer.android.com/tools/projects/projects-eclipse.html#SettingUpLibraryProject and it worked without problems.

Did the same thing with an open soruce project (puzzle) http://code.google.com/p/androidsoft/source/browse/#svn%2Ftrunk%2Fpuzzle but get an error message in LogCat and my appa crashes when I click the button in my main app.

Guess I may have missed something in AndroidManifest.xml According to the documentation it says

Declaring library components in the manifest file: You must declare any <activity>, <service>, <receiver>, <provider>, and so on, as well as <permission>, <uses-library>.

I can compile puzzle as their own project without any problems. If the puzzle is a library will not work.


My main app with a button that will start the second project

public class AppActivity extends Activity {

Button button;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListenerOnButton();
}

public void addListenerOnButton() {

final Context context = this;

button = (Button) findViewById(R.id.button1);

button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

Intent intent = new Intent(context, org.androidsoft.games.puzzle.kids.MainActivity.class);
startActivity(intent);

}

});

}

}

AndroidManifest.xml in my main app with android:name="org.androidsoft.games.puzzle.kids.MainActivity

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

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

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".AppActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="org.androidsoft.games.puzzle.kids.MainActivity">
</activity>
</application>

</manifest>


AndroidManifest.xml in puzzle that I want to use as a library http://code.google.com/p/androidsoft/source/browse/trunk/puzzle/AndroidManifest.xml

LogCat error


08-08 12:44:31.607: E/AndroidRuntime(780): FATAL EXCEPTION: main
08-08 12:44:31.607: E/AndroidRuntime(780): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mkyong.android/org.androidsoft.games.puzzle.kids.MainActivity}: java.lang.NullPointerException
08-08 12:44:31.607: E/AndroidRuntime(780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.os.Handler.dispatchMessage(Handler.java:99)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.os.Looper.loop(Looper.java:137)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.app.ActivityThread.main(ActivityThread.java:4745)
08-08 12:44:31.607: E/AndroidRuntime(780): at java.lang.reflect.Method.invokeNative(Native Method)
08-08 12:44:31.607: E/AndroidRuntime(780): at java.lang.reflect.Method.invoke(Method.java:511)
08-08 12:44:31.607: E/AndroidRuntime(780): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-08 12:44:31.607: E/AndroidRuntime(780): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-08 12:44:31.607: E/AndroidRuntime(780): at dalvik.system.NativeStart.main(Native Method)
08-08 12:44:31.607: E/AndroidRuntime(780): Caused by: java.lang.NullPointerException
08-08 12:44:31.607: E/AndroidRuntime(780): at org.androidsoft.games.puzzle.kids.AbstractMainActivity.onCreate(AbstractMainActivity.java:81)
08-08 12:44:31.607: E/AndroidRuntime(780): at org.androidsoft.games.puzzle.kids.MainActivity.onCreate(MainActivity.java:57)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.app.Activity.performCreate(Activity.java:5008)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
08-08 12:44:31.607: E/AndroidRuntime(780): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
08-08 12:44:31.607: E/AndroidRuntime(780): ... 11 more



--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment