gpt4 book ai didi

java - "Unfortunately, app has stopped"java.lang.RuntimeException : Unable to start activity ComponentInfo CAMERA APP

转载 作者:行者123 更新时间:2023-11-29 23:38:44 26 4
gpt4 key购买 nike

所以,我一直在 YouTube 上关注我们应用程序的教程,由于我对应用程序开发(自学)几乎一无所知,所以我手动输入了它,这样我就可以知道哪些行有这些代码,并且..我只是不知道当我按照视频中的所有内容(或者我可能遗漏了某些内容)进行操作时,我才知道它出了什么问题。我的应用程序无法运行。

`08-27 16:50:41.336 4192-4192/e.alasse.opencv E/MultiWindowProxy: getServiceInstance failed!
08-27 16:50:41.818 4192-4192/e.alasse.opencv E/AndroidRuntime: FATAL EXCEPTION: main
Process: e.alasse.opencv, PID: 4192
java.lang.RuntimeException: Unable to start activity ComponentInfo{e.alasse.opencv/e.alasse.opencv.OpenCamera}: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class ImageView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2572)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2654)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Caused by: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class ImageView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at e.alasse.opencv.OpenCamera.onCreate(OpenCamera.java:33)
at android.app.Activity.performCreate(Activity.java:6301)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2519)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2654) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:207) 
at android.app.ActivityThread.main(ActivityThread.java:5728) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 
Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at e.alasse.opencv.OpenCamera.onCreate(OpenCamera.java:33) 
at android.app.Activity.performCreate(Activity.java:6301) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2519) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2654) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:207) 
at android.app.ActivityThread.main(ActivityThread.java:5728) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070066
at android.content.res.Resources.getValue(Resources.java:1544)
at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:331)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:198)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:102)
at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:59)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:78)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
at android.support.v7.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:182)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at e.alasse.opencv.OpenCamera.onCreate(OpenCamera.java:33) 
at android.app.Activity.performCreate(Activity.java:6301) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2519) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2654) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488) 
at android.os.Handler.dispatchMessage(Handler.java:111) 
at android.os.Looper.loop(Looper.java:207) 
at android.app.ActivityThread.main(ActivityThread.java:5728) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) `

//OpenCamera.java 包e.alasse.opencv;

import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.media.ExifInterface;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.widget.ImageView;

import org.opencv.android.Utils;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

import java.io.IOException;

public class OpenCamera extends AppCompatActivity {


ImageView iv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_open_camera);
iv = findViewById(R.id.imageView);
}

public void openGallery(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 101);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 101 && resultCode == RESULT_OK && data != null) {
Uri imageUri = data.getData();
String path = getPath(imageUri);
loadImage(path);
displayImage(sampledImg);


}
}

private void displayImage(Mat mat)
{
Bitmap bitmap = Bitmap.createBitmap(mat.cols(),mat.rows(),Bitmap.Config.RGB_565);

//convert mat to bitmap

Utils.matToBitmap(mat, bitmap);
iv.setImageBitmap(bitmap);
}
Mat sampledImg;
private void loadImage(String path) {


Mat originalImage = Imgcodecs.imread(path);
Mat rgbImg = new Mat();

Imgproc.cvtColor(originalImage, rgbImg, Imgproc.COLOR_BGR2RGB);
Display display = getWindowManager().getDefaultDisplay();

Point size = new Point();
display.getSize(size);

int mobile_width = (int) size.x;
int mobile_height = (int) size.y;

Mat sampledImg = new Mat();

double downSampleRatio = calculateSubSimpleSize(rgbImg, mobile_width, mobile_height);
Imgproc.resize(rgbImg, sampledImg, new Size(), downSampleRatio, downSampleRatio, Imgproc.INTER_AREA);

try
{
ExifInterface exif = new ExifInterface(path);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);

switch(orientation)
{
case ExifInterface.ORIENTATION_ROTATE_90:
sampledImg = sampledImg.t();
Core.flip(sampledImg, sampledImg, 1);
break;

case ExifInterface.ORIENTATION_ROTATE_270:
sampledImg = sampledImg.t();
Core.flip(sampledImg, sampledImg, 0);
break;
}
} catch (IOException e) {
e.printStackTrace();
}

}



private double calculateSubSimpleSize(Mat src, int mobile_width, int mobile_height) {

final int width = src.width();
final int height = src.height();
double inSampleSize = 1;

if (height > mobile_height || width > mobile_width) {
//calculate ratio

final double heightRatio = (double) mobile_height / (double) height;
final double widthRatio = (double) mobile_width / (double) width;

inSampleSize = heightRatio < widthRatio ? height : width;
}

return inSampleSize;
}

private String getPath(Uri uri) {
if (uri == null) {
return null;

} else {
String projection = (MediaStore.Images.Media.DATA);
Cursor cursor = getContentResolver().query(uri, new String[]{projection}, null, null, null);
if (cursor != null) {
int col_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();

return cursor.getString(col_index);
}

}
return uri.getPath();
}
}

//activity_open_camera.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".OpenCamera">

<Button
android:id="@+id/button"
android:layout_width="351dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@color/bgcolor"
android:onClick="openGallery"
android:text="Pick Image"
android:textColor="@color/txtcolor" />

<ImageView
android:id="@+id/imageView"
android:layout_width="351dp"
android:layout_height="562dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="0dp"
android:background="@color/bgcolor"
app:srcCompat="@drawable/ic_launcher_foreground" />

// list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="e.alasse.opencv">

<uses-permission android:name="android.permission.CAMERA" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".OpenCamera">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name= ".MainActivity"/>
</application>

</manifest>

最佳答案

尝试替换以下属性

app:srcCompat="@drawable/ic_launcher_foreground" />

在你的

activity_open_camera.xml

文件位于“ImageView”元素的底部

android:src="@drawable/ic_launcher_foreground"/>

如果它有助于避免应用程序的 ANR 状态,请告诉我。

关于java - "Unfortunately, app has stopped"java.lang.RuntimeException : Unable to start activity ComponentInfo CAMERA APP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52036027/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com