0

I make the jar library in my code successfully, but in my xml file it calls

 06-08 18:55:23.715: E/AndroidRuntime(13218): java.lang.RuntimeException: Unable to start activity ComponentInfo: android.view.InflateException: Binary XML file line #6: Error inflating class android.jar.com.jjoe64.graphview.BarGraphView

exception. And the jar file is here github-jjoe64/GraphView

 06-08 19:46:22.023: E/AndroidRuntime(19764): FATAL EXCEPTION: main
06-08 19:46:22.023: E/AndroidRuntime(19764): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zxl.Timetable/com.zxl.Timetable.ui.CurriculumAllInfo}: android.view.InflateException: Binary XML file line #6: Error inflating class com.jjoe64.graphview.BarGraphView
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.app.ActivityThread.access$600(ActivityThread.java:153)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.os.Looper.loop(Looper.java:137)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.app.ActivityThread.main(ActivityThread.java:5226)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at java.lang.reflect.Method.invokeNative(Native Method)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at java.lang.reflect.Method.invoke(Method.java:511)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at dalvik.system.NativeStart.main(Native Method)
06-08 19:46:22.023: E/AndroidRuntime(19764): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class com.jjoe64.graphview.BarGraphView
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.view.LayoutInflater.createView(LayoutInflater.java:596)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.app.Activity.setContentView(Activity.java:1881)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at com.zxl.Timetable.ui.CurriculumAllInfo.onCreate(CurriculumAllInfo.java:39)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.app.Activity.performCreate(Activity.java:5104)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
06-08 19:46:22.023: E/AndroidRuntime(19764):    ... 11 more
06-08 19:46:22.023: E/AndroidRuntime(19764): Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
06-08 19:46:22.023: E/AndroidRuntime(19764):    at java.lang.Class.getConstructorOrMethod(Class.java:460)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at java.lang.Class.getConstructor(Class.java:431)
06-08 19:46:22.023: E/AndroidRuntime(19764):    at android.view.LayoutInflater.createView(LayoutInflater.java:561)
06-08 19:46:22.023: E/AndroidRuntime(19764):    ... 22 more

@jjoe64

ivanchou
  • 19
  • 4

2 Answers2

1

create a folder

libs

in your project and add that jar file in it

Right Click that jar file

-->Build path-->Add to Build Path

Bald bcs of IT
  • 892
  • 6
  • 14
0

The View that you are trying to use in the layout file needs to implement the two-parameter constructor that takes a Context and an AttributeSet, as that is the constructor used by the layout inflater. Your View does not, and hence it cannot be used in a layout XML resource.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • but the BarGraphView extends from GraphView not the View class, so it can't implement the constructor. – ivanchou Jun 08 '13 at 13:25
  • @ivanchou: Either `GraphView` itself inherits from `View` (directly or indirectly), or it does not. If it does, you can implement the constructor, though you may need to modify `GraphView` as well. If `GraphView` does not inherit from `View` (directly or indirectly), then it cannot be used in a layout resource or any sort of `View`-based UI in Android. – CommonsWare Jun 08 '13 at 13:28
  • I found another graphview on github that it extends from the lib and it implement the constructor you said. But still can't work. the link https://github.com/Kusand/GraphView – ivanchou Jun 08 '13 at 14:27
  • "06-08 21:56:03.293: E/AndroidRuntime(9683): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class com.kusand.graphview.BarGraphView " – ivanchou Jun 08 '13 at 14:28