我正在尝试在Android Studio中创建一个应用程序,该应用程序根据从一组4个Seek Bars(每个RGBA值一个)收集的RGBA值更改框的颜色。
目前我已将其设置为每个搜索栏的数值实时显示在条形图下方。
我没有接触到将条形连接到除下面文本之外的任何东西的部分。它的工作就像一个魅力,直到我去添加一个ImageButton混合(通过设计视图),突然间我不断收到以下错误:
06-08 00:24:59.004 1581-1581/edu.ggc.tkeating.grizzlycolorsapptkeating E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.ggc.tkeating.grizzlycolorsapptkeating/edu.ggc.tkeating.grizzlycolorsapptkeating.MainActivity}: android.view.InflateException: Binary XML file line #87: Error inflating class TextView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #87: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at edu.ggc.tkeating.grizzlycolorsapptkeating.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/color/abc_search_url_text.xml from drawable resource ID #0x7f0b004e
at android.content.res.Resources.loadDrawable(Resources.java:1953)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.<init>(View.java:3330)
at android.widget.TextView.<init>(TextView.java:583)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:60)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:56)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:980)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1039)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:675)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at edu.ggc.tkeating.grizzlycolorsapptkeating.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #18: <item> tag requires a 'drawable' attribute or child tag defining a drawable
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:178)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:885)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:822)
at android.content.res.Resources.loadDrawable(Resources.java:1950)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.<init>(View.java:3330)
at android.widget.TextView.<init>(TextView.java:583)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:60)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:56)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:980)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1039)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:675)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:830)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:736)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at edu.ggc.tkeating.grizzlycolorsapptkeating.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
现在我已经全神贯注地寻找解决方案了,我在StackOverflow和其他一些网站上发现了几个类似的问题,但似乎没有任何工作。我不确定我的代码是不是太笨重或什么。我检查了android.view.InflateException中引用的XML文件:二进制XML文件行#87“错误,但这是在我自己没有触及的自动生成的类中
这是在我的content_main.xml文件中给我带来麻烦的TextView
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/textViewAlphaProg"
android:layout_below="@+id/seekBarAlpha"
android:layout_centerHorizontal="true"
android:background="@color/abc_search_url_text"/>
这是我相当冗长的MainActivity.java
package edu.ggc.tkeating.grizzlycolorsapptkeating;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.SeekBar;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private static SeekBar seek_bar_red;
private static SeekBar seek_bar_blue;
private static TextView text_view_red;
private static TextView text_view_blue;
private static SeekBar seek_bar_green;
private static TextView text_view_green;
private static SeekBar seek_bar_alpha;
private static TextView text_view_alpha;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//start seekbar methods
seekbarred();
seekbarblue();
seekbargreen();
seekbaralpha();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
public void seekbarred() {
//Red Value
seek_bar_red = (SeekBar) findViewById(R.id.seekBarRed);
text_view_red = (TextView) findViewById(R.id.textViewRedProg);
text_view_red.setText("Red Value : " + seek_bar_red.getProgress() + " of " + seek_bar_red.getMax());
seek_bar_red.setOnSeekBarChangeListener(
new SeekBar.OnSeekBarChangeListener() {
int progress_value_red;
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress_value_red = progress;
text_view_red.setText("Red Value : " + progress + " of " + seek_bar_red
.getMax
());
//Toast.makeText(MainActivity.this, "SeekBar in Progress", Toast
//.LENGTH_LONG).show();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
/*Toast.makeText(MainActivity.this, "SeekBar in StartTracking", Toast
.LENGTH_LONG).show();*/
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
/*text_view.setText("Value : " + progress_value + " of " + seek_bar.getMax());
Toast.makeText(MainActivity.this, "SeekBar in StopTracking", Toast
.LENGTH_LONG).show();*/
}
}
);
}
public void seekbarblue() {
//blue Value
seek_bar_blue = (SeekBar) findViewById(R.id.seekBarBlue);
text_view_blue = (TextView) findViewById(R.id.textViewBlueProg);
text_view_blue.setText("Blue Value : " + seek_bar_blue.getProgress() + " of " +
seek_bar_blue
.getMax());
seek_bar_blue.setOnSeekBarChangeListener(
new SeekBar.OnSeekBarChangeListener() {
int progress_value_blue;
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress_value_blue = progress;
text_view_blue.setText("Blue Value : " + progress + " of " + seek_bar_blue
.getMax
());
//Toast.makeText(MainActivity.this, "SeekBar in Progress", Toast
//.LENGTH_LONG).show();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
/*Toast.makeText(MainActivity.this, "SeekBar in StartTracking", Toast
.LENGTH_LONG).show();*/
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
/*text_view.setText("Value : " + progress_value + " of " + seek_bar.getMax());
Toast.makeText(MainActivity.this, "SeekBar in StopTracking", Toast
.LENGTH_LONG).show();*/
}
}
);
}
public void seekbargreen() {
//Green Value
seek_bar_green = (SeekBar) findViewById(R.id.seekBarGreen);
text_view_green = (TextView) findViewById(R.id.textViewGreenProg);
text_view_green.setText("Green Value : " + seek_bar_green.getProgress() + " of " +
seek_bar_green.getMax());
seek_bar_green.setOnSeekBarChangeListener(
new SeekBar.OnSeekBarChangeListener() {
int progress_value_green;
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress_value_green = progress;
text_view_green.setText("Green Value : " + progress + " of " +
seek_bar_green.getMax());
//Toast.makeText(MainActivity.this, "SeekBar in Progress", Toast
//.LENGTH_LONG).show();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
/*Toast.makeText(MainActivity.this, "SeekBar in StartTracking", Toast
.LENGTH_LONG).show();*/
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
/*text_view.setText("Value : " + progress_value + " of " + seek_bar.getMax());
Toast.makeText(MainActivity.this, "SeekBar in StopTracking", Toast
.LENGTH_LONG).show();*/
}
}
);
}
public void seekbaralpha() {
//Alpha Value
seek_bar_alpha = (SeekBar) findViewById(R.id.seekBarAlpha);
text_view_alpha = (TextView) findViewById(R.id.textViewAlphaProg);
text_view_alpha.setText("Alpha Value : " + seek_bar_alpha.getProgress() + " of " +
seek_bar_alpha.getMax());
seek_bar_alpha.setOnSeekBarChangeListener(
new SeekBar.OnSeekBarChangeListener() {
int progress_value_alpha;
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress_value_alpha = progress;
text_view_alpha.setText("Alpha Value : " + progress + " of " +
seek_bar_alpha.getMax());
//Toast.makeText(MainActivity.this, "SeekBar in Progress", Toast
//.LENGTH_LONG).show();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
/*Toast.makeText(MainActivity.this, "SeekBar in StartTracking", Toast
.LENGTH_LONG).show();*/
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
/*text_view.setText("Value : " + progress_value + " of " + seek_bar.getMax());
Toast.makeText(MainActivity.this, "SeekBar in StopTracking", Toast
.LENGTH_LONG).show();*/
}
}
);
}
}
所以,如果有人知道如何解决这个问题,那么它可以再次运行,我可以继续使用非常棒的编码。如果有人对更简单的方法执行搜索栏功能有任何建议,也会很好。
答案 0 :(得分:3)
如果查看日志,可以看到
android.content.res.Resources $ NotFoundException:来自可绘制资源ID的文件res / color / abc_search_url_text.xml#0x7f0b004e
意思是找不到color/abc_search_url_text
答案 1 :(得分:2)
检查一下。
android:background="@color/abc_search_url_text"
查看你的logcat
dalvik.system.NativeStart.main(Native Method) Caused by: android.content.res.Resources$NotFoundException: File res/color/abc_search_url_text.xml from drawable resource ID #0x7f0b004e at
答案 2 :(得分:1)
由于索尼移动的糟糕实施,我遇到了类似的问题。
尝试添加:
android:hardwareAccelerated="true"
到您的清单文件,或者只是制作minSdkVersion = 14 +。
我遇到的问题与硬件加速有关,显示给我的最后一个错误看起来就像你现在看到的那样。
有关此问题的详细信息,请参阅this。