#java #android #android-studio #compiler-errors #compilation
Вопрос:
activity_main.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"
tools:context=".MainActivity">
<TextView
android:text="From Riya"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Imageview
android:src="@drawable/party_pic"
android:layout_height="match_parent"
android:layout_width="match_parent" />
</RelativeLayout>
«ОШИБКИ»:
07/02 20:41:18: Launching 'app' on Pixel XL API 27.
App restart successful without requiring a re-install.
$ adb shell am start -n "android.example.birthdaycard/android.example.birthdaycard.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 9243 on device 'Pixel_XL_API_27 [emulator-5554]'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: android.example.birthdaycard, PID: 9243
java.lang.RuntimeException: Unable to start activity ComponentInfo{android.example.birthdaycard/android.example.birthdaycard.MainActivity}: android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class Imageview
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class Imageview
Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class Imageview
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.Imageview" on path: DexPathList[[zip file "/data/app/android.example.birthdaycard-vHuLF8O8-BA_mn_tr83zVw==/base.apk"],nativeLibraryDirectories=[/data/app/android.example.birthdaycard-vHuLF8O8-BA_mn_tr83zVw==/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:703)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
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 androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:699)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at android.example.birthdaycard.MainActivity.onCreate(MainActivity.java:12)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
MainActivity.java код
package android.example.birthdaycard;
import androidx.appcompat.app.AppCompatActivity;
import android. os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Комментарии:
1. Добро пожаловать в Stack Overflow! Вы неправильно
Imageview
набрали . Должно бытьImageView
, Java чувствительна к регистру. Когда вы получаете ошибку, подобную вашей — Не нашли класс «android.view. Imageview» , всегда дважды проверяйте свою орфографию.
Ответ №1:
Ваши View
буквы s должны присутствовать внутри чего-то ViewGroup
подобного LinearLayout
и RelativeLayout
т. Д.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="From Riya" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/party_pic" />
</LinearLayout>