目前我正在学习android开发,我对Textview有一个问题,我不知道如何解决它。
07-13 10:46:00.240 16541-16541/sabo.idocs E/AndroidRuntime: FATAL EXCEPTION: main
Process: sabo.idocs, PID: 16541
android.view.InflateException: Binary XML file line #142: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at sabo.idocs.main.menu.profile.Profile.onCreateView(Profile.java:82)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2239)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1332)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1574)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1641)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:794)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2415)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2200)
at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2153)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2063)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:725)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f020053 a=-1 r=0x7f020053}
at android.content.res.Resources.loadDrawable(Resources.java:3014)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.TextView.<init>(TextView.java:1220)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:62)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:58)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1026)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1083)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:173)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at sabo.idocs.main.menu.profile.Profile.onCreateView(Profile.java:82)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2239)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1332)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1574)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1641)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:794)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2415)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2200)
at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2153)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2063)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:725)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
在这里我的Textview:
<TextView
android:id="@+id/change_icon2"
android:layout_alignTop="@+id/password_change_text"
android:layout_toEndOf="@+id/view2"
android:drawableRight="@drawable/arrow_right"
android:padding="7dp"
android:textAlignment="textEnd"
android:layout_width="match_parent"
android:layout_height="35dp" />
这是我的片段类:
public class Profile extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
private ImageView userAvatar;
private TextView userName;
private TextView passwordChange;
private EditText emailText;
private EditText mobilePhone;
private String path;
private OkHttpClient client;
private Request request;
private SwipeRefreshLayout swipeLayout;
private SharedPreferences sharedPreferences;
private RelativeLayout profileLayout;
private User user;
private static final int PICK_IMAGE_REQUEST = 0;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View profile = inflater.inflate(R.layout.profile_fragment, container, false);
profileLayout = (RelativeLayout)profile.findViewById(R.id.profile_layout);
sharedPreferences = getContext().getSharedPreferences(Constants.PROJECT, Context.MODE_PRIVATE);
Gson gson = new Gson();
String userData = sharedPreferences.getString(SingletonConstants.USER, "");
user = gson.fromJson(userData, User.class);
userAvatar = (ImageView)profile.findViewById(R.id.user_avatar);
userAvatar.setScaleType(ImageView.ScaleType.CENTER_CROP);
userName = (TextView)profile.findViewById(R.id.user_name);
emailText = (EditText)profile.findViewById(R.id.email_json);
mobilePhone = (EditText)profile.findViewById(R.id.mob_phone);
passwordChange = (TextView)profile.findViewById(R.id.change_icon2);
passwordChange.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), ProfilePassword.class);
startActivity(intent);
}
});
swipeLayout = (SwipeRefreshLayout) profile.findViewById(R.id.swipe_container_profile);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorSchemeResources(android.R.color.holo_green_dark, android.R.color.holo_blue_bright, android.R.color.holo_orange_light);
profileDefaults();
onClick();
return profile;
}
是的,我看到了question,但就我而言,它不起作用。请帮忙。
答案 0 :(得分:0)
问题是,如果您在drawable-21
中有图片,则在旧版本的Android中不会将其作为可绘图。因此,您必须从该文件夹中删除该图片并将其移至drawble
或dpi
个文件夹。
答案 1 :(得分:0)
尝试将图像从drawable文件夹移动到mipmap。这对我有用。