当我运行我的应用程序时,这只是一个通过按下按钮调用另一个应用程序的活动,我得到了这个例外。
虽然我的xml中没有这样的视图,但有关于imageview的例外情况。
以下是例外:
12-22 12:47:51.412: E/AndroidRuntime(22167): FATAL EXCEPTION: main
12-22 12:47:51.412: E/AndroidRuntime(22167): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.williamromatest.testnavigationbar/com.williamromatest.testnavigationbar.MainActivity}: android.view.InflateException: Binary XML file line #41: Error inflating class android.widget.ImageView
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.app.ActivityThread.access$1500(ActivityThread.java:121)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.os.Handler.dispatchMessage(Handler.java:99)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.os.Looper.loop(Looper.java:130)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.app.ActivityThread.main(ActivityThread.java:3701)
12-22 12:47:51.412: E/AndroidRuntime(22167): at java.lang.reflect.Method.invokeNative(Native Method)
12-22 12:47:51.412: E/AndroidRuntime(22167): at java.lang.reflect.Method.invoke(Method.java:507)
12-22 12:47:51.412: E/AndroidRuntime(22167): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
12-22 12:47:51.412: E/AndroidRuntime(22167): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
12-22 12:47:51.412: E/AndroidRuntime(22167): at dalvik.system.NativeStart.main(Native Method)
12-22 12:47:51.412: E/AndroidRuntime(22167): Caused by: android.view.InflateException: Binary XML file line #41: Error inflating class android.widget.ImageView
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
12-22 12:47:51.412: E/AndroidRuntime(22167): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-22 12:47:51.412: E/AndroidRuntime(22167): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:227)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.app.Activity.setContentView(Activity.java:1657)
12-22 12:47:51.412: E/AndroidRuntime(22167): at com.williamromatest.testnavigationbar.MainActivity.onCreate(MainActivity.java:18)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
12-22 12:47:51.412: E/AndroidRuntime(22167): ... 11 more
12-22 12:47:51.412: E/AndroidRuntime(22167): Caused by: java.lang.reflect.InvocationTargetException
12-22 12:47:51.412: E/AndroidRuntime(22167): at java.lang.reflect.Constructor.constructNative(Native Method)
12-22 12:47:51.412: E/AndroidRuntime(22167): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
12-22 12:47:51.412: E/AndroidRuntime(22167): ... 22 more
12-22 12:47:51.412: E/AndroidRuntime(22167): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f01005b a=-1}
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.content.res.Resources.loadDrawable(Resources.java:1692)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.widget.ImageView.<init>(ImageView.java:122)
12-22 12:47:51.412: E/AndroidRuntime(22167): at android.widget.ImageView.<init>(ImageView.java:112)
12-22 12:47:51.412: E/AndroidRuntime(22167): ... 25 more
这是我的代码:
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener {
Button b_button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b_button = (Button) findViewById(R.id.b_button1);
b_button.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.b_button1:
Intent intentToFirstActivity = new Intent(MainActivity.this,
FirstAcitivty.class);
startActivity(intentToFirstActivity);
break;
default:
break;
}
}
}
我的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: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=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:id="@+id/b_button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_marginTop="133dp"
android:layout_toRightOf="@+id/textView1"
android:text="Button" />
</RelativeLayout>
答案 0 :(得分:0)
您的问题似乎没有任何问题。我建议你只清理一次项目并生成让它生成R.java文件。