AndroidLocalization(如何将我的母语telugu更改为整个应用程序语言)

时间:2014-03-26 04:48:57

标签: android localization locale android-typeface

如何将我的母语telugu更改为整个应用程序语言。实际上我在下面尝试按钮以泰卢固语显示:

Typeface gautami_font = Typeface.createFromAsset(getAssets(), "gautami.ttf");
tel.setTypeface(gautami_font);

但是当我更喜欢在TabActivity指示器中显示相同的语言时,它会抛出错误。请帮我。提前谢谢。

以下是我尝试实施的完整代码。

import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

@SuppressWarnings("deprecation")
public class ActivityStart extends TabActivity {

TextView frst,scnd,thrd;

TabHost tHst;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_activity_start);
    //      frst=(TextView) findViewById(R.id.frsttxt);
    Typeface gautami_font= Typeface.createFromAsset(getAssets(), "gautami.ttf");
    frst.setTypeface(gautami_font);
    frst.setText(getString(R.string.first));


    tHst=getTabHost();
    TabSpec tSpc;

    Intent a = new Intent(this,FrameActivity.class);
    tSpc=tHst.newTabSpec("Ram").setIndicator(frst).setContent(a);

    tHst.addTab(tSpc);
    Intent b = new Intent(this,FrameActivity.class);
    tSpc=tHst.newTabSpec("").setIndicator(getResources().getString(R.string.second)).setContent(b);
    tHst.addTab(tSpc);
    Intent c = new Intent(this,FrameActivity.class);
    tSpc=tHst.newTabSpec("").setIndicator(getResources().getString(R.string.third)).setContent(c);
    tHst.addTab(tSpc);
}

}

错误:

03-26 05:57:11.649: E/AndroidRuntime(2101): FATAL EXCEPTION: main
03-26 05:57:11.649: E/AndroidRuntime(2101): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.changelanguage/com.example.changelanguage.ActivityStart}: java.lang.NullPointerException
03-26 05:57:11.649: E/AndroidRuntime(2101):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-26 05:57:11.649: E/AndroidRuntime(2101):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-26 05:57:11.649: E/AndroidRuntime(2101):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-26 05:57:11.649: E/AndroidRuntime(2101):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-26 05:57:11.649: E/AndroidRuntime(2101):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-26 05:57:11.649: E/AndroidRuntime(2101):     at android.os.Looper.loop(Looper.java:137)
03-26 05:57:11.649: E/AndroidRuntime(2101):     at android.app.ActivityThread.main(ActivityThread.java:5039)
03-26 05:57:11.649: E/AndroidRuntime(2101):     at java.lang.reflect.Method.invokeNative(Native Method)
03-26 05:57:11.649: E/AndroidRuntime(2101):     at java.lang.reflect.Method.invoke(Method.java:511)
03-26 05:57:11.649: E/AndroidRuntime(2101):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-26 05:57:11.649: E/AndroidRuntime(2101):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-26 05:57:11.649: E/AndroidRuntime(2101):     at dalvik.system.NativeStart.main(Native Method)
03-26 05:57:11.649: E/AndroidRuntime(2101): Caused by: java.lang.NullPointerException
03-26 05:57:11.649: E/AndroidRuntime(2101):     at com.example.changelanguage.ActivityStart.onCreate(ActivityStart.java:23)
03-26 05:57:11.649: E/AndroidRuntime(2101):     at android.app.Activity.performCreate(Activity.java:5104)
03-26 05:57:11.649: E/AndroidRuntime(2101):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-26 05:57:11.649: E/AndroidRuntime(2101):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-26 05:57:11.649: E/AndroidRuntime(2101):     ... 11 more

1 个答案:

答案 0 :(得分:0)

你在第23行获得NullPointerException所以你在第23行得到空值,这一行是这些行中的第23行

frst.setTypeface(gautami_font);
frst.setText(getString(R.string.first));

如果第一行的异常试图查看路径是否正确" gautami.ttf" ...它是直接复制到资产还是有任何子文件夹?

如果第二行的异常然后在行之前放置一个日志来打印getstring值...