Error at setting up a larger library project Android

Put your problem here if it does not fit any of the other categories.

Error at setting up a larger library project Android

Postby xtreme » Wed Aug 08, 2012 5:25 pm

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/proj ... aryProject and it worked without problems.

Did the same thing with an open soruce project (puzzle) http://code.google.com/p/androidsoft/so ... k%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

Code: Select all
    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
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.    public class AppActivity extends Activity {
  2.    
  3.         Button button;
  4.    
  5.         @Override
  6.         public void onCreate(Bundle savedInstanceState) {
  7.                 super.onCreate(savedInstanceState);
  8.                 setContentView(R.layout.main);
  9.                 addListenerOnButton();
  10.         }
  11.    
  12.         public void addListenerOnButton() {
  13.    
  14.                 final Context context = this;
  15.    
  16.                 button = (Button) findViewById(R.id.button1);
  17.    
  18.                 button.setOnClickListener(new OnClickListener() {
  19.    
  20.                         @Override
  21.                         public void onClick(View arg0) {
  22.    
  23.                                 Intent intent = new Intent(context, org.androidsoft.games.puzzle.kids.MainActivity.class);
  24.                     startActivity(intent);  
  25.    
  26.                         }
  27.    
  28.                 });
  29.    
  30.         }
  31.    
  32.     }
  33.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4

AndroidManifest.xml in my main app with android:name="org.androidsoft.games.puzzle.kids.MainActivity
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.     <?xml version="1.0" encoding="utf-8"?>
  2.     <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.        package="com.mkyong.android"
  4.        android:versionCode="1"
  5.        android:versionName="1.0" >
  6.      
  7.         <uses-sdk android:minSdkVersion="10" />
  8.      
  9.         <application
  10.            android:icon="@drawable/ic_launcher"
  11.            android:label="@string/app_name" >
  12.             <activity
  13.                android:label="@string/app_name"
  14.                android:name=".AppActivity" >
  15.                 <intent-filter >
  16.                     <action android:name="android.intent.action.MAIN" />
  17.                     <category android:name="android.intent.category.LAUNCHER" />
  18.                 </intent-filter>
  19.             </activity>
  20.             <activity
  21.               android:name="org.androidsoft.games.puzzle.kids.MainActivity">
  22.             </activity>
  23.             </application>
  24.      
  25.     </manifest>
  26.  
  27.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4

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

LogCat error



Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.     08-08 12:44:31.607: E/AndroidRuntime(780): FATAL EXCEPTION: main
  3.     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
  4.     08-08 12:44:31.607: E/AndroidRuntime(780):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
  5.     08-08 12:44:31.607: E/AndroidRuntime(780):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
  6.     08-08 12:44:31.607: E/AndroidRuntime(780):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
  7.     08-08 12:44:31.607: E/AndroidRuntime(780):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
  8.     08-08 12:44:31.607: E/AndroidRuntime(780):  at android.os.Handler.dispatchMessage(Handler.java:99)
  9.     08-08 12:44:31.607: E/AndroidRuntime(780):  at android.os.Looper.loop(Looper.java:137)
  10.     08-08 12:44:31.607: E/AndroidRuntime(780):  at android.app.ActivityThread.main(ActivityThread.java:4745)
  11.     08-08 12:44:31.607: E/AndroidRuntime(780):  at java.lang.reflect.Method.invokeNative(Native Method)
  12.     08-08 12:44:31.607: E/AndroidRuntime(780):  at java.lang.reflect.Method.invoke(Method.java:511)
  13.     08-08 12:44:31.607: E/AndroidRuntime(780):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
  14.     08-08 12:44:31.607: E/AndroidRuntime(780):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  15.     08-08 12:44:31.607: E/AndroidRuntime(780):  at dalvik.system.NativeStart.main(Native Method)
  16.     08-08 12:44:31.607: E/AndroidRuntime(780): Caused by: java.lang.NullPointerException
  17.     08-08 12:44:31.607: E/AndroidRuntime(780):  at org.androidsoft.games.puzzle.kids.AbstractMainActivity.onCreate(AbstractMainActivity.java:81)
  18.     08-08 12:44:31.607: E/AndroidRuntime(780):  at org.androidsoft.games.puzzle.kids.MainActivity.onCreate(MainActivity.java:57)
  19.     08-08 12:44:31.607: E/AndroidRuntime(780):  at android.app.Activity.performCreate(Activity.java:5008)
  20.     08-08 12:44:31.607: E/AndroidRuntime(780):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
  21.     08-08 12:44:31.607: E/AndroidRuntime(780):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
  22.     08-08 12:44:31.607: E/AndroidRuntime(780):  ... 11 more
  23.  
  24.  
  25.  
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
xtreme
Junior Developer
Junior Developer
 
Posts: 10
Joined: Fri May 14, 2010 1:12 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 14 guests