0

I am new Android development and to Eclipse, which is what I am using to make my app. At the moment I have my main activity which doesn't have much on it - it just has three button. Leaving it like that the app starts up fine in the emulator.

I have also included a (JAR) library that I wrote into the project and I am wanting the main activity to implement an interface from it but when I do so the app crashes.

This is what I get from LogCat:

03-26 05:54:56.211: E/AndroidRuntime(823): FATAL EXCEPTION: main
03-26 05:54:56.211: E/AndroidRuntime(823): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.abc/com.example.abc.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.abc.MainActivity" on path: /data/app/com.example.abc-2.apk
03-26 05:54:56.211: E/AndroidRuntime(823):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
03-26 05:54:56.211: E/AndroidRuntime(823):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-26 05:54:56.211: E/AndroidRuntime(823):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-26 05:54:56.211: E/AndroidRuntime(823):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-26 05:54:56.211: E/AndroidRuntime(823):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-26 05:54:56.211: E/AndroidRuntime(823):  at android.os.Looper.loop(Looper.java:137)
03-26 05:54:56.211: E/AndroidRuntime(823):  at android.app.ActivityThread.main(ActivityThread.java:5041)
03-26 05:54:56.211: E/AndroidRuntime(823):  at java.lang.reflect.Method.invokeNative(Native Method)
03-26 05:54:56.211: E/AndroidRuntime(823):  at java.lang.reflect.Method.invoke(Method.java:511)
03-26 05:54:56.211: E/AndroidRuntime(823):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-26 05:54:56.211: E/AndroidRuntime(823):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-26 05:54:56.211: E/AndroidRuntime(823):  at dalvik.system.NativeStart.main(Native Method)
03-26 05:54:56.211: E/AndroidRuntime(823): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.abc.MainActivity" on path: /data/app/com.example.abc-2.apk
03-26 05:54:56.211: E/AndroidRuntime(823):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
03-26 05:54:56.211: E/AndroidRuntime(823):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-26 05:54:56.211: E/AndroidRuntime(823):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-26 05:54:56.211: E/AndroidRuntime(823):  at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
03-26 05:54:56.211: E/AndroidRuntime(823):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
03-26 05:54:56.211: E/AndroidRuntime(823):  ...  11 more

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.abc"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.abc.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

Activity:

import java.math.BigDecimal;
import java.util.List;
import BudgetEngine.BudgetEventHandler;
import BudgetEngine.BudgetItem;
import BudgetEngine.BudgetView;
import BudgetEngine.ExpenseGroup;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;


public class MainActivity extends Activity implements BudgetView {

    public final static String MESSAGE = "com.example.abc.MESSAGE";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


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


    @Override
    public void addBudgetEventHandler(BudgetEventHandler arg0) {
        // TODO Auto-generated method stub

    }


    @Override
    public void removeBudgetEventHandler(BudgetEventHandler arg0) {
        // TODO Auto-generated method stub

    }


    @Override
    public void setActualTotal(BigDecimal arg0) {
        // TODO Auto-generated method stub

    }


    @Override
    public void setBudgetTotal(BigDecimal arg0) {
        // TODO Auto-generated method stub

    }


    @Override
    public void setErrorMessage(String arg0) {
        // TODO Auto-generated method stub

    }


    @Override
    public void setExpenseGroups(List<ExpenseGroup> arg0) {
        // TODO Auto-generated method stub

    }


    @Override
    public void setIncomeItems(List<BudgetItem> arg0) {
        // TODO Auto-generated method stub

    } 
}

Does anyone have any ideas what might be going wrong?

Please let me know if you need any more information.

Shane Haw
  • 723
  • 9
  • 22
  • `Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.abc.MainActivity"`. Made an entry for the same in manifest?? – Raghunandan Mar 26 '14 at 06:46
  • 1
    Did you add jar to android project as here http://stackoverflow.com/questions/1334802/how-can-i-use-external-jars-in-an-android-project – Sercan Ozdemir Mar 26 '14 at 06:48
  • @SercanOzdemir to tell you the truth I can't remember how I added the JAR, it was a while ago. I will read what has been posted in your link and try that. Thanks. – Shane Haw Mar 28 '14 at 07:34
  • @SercanOzdemir I added the JAR as described there and it still gives me the same error when loading the activity on the emulator. Do you have any other ideas? – Shane Haw Apr 03 '14 at 07:49
  • @Raghunandan I have added the manifest to the quesion. – Shane Haw Apr 03 '14 at 07:49

1 Answers1

0

you probably dont want to use a jar you made just a class from another package, which you could copy and paste into your current packacge and then call, show us some code though, either the class is not declared in your manifest, or the class your trying to call is not in the right package.

do you need all the other classes in the jar? or just some?

to be more clear... the android order and export preferences can be finnicky from version to version...

Technivorous
  • 1,682
  • 2
  • 16
  • 22
  • I was really hoping to keep the code in the JAR separate from the android project. I think I have perhaps included the JAR incorrectly like suggestions above. I will investigate that further and leave including the code from the JAR as a last resort. – Shane Haw Mar 28 '14 at 07:35