1

I am trying to learn android programming and I am creating an app that starts with a splash screen and loads a menu class after that. the problem is I get this exception

06-04 10:59:37.166: E/AndroidRuntime(926): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.em.example1.MENU" on path: /data/app/com.em.example1-1.apk

I understand what the exception states but I do not understand why this is happening. In my splash screen class I load the Menu activity like this

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    Thread timer = new Thread() {
        public void run() {
            try {
                sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                Intent mainApp = new Intent("com.em.example1.MENU");
                startActivity(mainApp);

            }
        }
    };
    timer.start();

and the menu class is defined in the manifest file like this

    <activity
        android:name="com.em.example1.MENU"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.em.example1.MENU" />

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

When i was loading a main activity with two buttons and a label everything was working ok. But when I changed it (inside my splash screen activity) so it would load Menu Activity it keeps giving me this error.

Thanks in advance

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
John Demetriou
  • 4,093
  • 6
  • 52
  • 88
  • 3
    and the menu class is named MENU? please post that activity too. – nano_nano Jun 04 '13 at 11:08
  • http://developer.android.com/training/articles/perf-anr.html. using sleep() inside a thread is a bad design. check the link – Raghunandan Jun 04 '13 at 11:18
  • http://stackoverflow.com/questions/16643177/changing-image-in-imageview-using-threads/16643267#16643267. for splash screen. Using splash is considered evil by some http://cyrilmottier.com/2012/05/03/splash-screens-are-evil-dont-use-them/ – Raghunandan Jun 04 '13 at 11:22
  • @StefanBeike I apologise, I will edit my post immediately – John Demetriou Jun 04 '13 at 19:53
  • @Raghunandan None of the parts above you said solve the problem dear friend. I am just learning however and I will consider the links you gave me but first I want to solve my problem – John Demetriou Jun 04 '13 at 19:54
  • @JohnDemetriou using sleep inside a thread is a bad design. and using splash screen is considered not good by some people and i posted the links to support what i suggested. http://stackoverflow.com/questions/16643177/changing-image-in-imageview-using-threads/16643267#16643267 splash using handler – Raghunandan Jun 04 '13 at 19:57
  • @StefanBeike turns out that was the problem. I guess I am too dumb, i shouldn't had capitalized Menu – John Demetriou Jun 04 '13 at 20:22

6 Answers6

3

Right click on your project goto properties. Java Build Path. Choose Order export tab. Make sure that Android Private Libraries is selected. If you have referenced library project. do the same for the library project also. Clean and Build.

Pawan Yadav
  • 1,772
  • 19
  • 17
2

Maybe you should use this:

Intent mainApp = new Intent(this,com.em.example1.MENU.class);
startActivity(mainApp);
kongo
  • 43
  • 1
  • 5
2

You may use this code, i have made some changes. it may be help u..

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    Thread timer = new Thread() {
        public void run() {
            try {
                sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                MENU.this.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        Intent mainApp = new Intent(MENU.this,com.em.example1.MENU.class);
                        MENU.this.startActivity(mainApp);
                    }
                });


            }
        }
    };
timer.start();
Mukesh Kumar Singh
  • 4,512
  • 2
  • 22
  • 30
  • If you implement Thread or HandlerThread, be sure that your UI thread does not block while waiting for the worker thread to complete—do not call Thread.wait() or Thread.sleep(). not a good design. http://developer.android.com/training/articles/perf-anr.html – Raghunandan Jun 04 '13 at 11:23
  • No enclosing instance of the type Menu is accessible in scope this is the error I get – John Demetriou Jun 04 '13 at 19:59
1

the stuff f in manifest before what you listed is what? What you are looking for is that to seee what the app package name is..

Fred Grott
  • 3,505
  • 1
  • 23
  • 18
1

Try changing this line in your manifest file.

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

And also try this thing

Try going to Project -> Properties -> Java Build Path -> Order & Export and ensure Android Private Libraries are checked for your project and for all other library projects you are using. Clean all projects afterwards and see what happens.

Nirali
  • 13,571
  • 6
  • 40
  • 53
  • so i should change from the package to a action intent main? is that your suggestion? (I am trying to understand it aswel, not just throw it in and be glad it worked) – John Demetriou Jun 04 '13 at 18:13
0

As it turns out I the error was too simple to realize...... I had the word Menu capitalized in Android Manifest in the name and not only in action name. Thanks for trying to help me everyone

John Demetriou
  • 4,093
  • 6
  • 52
  • 88