启动应用程序时,我面临以下错误。
07-03 01:47:06.218: E/AndroidRuntime(1171): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.wifidemo/com.example.wifidemo.WifiDemoActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.app.ActivityThread.access$600(ActivityThread.java:128)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.os.Handler.dispatchMessage(Handler.java:99)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.os.Looper.loop(Looper.java:137)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.app.ActivityThread.main(ActivityThread.java:4517)
07-03 01:47:06.218: E/AndroidRuntime(1171): at java.lang.reflect.Method.invokeNative(Native Method)
07-03 01:47:06.218: E/AndroidRuntime(1171): at java.lang.reflect.Method.invoke(Method.java:511)
07-03 01:47:06.218: E/AndroidRuntime(1171): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:995)
07-03 01:47:06.218: E/AndroidRuntime(1171): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
07-03 01:47:06.218: E/AndroidRuntime(1171): at dalvik.system.NativeStart.main(Native Method)
07-03 01:47:06.218: E/AndroidRuntime(1171): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
07-03 01:47:06.218: E/AndroidRuntime(1171): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-03 01:47:06.218: E/AndroidRuntime(1171): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:283)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.app.Activity.setContentView(Activity.java:1927)
07-03 01:47:06.218: E/AndroidRuntime(1171): at com.example.wifidemo.WifiDemoActivity.onCreate(WifiDemoActivity.java:31)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.app.Activity.performCreate(Activity.java:4597)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
07-03 01:47:06.218: E/AndroidRuntime(1171): ... 11 more
07-03 01:47:06.218: E/AndroidRuntime(1171): Caused by: java.lang.reflect.InvocationTargetException
07-03 01:47:06.218: E/AndroidRuntime(1171): at java.lang.reflect.Constructor.constructNative(Native Method)
07-03 01:47:06.218: E/AndroidRuntime(1171): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
07-03 01:47:06.218: E/AndroidRuntime(1171): ... 23 more
07-03 01:47:06.218: E/AndroidRuntime(1171): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060000 a=-1 r=0x7f060000}
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.content.res.Resources.loadDrawable(Resources.java:1936)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.view.View.<init>(View.java:2867)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.view.View.<init>(View.java:2804)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.view.ViewGroup.<init>(ViewGroup.java:696)
07-03 01:47:06.218: E/AndroidRuntime(1171): at android.widget.RelativeLayout.<init>(RelativeLayout.java:174)
我已经清理并构建了项目,但仍然存在异常。
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"
android:background="@style/AppBaseTheme"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".WifiDemoActivity" >
<TextView
android:id="@+id/tv_wifi_statustext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Wifi Status" />
<ProgressBar
android:id="@+id/scan_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tv_wifi_statustext"
android:layout_alignRight="@+id/button_scan"
android:layout_below="@+id/button_wifi_on_off"
android:layout_marginTop="20dp" />
<ToggleButton
android:id="@+id/button_wifi_on_off"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/tv_wifi_statustext"
android:layout_marginLeft="70dp"
android:layout_toRightOf="@+id/tv_wifi_statustext"
android:text="Off" />
<Button
android:id="@+id/button_scan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/button_wifi_on_off"
android:layout_toRightOf="@+id/button_wifi_on_off"
android:text="@string/Scan" />
<TextView
android:id="@+id/txt_status"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignLeft="@+id/scan_bar"
android:layout_alignRight="@+id/scan_bar"
android:layout_below="@+id/scan_bar"
android:layout_marginTop="20dp"/>
</RelativeLayout>
活动部分
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wifi_demo);
initializeView();
initializeListener();
}
private void initializeListener() {
wifistatelistener = new WifistateListener();
wifi_ONOFF.setOnCheckedChangeListener(wifistatelistener);
}
private void initializeView() {
wifi_ONOFF = (ToggleButton) findViewById(R.id.button_wifi_on_off);
button_wifiscan = (Button) findViewById(R.id.button_scan);
wifiscanprogressBar = (ProgressBar) findViewById(R.id.scan_bar);
status = (TextView) findViewById(R.id.txt_status);
}
答案 0 :(得分:0)
我相信,这是罪魁祸首:
android:background="@style/AppBaseTheme"
android:background
期待一些抽奖,风格显然不是它想要的。
我不知道AppBaseTheme
包含什么,所以我不能确切地说明在你的情况下解决这个问题的最佳方法是什么,但我有一些建议。最简单的方法是简单地将背景设置为一些显式图像。更复杂的解决方案是在主题中声明属性,将主题应用于应用程序或活动(如果尚未应用),并使用?attr/
语法引用此属性。