fyales
fyales

Reputation: 64

Quote the resource of Android library

I imported an android library for my application by android studio module.However something wrong happened.I defined a custom view in my module and it use the method of getResource().Because I used the view in my application.So the context is my application context instead of my module context.So I can't get my file of Resources which is defined in my module.So what can I do to solve the problem.

//It is in my custom view in android library
TextView textView = new TextView(context);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
textView.setLayoutParams(params);
textView.setText(content);
textView.setTextSize(20);
textView.setSingleLine();
textView.setTextColor(getResources().getColor(R.color.title));
textView.setPadding(0, 70, 0, 30);
textView.setGravity(Gravity.CENTER);
this.addView(textView);

When I use the custom view in my application.It will crash when code arrive at the method of textView.setTextColor(getResources().getColor(R.color.title));

02-16 16:10:03.449  25438-25438/fyales.com.lovehistory E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: fyales.com.lovehistory, PID: 25438
    java.lang.RuntimeException: Unable to start activity ComponentInfo{fyales.com.lovehistory/fyales.com.lovehistory.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f08003d
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f08003d
            at android.content.res.Resources.getValue(Resources.java:1233)
            at android.content.res.Resources.getColor(Resources.java:887)
            at fyales.com.parser.widget.MDLayout.drawData(MDLayout.java:75)
            at fyales.com.lovehistory.fragment.DynastyListFragment.onCreateView(DynastyListFragment.java:74)
            at android.app.Fragment.performCreateView(Fragment.java:2053)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:894)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
            at android.app.BackStackRecord.run(BackStackRecord.java:833)
            at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
            at android.app.Activity.performStart(Activity.java:5948)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Any help is greatly appreciated.

Upvotes: 0

Views: 96

Answers (1)

Chirag Vaghela
Chirag Vaghela

Reputation: 141

https://play.google.com/store/apps/details?id=com.desarrollodroide.repos&hl=en

Download above app.

You surely get source code for the same

Upvotes: 1

Related Questions