Я могу сделать снимок и отобразить его в новом макете. Но когда я вернусь к своему предыдущему макету и попытаюсь сделать новое изображение, мое приложение выйдет из строя, сказав, что «камера остановлена»Ошибка приложения при попытке сделать второй снимок
Я начинаю с android. Может кто-нибудь мне помочь?
EDIT: Мое приложение разбился, потому что у меня была OnClick в моем XML
Это мой отчет о сбое:
12-18 10:06:36.000 16690-16690/groep4.multec.integration.ehb.com.camera E/AndroidRuntime: FATAL EXCEPTION: main
12-18 10:06:36.000 16690-16690/groep4.multec.integration.ehb.com.camera E/AndroidRuntime: Process: groep4.multec.integration.ehb.com.camera, PID: 16690
12-18 10:06:36.000 16690-16690/groep4.multec.integration.ehb.com.camera E/AndroidRuntime: java.lang.IllegalStateException: Could not find method sendMessage(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.widget.ImageButton with id 'buttonFoto'
12-18 10:06:36.000 16690-16690/groep4.multec.integration.ehb.com.camera E/AndroidRuntime: at android.view.View$DeclaredOnClickListener.resolveMethod(View.java:4485)
12-18 10:06:36.000 16690-16690/groep4.multec.integration.ehb.com.camera E/AndroidRuntime: at android.view.View$DeclaredOnClickListener.onClick(View.java:4449)
12-18 10:06:36.000 16690-16690/groep4.multec.integration.ehb.com.camera E/AndroidRuntime: at android.view.View.performClick(View.java:5204)
12-18 10:06:36.000 16690-16690/groep4.multec.integration.ehb.com.camera E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:21153)
12-18 10:06:36.000 16690-16690/groep4.multec.integration.ehb.com.camera E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
12-18 10:06:36.000 16690-16690/groep4.multec.integration.ehb.com.camera E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
12-18 10:06:36.000 16690-16690/groep4.multec.integration.ehb.com.camera E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
12-18 10:06:36.000 16690-16690/groep4.multec.integration.ehb.com.camera E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
12-18 10:06:36.000 16690-16690/groep4.multec.integration.ehb.com.camera E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
12-18 10:06:36.000 16690-16690/groep4.multec.integration.ehb.com.camera E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
12-18 10:06:36.000 16690-16690/groep4.multec.integration.ehb.com.camera E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Вот мой код:
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
ImageButton btnTakePhoto;
ImageView imgTakenPhoto;
private static final int CAM_REQUEST = 1313;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnTakePhoto = (ImageButton) findViewById(R.id.buttonFoto);
imgTakenPhoto = (ImageView) findViewById(R.id.genomenFoto);
btnTakePhoto.setOnClickListener(new btnTakePhotoClicker());
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == CAM_REQUEST){
setContentView(R.layout.share);
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
imgTakenPhoto = (ImageView) findViewById(R.id.genomenFoto);
imgTakenPhoto.setImageBitmap(thumbnail);
}
}
class btnTakePhotoClicker implements Button.OnClickListener {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAM_REQUEST);
}
}
//Share layout -- back button - Go back to main layout
public void ibBackToPhotograph(View v) {
setContentView(R.layout.activity_main);
}
}
пожалуйста, напишите свой отчет об ошибке – Sree
Я Editted моего поста –
Есть ли у вас какая-либо кнопка в вашей XML для buttonFoto? – Sree