android - "Could not find method in a parent or ancestor" for camera -


i newbie in android world , struggling getting camera open on click of button in app. have followed several tutorials , still not managed work.

finally have come stage can run app, , open camera activity, when click button take new picture app fails.

i have tried various tutorials out can't seem make work.

can tell me code below need make work?

i following errors:

java.lang.illegalstateexception: not find method dispatchtakepictureintent(view) in parent or ancestor context android:onclick attribute defined on view class android.support.v7.widget.appcompatbutton id 'button_add_ph'   public class cameraactivity extends activity {  imageview result; static final int request_image_capture = 1;  @override protected void oncreate(bundle savedinstancestate){     super.oncreate(savedinstancestate);     setcontentview(r.layout.camera_activity);      result = (imageview)findviewbyid(r.id.imageview1);     button takepic = (button)findviewbyid(button_add_ph);   }  public void dispatchtakepictureintent(view view) {     intent takepictureintent = new intent(mediastore.action_image_capture);     if (takepictureintent.resolveactivity(getpackagemanager()) != null) {         startactivityforresult(takepictureintent, request_image_capture);     } }  @override protected void onactivityresult(int requestcode, int resultcode, intent data) {     if (requestcode == request_image_capture && resultcode == result_ok) {         bundle extras = data.getextras();         bitmap imagebitmap = (bitmap) extras.get("data");         result.setimagebitmap(imagebitmap);     } } 

and xml

<?xml version="1.0" encoding="utf-8"?>      <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"         android:orientation="vertical" android:layout_width="match_parent"         android:layout_height="match_parent">          <relativelayout             android:layout_width="match_parent"             android:layout_height="match_parent"             android:layout_weight="0.5"             android:layout_margintop="15dp"             >              <imageview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:visibility="visible"                 android:id="@+id/imageview1"                 android:layout_centervertical="true" />         </relativelayout>          <relativelayout             android:layout_width="match_parent"             android:layout_height="match_parent"             android:layout_weight="0.5"             android:layout_margintop="10dp"             >              <relativelayout                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:id="@+id/notes"                 android:layout_centerhorizontal="true"                 android:layout_margintop="5dp">                  <textview                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:textalignment="center"                     android:text="yo - no notes added photo photo photo photo"                     android:id="@+id/textview"                     android:textsize="14dp"                     android:layout_centerhorizontal="true"                     android:maxlength="60"/>                  <button                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:id="@+id/button_edit"                     android:text="edit note"                     android:layout_below="@+id/textview"                     android:layout_centerhorizontal="true"                     android:layout_margintop="5dp"/>              </relativelayout>              <linearlayout                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_below="@+id/notes"                 android:layout_margintop="25dp">                  <button                     android:layout_width="0dip"                     android:layout_height="match_parent"                     android:layout_weight="1"                     android:id="@+id/button_add_note"                     android:text="add note"/>                  <button                     android:layout_width="0dip"                     android:layout_height="match_parent"                     android:layout_weight="1"                     android:id="@+id/button_delete"                     android:text="delete picture"/>                  <button                     android:layout_width="0dip"                     android:layout_height="match_parent"                     android:layout_weight="1"                     android:id="@+id/button_add_ph"                     android:onclick="dispatchtakepictureintent"                     android:text="take picture" />             </linearlayout>              <button                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:id="@+id/backbtn"                 android:onclick="buttononclick"                 android:text="hold dog mund"                 android:layout_alignparentbottom="true"                 android:layout_centerhorizontal="true"                 android:layout_marginbottom="10dp"/>          </relativelayout>     </linearlayout> 

and manifest

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.europcar.mob1exam">      <uses-feature android:name="android.hardware.camera2" android:required="true"/>     <uses-permission android:name="android.permission.write_external_storage" />      <application         android:allowbackup="true"         android:icon="@mipmap/iconfaetter"         android:label="@string/app_name"         android:supportsrtl="true"         android:theme="@style/apptheme">         <activity android:name=".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>         <activity android:name=".cameraactivity">          </activity>     </application>  </manifest> 

thanks lot in advance


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -