Error when using activities in a child package

Asked

Viewed 105 times

0

I have a problem in my Android project on Eclipse. After implementing the functionalities, I reached a total of 10 activities and 8 other classes. From there I realized the need to structure the code and created child packages within the project package:

Estrutura do Projeto

Remembering that in order for Eclipse to display packages in this way I changed the view mode of packages to display by hierarchy.

Inside the activities package I put all the activities of the project. When saving everything and running I get the following error:

01-03 19:59:59.630: E/AndroidRuntime(361): FATAL EXCEPTION: main
01-03 19:59:59.630: E/AndroidRuntime(361): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.meu_projeto/com.example.meu_projeto.MainActivity}: java.lang.ClassNotFoundException: com.example.meu_projeto.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.meu_projeto-1.apk]
01-03 19:59:59.630: E/AndroidRuntime(361):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)

I’ve tried to make that change in Androidmanifest.xml:

Before:

   <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Then I changed this line:

android:name=".activities.MainActivity"

But it didn’t help, someone can help?

  • Place an image of the folder structure /src/

  • Okay I’ll put.

  • Ready put the image, I hope someone can answer because I have not found the solution of this yet.

  • Rename all folders with com.example.meu_projeto. in front. Example the tasks folder would be: com.example.meu_projeto.tasks

  • But they are renamed this way, the Eclipse shows that way because I put to display hierarchically.

  • You can add the full androidmanifest?

  • @Diego Felipe already solved thanks to the solution of Jackowski and with the help of your comment thank you.

Show 2 more comments

1 answer

1


Your Mainactivity class package is wrong. Change the "name" attribute of your Mainactivity class on your Androidmanifest.xml by going as follows:

Before:

<activity
    android:name=".MainActivity"
    android:label="@string/title_activity_main" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Then just change this line:

android:name="com.example.meu_projeto.activities.MainActivity"

You should apply this change to Androidmanifest.xml for all activities in the child package.

  • You mean this:.

  • @Gustavoalmeidacavalcante put in attribute android:name as Jackowski has shown that it will work.

  • @Gustavoalmeidacavalcante only shows this error? There is no other warning?

  • @Jackowski, it shows other mistakes too, but the source of the mistake is this one so I just put this one there. After the explanation in the comment of Diego Felipe I understood what you meant and when applying in my file Androidmanifest worked just do not understand why you have to put the whole address of Activity if she is only in package son, but that’s okay. The important thing is that I decided to edit your answer to be more explanatory and put as solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.