Cannot run HelloCpp sample on Eclipse

I am getting the error:

12-18 02:03:58.904: E/AndroidRuntime(3864): FATAL EXCEPTION: main
12-18 02:03:58.904: E/AndroidRuntime(3864): java.lang.Error: Unresolved compilation problems: 
12-18 02:03:58.904: E/AndroidRuntime(3864):     The import org.cocos2dx cannot be resolved
12-18 02:03:58.904: E/AndroidRuntime(3864):     Cocos2dxActivity cannot be resolved to a type
12-18 02:03:58.904: E/AndroidRuntime(3864):     Cocos2dxActivity cannot be resolved to a type
12-18 02:03:58.904: E/AndroidRuntime(3864):     at com.xxxxx.xxxxx.APPNAME.(APPNAME.java:26)
12-18 02:03:58.904: E/AndroidRuntime(3864):     at java.lang.Class.newInstanceImpl(Native Method)
12-18 02:03:58.904: E/AndroidRuntime(3864):     at java.lang.Class.newInstance(Class.java:1409)
12-18 02:03:58.904: E/AndroidRuntime(3864):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
12-18 02:03:58.904: E/AndroidRuntime(3864):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
12-18 02:03:58.904: E/AndroidRuntime(3864):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-18 02:03:58.904: E/AndroidRuntime(3864):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-18 02:03:58.904: E/AndroidRuntime(3864):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-18 02:03:58.904: E/AndroidRuntime(3864):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-18 02:03:58.904: E/AndroidRuntime(3864):     at android.os.Looper.loop(Looper.java:130)
12-18 02:03:58.904: E/AndroidRuntime(3864):     at android.app.ActivityThread.main(ActivityThread.java:3683)
12-18 02:03:58.904: E/AndroidRuntime(3864):     at java.lang.reflect.Method.invokeNative(Native Method)
12-18 02:03:58.904: E/AndroidRuntime(3864):     at java.lang.reflect.Method.invoke(Method.java:507)
12-18 02:03:58.904: E/AndroidRuntime(3864):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:850)
12-18 02:03:58.904: E/AndroidRuntime(3864):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
12-18 02:03:58.904: E/AndroidRuntime(3864):     at dalvik.system.NativeStart.main(Native Method)

Seems that the class Cocos2dxActivity cannot be found by Eclipse. How do I resolve this?
I also tried building using the Terminal ( via build_native.sh ) but after installing the app on my Kindle Fire, it crashes and says “The application has stopped unexpectedly.”

Im also facing the same problem. If u found the solution pls let me know. Thanks in advance.

Hi,
I think you did not attach the source code for package org.cocos2dx
Follow the below mentioned steps

  1. Inside eclipse right click on your project and go to the properties.
  2. Go to Java Build Path and click on Source tab and click on Link Source and browse to your cocos2dx folder and go to 2dx\platform\android\java\src\org
  3. Now clean your project and run it

It should solve your problem.

I’ve been having the same problem and can’t figure it out. I tried what Touch Coder said, but it only complains.

<pre> Description Resource Path Location Type The declared package "org.cocos2dx.lib" does not match the expected package "cocos2dx.lib" Cocos2dxActivity.java /HelloCpp/orgdsf/cocos2dx/lib line 24 Java Problem The declared package "org.cocos2dx.lib" does not match the expected package "cocos2dx.lib" Cocos2dxAccelerometer.java /HelloCpp/orgdsf/cocos2dx/lib line 24 Java Problem The declared package "org.cocos2dx.lib" does not match the expected package "cocos2dx.lib" Cocos2dxHelper.java /HelloCpp/orgdsf/cocos2dx/lib line 24 Java Problem The declared package "org.cocos2dx.lib" does not match the expected package "cocos2dx.lib" Cocos2dxTextInputWraper.java /HelloCpp/orgdsf/cocos2dx/lib line 24 Java Problem The declared package "org.cocos2dx.lib" does not match the expected package "cocos2dx.lib" Cocos2dxHandler.java /HelloCpp/orgdsf/cocos2dx/lib line 25 Java Problem The declared package "org.cocos2dx.lib" does not match the expected package "cocos2dx.lib" Cocos2dxTypefaces.java /HelloCpp/orgdsf/cocos2dx/lib line 24 Java Problem The declared package "org.cocos2dx.lib" does not match the expected package "cocos2dx.lib" Cocos2dxMusic.java /HelloCpp/orgdsf/cocos2dx/lib line 24 Java Problem The declared package "org.cocos2dx.lib" does not match the expected package "cocos2dx.lib" Cocos2dxEditBoxDialog.java /HelloCpp/orgdsf/cocos2dx/lib line 25 Java Problem The declared package "org.cocos2dx.lib" does not match the expected package "cocos2dx.lib" Cocos2dxSound.java /HelloCpp/orgdsf/cocos2dx/lib line 24 Java Problem The method init(Context, Cocos2dxHelper.Cocos2dxHelperListener) in the type Cocos2dxHelper is not applicable for the arguments (Cocos2dxActivity, Cocos2dxActivity) Cocos2dxActivity.java /HelloCpp/orgdsf/cocos2dx/lib line 60 Java Problem The declared package "org.cocos2dx.lib" does not match the expected package "cocos2dx.lib" Cocos2dxRenderer.java /HelloCpp/orgdsf/cocos2dx/lib line 24 Java Problem The declared package "org.cocos2dx.lib" does not match the expected package "cocos2dx.lib" Cocos2dxBitmap.java /HelloCpp/orgdsf/cocos2dx/lib line 24 Java Problem The declared package "org.cocos2dx.lib" does not match the expected package "cocos2dx.lib" Cocos2dxGLSurfaceView.java /HelloCpp/orgdsf/cocos2dx/lib line 24 Java Problem The declared package "org.cocos2dx.lib" does not match the expected package "cocos2dx.lib" Cocos2dxEditText.java /HelloCpp/orgdsf/cocos2dx/lib line 24 Java Problem </pre>

so needless to say i removed that source and i’m just keeping /src. Did any of you guys figure it out?

EDIT: Ok i managed to get it to run! I had to manually compile the HelloCpp C++ code myself (editing in where your NDK_ROOT is in the build_native.sh, like usual), did a clean and ran it.

I fixed this by attaching the cocos2dx library in the project in Eclipse.

@lance_gray how you attach the cocos2dx library in the project in Eclipse?

Hi,
I think you did not attach the source code for package org.cocos2dx
Follow the below mentioned steps

  1. Inside eclipse right click on your project and go to the properties.
  2. Go to Java Build Path and click on Source tab and click on Link Source and browse to your cocos2dx folder and go to 2dx\platform\android\java\src\org
  3. Now clean your project and run it

It should solve your problem.

courtesy @TouchCoder