0

Hi i am creating an external jar file and that is a library for reshaping a text view and here is the reshape class :

public class Reshaper extends Activity{
    public static Context co;

    public static void ReshapeTextview(TextView Textview, String fontpath) {
        Typeface tf = Typeface.createFromAsset(co.getAssets(), fontpath);
        Textview.setTypeface(tf);
        PersianReshape.reshape(Textview.getText().toString());
    } 

and here is how i use it in other project that i have imported that jar there.

public class Main extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView tv = (TextView) findViewById(R.id.textView1);
        Reshaper.ReshapeTextview(tv, "title.TTF");

    }

but when i launch it i got a force close !

and here is the log:

11-29 19:13:48.637: E/AndroidRuntime(1218): Uncaught handler: thread main exiting due to uncaught exception
11-29 19:13:48.678: E/AndroidRuntime(1218): java.lang.NoClassDefFoundError: mr.persian.reshape.Reshaper
11-29 19:13:48.678: E/AndroidRuntime(1218):     at com.example.mm.Main.onCreate(Main.java:15)
11-29 19:13:48.678: E/AndroidRuntime(1218):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-29 19:13:48.678: E/AndroidRuntime(1218):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
11-29 19:13:48.678: E/AndroidRuntime(1218):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
11-29 19:13:48.678: E/AndroidRuntime(1218):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
11-29 19:13:48.678: E/AndroidRuntime(1218):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
11-29 19:13:48.678: E/AndroidRuntime(1218):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-29 19:13:48.678: E/AndroidRuntime(1218):     at android.os.Looper.loop(Looper.java:123)
11-29 19:13:48.678: E/AndroidRuntime(1218):     at android.app.ActivityThread.main(ActivityThread.java:4363)
11-29 19:13:48.678: E/AndroidRuntime(1218):     at java.lang.reflect.Method.invokeNative(Native Method)
11-29 19:13:48.678: E/AndroidRuntime(1218):     at java.lang.reflect.Method.invoke(Method.java:521)
11-29 19:13:48.678: E/AndroidRuntime(1218):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-29 19:13:48.678: E/AndroidRuntime(1218):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-29 19:13:48.678: E/AndroidRuntime(1218):     at dalvik.system.NativeStart.main(Native Method)
Like
  • 96
  • 7
  • 1
    Reshaper doesn't need Activity's behaviour. So do not extend anything. You have other kind of problem: VM cant find Reshaper class. – Leonidos Nov 29 '13 at 16:01
  • @Leonidos I have followed this tutorial to export a jar file! http://stackoverflow.com/questions/17063826/how-to-create-jar-for-android-library-project – Like Nov 29 '13 at 16:02
  • You missed something and your jar is not in your apk or it's in wrong place ) – Leonidos Nov 29 '13 at 16:05

1 Answers1

0

Don't have it extend anything and accept a Context as a parameter in your static methods.

You can probably do something like:

public class Reshaper {
    public static void ReshapeTextview(TextView Textview, String fontpath) {
        Context co = Textview.getContext();
        ReshapeTextview(Textview, fontpath, co);
    }

    // If the Context returned is not the correct one, you can accept a context as a parameter:
    public static void ReshapeTextview(TextView Textview, String fontpath, Context co) {
        Typeface tf = Typeface.createFromAsset(co.getAssets(), fontpath);
        Textview.setTypeface(tf);
        PersianReshape.reshape(Textview.getText().toString());
    }
}

In terms of the error you are seeing, the comments are correct in that the class Reshaper is not found, which implies it's not in the classpath.

NG.
  • 22,560
  • 5
  • 55
  • 61