-1

I'm trying to use fragments to create a simple, persistent navigation bar. The problem is I'm getting the following Error output.

05-23 14:58:02.861: E/AndroidRuntime(882): FATAL EXCEPTION: main
05-23 14:58:02.861: E/AndroidRuntime(882): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo    {org.childrensmuseum.visittcmindy/org.childrensmuseum.visittcmindy.MainActivity}: java.lang.ClassNotFoundException: org.childrensmuseum.visittcmindy.MainActivity
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.os.Looper.loop(Looper.java:137)
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.app.ActivityThread.main(ActivityThread.java:4340)
05-23 14:58:02.861: E/AndroidRuntime(882):  at java.lang.reflect.Method.invokeNative(Native Method)
05-23 14:58:02.861: E/AndroidRuntime(882):  at java.lang.reflect.Method.invoke(Method.java:511)
05-23 14:58:02.861: E/AndroidRuntime(882):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-23 14:58:02.861: E/AndroidRuntime(882):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-23 14:58:02.861: E/AndroidRuntime(882):  at dalvik.system.NativeStart.main(Native Method)
05-23 14:58:02.861: E/AndroidRuntime(882): Caused by: java.lang.ClassNotFoundException: org.childrensmuseum.visittcmindy.MainActivity
05-23 14:58:02.861: E/AndroidRuntime(882):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
05-23 14:58:02.861: E/AndroidRuntime(882):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-23 14:58:02.861: E/AndroidRuntime(882):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
05-23 14:58:02.861: E/AndroidRuntime(882):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1870)
05-23 14:58:02.861: E/AndroidRuntime(882):  ... 11 more

My main activity looks like this:

package org.childrensmuseum.visittcmindy;

import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.ImageButton;

public class MainActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    getWindow().setFormat(PixelFormat.RGBA_8888);
    findViewById(R.id.NavigationBar).getBackground().setDither(true);
    ImageButton homeButton = (ImageButton) findViewById(R.id.home_button);
    homeButton.setColorFilter(Color.argb(255, 90, 179, 0));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}


}

My Fragment looks like this:

package org.childrensmuseum.visittcmindy;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class MainNavigation extends Fragment{

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    return inflater.inflate(R.layout.navigation_main, container, false);
}
}

Lastly my main activity xml file looks like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<ImageView 
    android:id="@+id/HomeBackground"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:contentDescription="@string/homescreen_desc"
    android:src="@drawable/homescreen"
    android:scaleType="centerCrop"
    />
<fragment android:name="org.childrensmuseum.visittcmindy.MainNavigation"
    android:id="@+id/NavigationBar"
    android:layout_gravity="bottom" />

</RelativeLayout>

What am I missing?

LoneWolfPR
  • 3,978
  • 12
  • 48
  • 84

1 Answers1

1

EDITED to try to make it a general answer to this issue (in this case, the correct answer is provided by @Raghunandan):

Humm... so your MainActivity is "lost" (ClassNotFoundException: org.childrensmuseum.visittcmindy.MainActivity):

1.- May be an Eclipse (or whatever IDE you are using) building issue. Clean your Project and rebuild it and/or restart Eclipse.

2.- It can be a problem with your Manifest file. Add your Activity in your 'AndroidManifest.xml', making sure your Package and Activity names are correctly written (check caps). An example could be:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.childrensmuseum.visittcmindy">
    <application>
        <activity android:name=".MainActivity"></activity>
    </application>
    <uses-sdk android:minSdkVersion="7" />
</manifest>

3.- Doesn't seem to be your case, but sometimes external libraries are not correctly included in the Build Path. You have to put your third party libraries in a "libs" folder and re-reference them (Right-click, properties, Java Build Path, Libraries, Add Jar...).

Shared libraries like the Maps library, which is not a part of the standard Android library, must be declared in the Android Manifest. Open the AndroidManifest.xml file and add the following as a child of the element:

<uses-library android:name="com.google.android.maps"/>

4.- @Raghunandan gives a solution here in case you've updated to Android SDK Tools Rev 22.

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.
Community
  • 1
  • 1
Alejandro Colorado
  • 6,034
  • 2
  • 28
  • 39