Git Product home page Git Product logo

Comments (7)

H07000223 avatar H07000223 commented on June 17, 2024

应该不存在国际化的问题具体些贴下代码以及异常

from flycotablayout.

275873859 avatar 275873859 commented on June 17, 2024

在demo中,直接将首页提取到 string中就崩溃了

from flycotablayout.

275873859 avatar 275873859 commented on June 17, 2024

FATAL EXCEPTION: main
Process: com.flyco.tablayoutsamples, PID: 15274
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.flyco.tablayoutsamples/com.flyco.tablayoutsamples.ui.CommonTabActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2126)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249)
at android.app.ActivityThread.access$800(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.content.ContextWrapper.getResources(ContextWrapper.java:89)
at android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:78)
at android.content.Context.getString(Context.java:345)
at com.flyco.tablayoutsamples.ui.CommonTabActivity.(CommonTabActivity.java:30)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2117)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2249) 
at android.app.ActivityThread.access$800(ActivityThread.java:141) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5113) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 

from flycotablayout.

H07000223 avatar H07000223 commented on June 17, 2024

这个跟TabLayout库无关.
不要在全局变量初始化中,使用getResource方法

  private String[] mTitles;
  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_common_tab);

        mTitles = new String[]{getResources().getString(R.string.xxx), ...};
}

from flycotablayout.

275873859 avatar 275873859 commented on June 17, 2024

谢谢

from flycotablayout.

tuzhao avatar tuzhao commented on June 17, 2024

为什么不能在oncreate中使用getResource()?

2016-01-06 17:50 GMT+08:00 Flyco [email protected]:

这个跟TabLayout库无关.
不要在全局变量初始化中,使用getResource方法

private String[] mTitles;
@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_common_tab);

    mTitles = new String[]{getResources().getString(R.string.xxx), ...};

}


Reply to this email directly or view it on GitHub
#7 (comment)
.

from flycotablayout.

H07000223 avatar H07000223 commented on June 17, 2024

能在oncreate中使用getResource(),不要在全局变量定义的地方使用.
此时Activity还没创建,context拿不到为null

from flycotablayout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.