android - InflateException in custom ImageView -


i'm making example rotate image this post.
i've extends imageview override ondraw , put in mainactivity. fired "inflateexception". here example code:
mimageview

public class mimageview extends imageview {      public mimageview(context context) {         super(context);         // todo auto-generated constructor stub     }      @override     protected void ondraw(canvas canvas) {         // todo auto-generated method stub         canvas.save();         canvas.rotate(45, 0, 0);         super.ondraw(canvas);         canvas.restore();     } } 

mainactivity

public class mainactivity extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         mimageview mimageview = (mimageview) findviewbyid(r.id.imageview1);     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;     }  } 

main_activity.xml

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context=".mainactivity" >        <com.example.rotatetest.mimageview         android:id="@+id/imageview1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/ic_launcher" />  </relativelayout> 

manifest

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.rotatetest"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="8"         android:targetsdkversion="17" />      <application         android:allowbackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/apptheme" >         <activity             android:name="com.example.rotatetest.mainactivity"             android:label="@string/app_name" >             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>     </application>  </manifest> 

logcat

08-16 10:21:31.820: d/androidruntime(5135): shutting down vm 08-16 10:21:31.820: w/dalvikvm(5135): threadid=1: thread exiting uncaught exception (group=0x40ab4210) 08-16 10:21:31.820: e/androidruntime(5135): fatal exception: main 08-16 10:21:31.820: e/androidruntime(5135): java.lang.runtimeexception: unable start activity componentinfo{com.example.rotatetest/com.example.rotatetest.mainactivity}: android.view.inflateexception: binary xml file line #13: error inflating class com.example.rotatetest.mimageview 08-16 10:21:31.820: e/androidruntime(5135):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2049) 08-16 10:21:31.820: e/androidruntime(5135):     @ android.app.activitythread.handlelaunchactivity(activitythread.java:2083) 08-16 10:21:31.820: e/androidruntime(5135):     @ android.app.activitythread.access$600(activitythread.java:134) 08-16 10:21:31.820: e/androidruntime(5135):     @ android.app.activitythread$h.handlemessage(activitythread.java:1233) 08-16 10:21:31.820: e/androidruntime(5135):     @ android.os.handler.dispatchmessage(handler.java:99) 08-16 10:21:31.820: e/androidruntime(5135):     @ android.os.looper.loop(looper.java:137) 08-16 10:21:31.820: e/androidruntime(5135):     @ android.app.activitythread.main(activitythread.java:4697) 08-16 10:21:31.820: e/androidruntime(5135):     @ java.lang.reflect.method.invokenative(native method) 08-16 10:21:31.820: e/androidruntime(5135):     @ java.lang.reflect.method.invoke(method.java:511) 08-16 10:21:31.820: e/androidruntime(5135):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:787) 08-16 10:21:31.820: e/androidruntime(5135):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:554) 08-16 10:21:31.820: e/androidruntime(5135):     @ dalvik.system.nativestart.main(native method) 08-16 10:21:31.820: e/androidruntime(5135): caused by: android.view.inflateexception: binary xml file line #13: error inflating class com.example.rotatetest.mimageview 08-16 10:21:31.820: e/androidruntime(5135):     @ android.view.layoutinflater.createview(layoutinflater.java:589) 08-16 10:21:31.820: e/androidruntime(5135):     @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:680) 08-16 10:21:31.820: e/androidruntime(5135):     @ android.view.layoutinflater.rinflate(layoutinflater.java:739) 08-16 10:21:31.820: e/androidruntime(5135):     @ android.view.layoutinflater.inflate(layoutinflater.java:489) 08-16 10:21:31.820: e/androidruntime(5135):     @ android.view.layoutinflater.inflate(layoutinflater.java:396) 08-16 10:21:31.820: e/androidruntime(5135):     @ android.view.layoutinflater.inflate(layoutinflater.java:352) 08-16 10:21:31.820: e/androidruntime(5135):     @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:255) 08-16 10:21:31.820: e/androidruntime(5135):     @ android.app.activity.setcontentview(activity.java:1879) 08-16 10:21:31.820: e/androidruntime(5135):     @ com.example.rotatetest.mainactivity.oncreate(mainactivity.java:15) 08-16 10:21:31.820: e/androidruntime(5135):     @ android.app.activity.performcreate(activity.java:4539) 08-16 10:21:31.820: e/androidruntime(5135):     @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1049) 08-16 10:21:31.820: e/androidruntime(5135):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2013) 08-16 10:21:31.820: e/androidruntime(5135):     ... 11 more 08-16 10:21:31.820: e/androidruntime(5135): caused by: java.lang.nosuchmethodexception: <init> [class android.content.context, interface android.util.attributeset] 08-16 10:21:31.820: e/androidruntime(5135):     @ java.lang.class.getconstructorormethod(class.java:460) 08-16 10:21:31.820: e/androidruntime(5135):     @ java.lang.class.getconstructor(class.java:431) 08-16 10:21:31.820: e/androidruntime(5135):     @ android.view.layoutinflater.createview(layoutinflater.java:561) 08-16 10:21:31.820: e/androidruntime(5135):     ... 22 more 

did wrong?

you have not implemented constructor (class android.content.context, interface android.util.attributeset) signature.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -