Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 我的实用程序类应该扩展什么?_Android_Class_Utility - Fatal编程技术网

Android 我的实用程序类应该扩展什么?

Android 我的实用程序类应该扩展什么?,android,class,utility,Android,Class,Utility,您好,我正在创建一个外部jar文件,这是一个用于重塑文本视图的库,下面是重塑类: public class Reshaper extends Activity{ public static Context co; public static void ReshapeTextview(TextView Textview, String fontpath) { Typeface tf = Typeface.createFromAsset(co.getAssets()

您好,我正在创建一个外部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)

不要让它扩展任何内容,在静态方法中接受
上下文
作为参数

您可能可以执行以下操作:

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());
    }
}

就您看到的错误而言,注释是正确的,因为找不到类
整形器
,这意味着它不在类路径中。

整形器不需要活动的行为。因此,不要扩展任何内容。您还有其他类型的问题:VM找不到整形器类。@Leonidos我按照本教程导出了jar文件!你错过了一些东西,你的罐子不在你的apk里或者它在错误的地方)你能解释一下你的答案吗?