我是Android編程新手。我正在按照YouTube教程中的指南進行操作。這是我們的論文。如何在Android中調試「不幸的應用程序已停止」?
這是在MainActivity
package com.example.abrico.violatorsprofile;
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import com.kosalgeek.android.photoutil.CameraPhoto;
import com.kosalgeek.android.photoutil.ImageLoader;
import java.io.FileNotFoundException;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
private final String TAG = this.getClass().getName();
ImageView ivCamera, ivImage;
CameraPhoto cameraPhoto;
final int CAMERA_REQUEST= 23345;
DataBaseHelper myDb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myDb = new DataBaseHelper(this);
//Move to TakePhoto activity
Button btnPhoto = (Button) findViewById(R.id.btnPhoto);
btnPhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),com.example.abrico.violatorsprofile.takephoto.class);
startActivity(intent);
}
});
// Opening the camera
ivImage = (ImageView)findViewById(R.id.ivImage);
ivCamera = (ImageView)findViewById(R.id.ivCamera);
cameraPhoto = new CameraPhoto(getApplicationContext());
ivCamera.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
startActivityForResult(cameraPhoto.takePhotoIntent(), CAMERA_REQUEST);
cameraPhoto.addToGallery();
} catch (IOException e) {
Toast.makeText(getApplicationContext(),
"Some wrong while taking photos", Toast.LENGTH_SHORT).show();
}
}
});
}
@Override //* IMAGE VIEW
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode== RESULT_OK){
if(requestCode==CAMERA_REQUEST){
String photoPath = cameraPhoto.getPhotoPath();
try {
Bitmap bitmap = ImageLoader.init().from(photoPath).requestSize(200,200).getBitmap();
ivImage.setImageBitmap(bitmap);
}catch (FileNotFoundException e) {
Toast.makeText(getApplicationContext(),
"Some wrong while loading photos", Toast.LENGTH_SHORT).show();
}
Log.d(TAG, photoPath);
}
}
}
}
這是清單
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.abrico.violatorsprofile">
<uses-feature
android:name="android.hardware.camera2"
android:required="true" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".takephoto">
</activity>
</application>
</manifest>
是什麼問題?發佈logcat文件 –
發佈logcat文件 –
已發佈對不起,我新在這裏 –