我很沮丧,我可能无法很好地解释,但基本上我试图编码一个音乐应用程序播放器,但每当我点击按钮,应用程序只是崩溃。Logcat真的帮不了什么忙,因为我不知道它出了什么问题。请帮帮我
主要活动。Java语言
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.startButton);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "Proceeding to login page", Toast.LENGTH_LONG).show();
openLogIn();
}
});
}
public void openLogIn(){
Intent intent = new Intent(this, Login.class);
startActivity(intent);
}
}
activity_main.xml:
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:background="@color/black"
tools:context=".MainActivity">
<TextView
android:id="@+id/musicAppTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="112dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="112dp"
android:text="@string/apollotunes"
android:textColor="@color/white"
android:textSize="34sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="56dp"
android:layout_marginTop="35dp"
android:layout_marginEnd="57dp"
android:gravity="center"
android:text="@string/millions_of_songs_to_choose_from_n_with_no_interruptions"
android:textColor="@color/white"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView2" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="300dp"
android:layout_height="250dp"
android:layout_marginStart="55dp"
android:layout_marginTop="49dp"
android:layout_marginEnd="56dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/musicAppTitle"
app:srcCompat="@drawable/project_logo" />
<Button
android:id="@+id/startButton"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginStart="80dp"
android:layout_marginTop="64dp"
android:layout_marginEnd="81dp"
android:text="@string/let_s_get_started"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textStart" />
登录。java:“
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
TextView email = (TextView) findViewById(R.id.email);
TextView password = (TextView) findViewById(R.id.password);
Button loginbtn = (Button) findViewById(R.id.logInButton);
loginbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(email.getText().toString().equals("flanders070105@gmail.com") && password.getText().toString().equals("2202231C"))
{
Toast.makeText(Login.this, "", Toast.LENGTH_SHORT).show();
}
else
Toast.makeText(Login.this, "LOGIN FAILED", Toast.LENGTH_SHORT).show();
}
});
}
}"
activity_login.xml:"
<TextView
android:id="@+id/signInText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="83dp"
android:layout_marginTop="76dp"
android:layout_marginEnd="84dp"
android:text="Sign into your account!"
android:textColor="@color/white"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/email"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_marginStart="30dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="31dp"
android:backgroundTint="@color/white"
android:drawableLeft="@drawable/ic_baseline_email_24"
android:drawablePadding="15dp"
android:hint="Email"
android:textColorHint="@color/white"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/signInText" />
<EditText
android:id="@+id/password"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_marginStart="30dp"
android:layout_marginTop="28dp"
android:layout_marginEnd="31dp"
android:backgroundTint="@color/white"
android:drawableLeft="@drawable/ic_baseline_lock_24"
android:drawablePadding="15dp"
android:hint="Password"
android:textColorHint="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/email"
tools:textSize="20sp" />
<Button
android:id="@+id/logInButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="153dp"
android:layout_marginTop="36dp"
android:layout_marginEnd="164dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/password" />
错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.finalapollotunes/com.example.finalapollotunes.Login}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:706)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at com.example.finalapollotunes.Login.onCreate(Login.java:16)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.content.res.Resources$NotFoundException: Drawable (missing name) with resource ID #0x7f0501a5
Caused by: android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7f0501a5
at android.content.res.ResourcesImpl.getResourceName(ResourcesImpl.java:255)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:785)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:631)
at android.content.res.Resources.loadDrawable(Resources.java:897)
at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:955)
at android.content.res.TypedArray.getDrawable(TypedArray.java:930)
enter cE/AndroidRuntime: at android.view.View.<init>(View.java:5010)
at android.view.ViewGroup.<init>(ViewGroup.java:659)
at android.view.ViewGroup.<init>(ViewGroup.java:655)
at android.view.ViewGroup.<init>(ViewGroup.java:651)
at androidx.constraintlayout.widget.ConstraintLayout.<init>(ConstraintLayout.java:587)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:706)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at com.example.finalapollotunes.Login.onCreate(Login.java:16)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)ode here
你的activity_login.xml应该是这样的,你必须贴上布局标签
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:background="@color/black"
tools:context=".LoginActivity">
<TextView
android:id="@+id/signInText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="83dp"
android:layout_marginTop="76dp"
android:layout_marginEnd="84dp"
android:text="Sign into your account!"
android:textColor="@color/white"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/email"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_marginStart="30dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="31dp"
android:backgroundTint="@color/white"
android:drawableLeft="@drawable/ic_baseline_email_24"
android:drawablePadding="15dp"
android:hint="Email"
android:textColorHint="@color/white"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/signInText" />
<EditText
android:id="@+id/password"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_marginStart="30dp"
android:layout_marginTop="28dp"
android:layout_marginEnd="31dp"
android:backgroundTint="@color/white"
android:drawableLeft="@drawable/ic_baseline_lock_24"
android:drawablePadding="15dp"
android:hint="Password"
android:textColorHint="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/email"
tools:textSize="20sp" />
<Button
android:id="@+id/logInButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="153dp"
android:layout_marginTop="36dp"
android:layout_marginEnd="164dp"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/password" />
</androidx.constraintlayout.widget.ConstraintLayout>
我刚刚实现了我的第四个选项卡到我的应用程序中,已经实现了谷歌地图。在此实现之前,我的应用程序运行良好,但现在当我更改选项卡时,它会崩溃。我在这里看到过类似的问题,但没有一个有答案(实际上有这么多不同的原因和回应这个问题) 下面是fragmentshouts_maps类 查看寻呼机适配器类 这是我的错误日志
“Android.View.InflateException:二进制XML文件行#54:Error inflating class EditText”是在由于项目而完成登录屏幕并运行时生成的。我怎么解决这个?
我正在尝试遵循Maps API指南,但我已经出现此错误一段时间了。我已经尝试过: android.view.InflateException:二进制XML文件:inflating类片段错误 这是我的xml代码 这是我的主要活动
当我点击后退按钮并返回到位置片段时,我遇到了一些问题,下面出现了一个错误: 我确实查了很多帖子,尝试了所有的解决方案,但它不起作用。似乎其他菜单项不是问题,只是这个位置页面给出了一个错误。 fragment_location.xml LocationFragment.java
这里的主要问题是:上面的代码在几乎所有的设备(受刺激的设备,或者一些真实的设备)上都能顺利运行。但当我在三星S3上运行时。它注意到这个错误: 请告诉我如何修复错误,谢谢:)