我是Android SDK和Android Studio的新手,但我对编程很熟悉。我有两个活动应该链接在一起,但是无论出于什么原因,由于我的一个XML文件中与我创建的TextView对象有关的错误,我的应用程序在启动时崩溃。我不知道那是怎么回事。任何帮助表示赞赏!
我90%确信此文件是罪魁祸首。如果您认为有必要,我可以根据要求上传更多代码。下面是错误。
package com.txfbla.benjamin.fblattire; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; public class LoginActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); } public void logIn(View view){ Intent intent = new Intent(this, HomePageActivity.class); EditText editText = (EditText) findViewById(R.id.login_username); String username = editText.getText().toString(); intent.putExtra("username", username); startActivity(intent); } }
这是我要加载的活动:
package com.txfbla.benjamin.fblattire; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; public class HomePageActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home_page); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } }
这是我得到的错误:
01-09 02:16:15.144 25368-25368/com.txfbla.benjamin.fblattire E/AndroidRuntime: FATAL EXCEPTION: main Process: com.txfbla.benjamin.fblattire, PID: 25368 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.txfbla.benjamin.fblattire/com.txfbla.benjamin.fblattire.LoginActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class TextView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) at android.app.ActivityThread.access$800(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class TextView at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763) at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at android.view.LayoutInflater.inflate(LayoutInflater.java:504) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) at com.txfbla.benjamin.fblattire.LoginActivity.onCreate(LoginActivity.java:14) at android.app.Activity.performCreate(Activity.java:5933) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) at android.app.ActivityThread.access$800(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) Caused by: android.content.res.Resources$NotFoundException: File #3677A1 from drawable resource ID #0x7f060018: .xml extension required at android.content.res.Resources.loadColorStateList(Resources.java:2549) at android.content.res.TypedArray.getColorStateList(TypedArray.java:427) at android.widget.TextView.(TextView.java:987) at android.widget.TextView. (TextView.java:629) at android.support.v7.widget.AppCompatTextView. (AppCompatTextView.java:60) at android.support.v7.widget.AppCompatTextView. (AppCompatTextView.java:56) at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:92) at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:938) at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:992) at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725) at android.view.LayoutInflater.rInflate(LayoutInflater.java:806) at android.view.LayoutInflater.inflate(LayoutInflater.java:504) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) at com.txfbla.benjamin.fblattire.LoginActivity.onCreate(LoginActivity.java:14) at android.app.Activity.performCreate(Activity.java:5933) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) at android.app.ActivityThread.access$800(ActivityThread.java:144) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
capt.swag.. 6
您无法通过字符串资源设置textColor。您可以硬编码#FFFFFF之类的值,也可以将该值保存在colors.xml文件中
colors.xml
#FFFFFF
更改
至
同样,将第二个TextView textColor更改为颜色资源。
您无法通过字符串资源设置textColor。您可以硬编码#FFFFFF之类的值,也可以将该值保存在colors.xml文件中
colors.xml
#FFFFFF
更改
至
同样,将第二个TextView textColor更改为颜色资源。