您好我正在创建一个外部jar文件,这是一个用于重塑文本视图的库,这里是重塑类:
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());
}
以下是我在其他项目中使用它的方法,我在那里导入了那个jar。
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");
}
但是当我发动它时,我有一个力量关闭!
这是日志:
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)
答案 0 :(得分:0)
不要扩展任何内容并在静态方法中接受Context
作为参数。
您可以执行以下操作:
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());
}
}
就您看到的错误而言,注释是正确的,因为找不到类Reshaper
,这意味着它不在类路径中。