你好所有我的activity不会启动,因为一些原因,我有麻烦弄清楚,这是一个简单的应用程序,它启动和显示这个布局,但我不断得到错误,每次我启动它,我不知道为什么
xml代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".HomeActivity"
tools:showIn="@layout/app_bar_home">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/back">
<ImageView
android:id="@+id/btnTraining"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerInParent="true"
android:src="@drawable/play" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="horizontal">
<info.hoang8f.widget.FButton
android:id="@+id/btnExercises"
android:text="Exercises"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:textColor="@color/white"
app:buttonColor="@color/colorPrimary"
app:shadowColor="@color/colorPrimaryDark"
app:shadowEnabled="true"
app:cornerRadius="2dp"
app:shadowHeight="2dp" />
<info.hoang8f.widget.FButton
android:id="@+id/btnSetting"
android:text="Setting"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="8dp"
android:layout_weight="1"
android:textColor="@color/white"
app:buttonColor="@color/colorPrimary"
app:shadowColor="@color/colorPrimaryDark"
app:shadowEnabled="true"
app:cornerRadius="2dp"
app:shadowHeight="2dp" />
</LinearLayout>
<info.hoang8f.widget.FButton
android:id="@+id/btnCalender"
android:text="Calender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="4dp"
android:layout_marginTop="8dp"
android:textColor="@color/white"
app:buttonColor="@color/colorPrimary"
app:shadowColor="@color/colorPrimaryDark"
app:shadowEnabled="true"
app:cornerRadius="0dp"
app:shadowHeight="2dp" />
</LinearLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Java电码
package com.example.kishorsinh.yogaapp;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
public class HomeActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
Button btnExercises,btnSetting,btnCalender;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
btnExercises =(Button)findViewById(R.id.btnExercises);
btnExercises.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(HomeActivity.this,ListExercises.class);
startActivity(intent);
}
});
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home_activity, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
//if (id == R.id.action_settings) {
//return true;
// }
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_instructions) {
// Handle the camera action
} else if (id == R.id.nav_benefits) {
}else if (id == R.id.nav_share) {
} else if (id == R.id.nav_about) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
分级
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.kishorsinh.yogaapp"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//Library
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'info.hoang8f:fbutton:1.0.5'
}
Gradle版本3.1.3
错误
java.lang.RuntimeException:无法启动activity组件Info{com.example.kishorsinh.yogaapp/com.example.kishorsinh.yogaapp.HomeActivity}:Android.View.InflateException:二进制XML文件行#11:二进制XML文件行#36:在Android.app.activitythread.PerformLaunchActivity(ActivityThread.java:2984)在Android.app.activityThread.HandleLaunchActivity(ActivityThread.java:3045)在文件行#36:膨胀类Info.Hoang8f.Widget.F Button时出错,原因是:Android.View.InflateException:二进制XML文件行#36:膨胀类Info.Hoang8f.Widget.F Button时出错,原因是:java.lang.Reflect.Constructor.NewInstance0(原生方法)在java.lang.Reflect.Constructor.NewInstance0(原生方法)在Android.View.LayoutInflater.CreateView(LayoutInflater.CreateView(ndroid.view.LayoutInflater.rInflateChildren(LayoutInflater.Java:828)在Android.view.LayoutInflater.ParseInclude(LayoutInflater.Java:1011)在Android.view.LayoutInflater.rInflateChildren(LayoutInflater.Java:861)在Android.view.LayoutInflater.rInflateChildren(LayoutInflater.Java:828)在A:26)在Android.app.Activity.PerformCreate(Activity.java:6956)在Android.app.Instrumentation.CallActivityCreate(Instrumentation.java:1126)在Android.app.ActivityThread.PerformLaunchActivity(ActivityThread.java:2927)在Android.app.ActivityThread.HandleLaunchActivity(ActivityThread.java:3045)在Android.app.ActivityThread.-Wrap14(ActivityThread.java)在Android.app.ActivityThread$H.ton.java:116)在info.hoang8f.widget.fbutton。(fbutton.java:52)...37更多
您的color.xml
文件可能有问题
从错误日志中
原因:java.lang.UnsupportedOperationException:无法将索引%1处的值转换为颜色:在Android.Content.Res.TypedArray.GetColor(TypedArray.java:480)处的Type=0x5
一开始,你的颜色值好像是错的
删除此
实现“info.hoang8f:fbutton:1.0.5”
<info.hoang8f.widget.FButton
android:id="@+id/btnCalender"
android:text="Calender"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="4dp"
android:layout_marginTop="8dp"
android:textColor="@color/white"
app:buttonColor="@color/colorPrimary"
app:shadowColor="@color/colorPrimaryDark"
app:shadowEnabled="true"
app:cornerRadius="0dp"
app:shadowHeight="2dp" />
可能是您没有在应用程序gradle中添加以下依赖项:compile'info.hoang8f:fbutton:1.0.5'
我很沮丧,我可能无法很好地解释,但基本上我试图编码一个音乐应用程序播放器,但每当我点击按钮,应用程序只是崩溃。Logcat真的帮不了什么忙,因为我不知道它出了什么问题。请帮帮我 主要活动。Java语言 } activity_main.xml: 登录。java:“ }" activity_login.xml:" 错误:
“Android.View.InflateException:二进制XML文件行#54:Error inflating class EditText”是在由于项目而完成登录屏幕并运行时生成的。我怎么解决这个?
我刚刚实现了我的第四个选项卡到我的应用程序中,已经实现了谷歌地图。在此实现之前,我的应用程序运行良好,但现在当我更改选项卡时,它会崩溃。我在这里看到过类似的问题,但没有一个有答案(实际上有这么多不同的原因和回应这个问题) 下面是fragmentshouts_maps类 查看寻呼机适配器类 这是我的错误日志
问题内容: 我按照http://www.techotopia.com/index.php/Using_Fragments_in_Android_- _A_Worked_Example上 的教程创建了一个应用程序,但出现错误。 LogCat: MainActivity.java: activity_main.xml: ToolbarFragment.java: toolbar_fragment.xm
当我点击后退按钮并返回到位置片段时,我遇到了一些问题,下面出现了一个错误: 我确实查了很多帖子,尝试了所有的解决方案,但它不起作用。似乎其他菜单项不是问题,只是这个位置页面给出了一个错误。 fragment_location.xml LocationFragment.java