1

I'm a having a bit of a problem trying to build an Android project in Eclipse. It seems to be a common problem but I've tried every possible solution provided by the other SO threads without getting anywhere. I am trying to use a simple class:

package qwe;

public class asd  {
    public asd() {  }
 }

Followed by typing this at the command prompt:

javac -d . -cp %classpath%;. asd.java
jar cvf asd.jar qwe

Android main activity code:

package com.example.zxc;

import android.os.Bundle;
import qwe.asd;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {

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

    TextView t = new TextView(this);
    try  {
        asd a = new asd();
    }
    catch( Throwable ex ) {
        t.setText( ex.toString() );
        setContentView( t );
    }
}  

}

I am importing the jar archive into an android project with eclipse by right clicking the libs project and adding the jar file, checking the jar in the project -> build path -> java tab, cleaning the project and then building. The compilation process does not throw any errors but i am getting a NoClassDefFoundError exception when running the app. This is just a test so that i can start working on a project with some real code but not even this simple attempt seems to give any results. What could I be missing ? Thanks.

Marius Pirvu
  • 45
  • 1
  • 1
  • 9
  • Can you post your error ? – GrIsHu Oct 16 '13 at 09:49
  • have you checked this http://stackoverflow.com/questions/2247998/noclassdeffounderror-eclipse-and-android ? – Lavanya Oct 16 '13 at 09:49
  • check your build path. there might be problem in your build path have you added the jar to the projects libs folder. Also why do you need `setContentView` twice have a textview i `activity_main.xml` initialize and then set text to it – Raghunandan Oct 16 '13 at 09:50

2 Answers2

1

Compiled for version 1.6:

javac -d . -cp %classpath%;. -source 1.6 -target 1.6 asd.java

It works now. Thanks a lot guys.

Marius Pirvu
  • 45
  • 1
  • 1
  • 9
0

First of all check your Build Path, if its fine and then also not working then right click on project-> Build path-> Configure Build path-> order and export-> Check your jar file there and make it up and clean the project and try it will work.

Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44