gpt4 book ai didi

Android布局膨胀异常

转载 作者:行者123 更新时间:2023-11-29 17:51:15 26 4
gpt4 key购买 nike

我有一个应用程序在我的智能手机 (android 4.2) 上运行完美,但是当我尝试在 android 模拟器 (android 3.0) 上查看它时,它崩溃并显示:

    03-26 19:14:01.731: E/AndroidRuntime(448): FATAL EXCEPTION: main
03-26 19:14:01.731: E/AndroidRuntime(448): android.view.InflateException: Binary XML file line #48: Error inflating class Space
03-26 19:14:01.731: E/AndroidRuntime(448): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:682)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.view.LayoutInflater.rInflate(LayoutInflater.java:727)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.view.LayoutInflater.inflate(LayoutInflater.java:391)
03-26 19:14:01.731: E/AndroidRuntime(448): at com.app.appgym.FragmentRegistro2.onCreateView(FragmentRegistro2.java:47)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.os.Handler.handleCallback(Handler.java:587)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.os.Handler.dispatchMessage(Handler.java:92)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.os.Looper.loop(Looper.java:126)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.app.ActivityThread.main(ActivityThread.java:3997)
03-26 19:14:01.731: E/AndroidRuntime(448): at java.lang.reflect.Method.invokeNative(Native Method)
03-26 19:14:01.731: E/AndroidRuntime(448): at java.lang.reflect.Method.invoke(Method.java:491)
03-26 19:14:01.731: E/AndroidRuntime(448): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
03-26 19:14:01.731: E/AndroidRuntime(448): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
03-26 19:14:01.731: E/AndroidRuntime(448): at dalvik.system.NativeStart.main(Native Method)
03-26 19:14:01.731: E/AndroidRuntime(448): Caused by: java.lang.ClassNotFoundException: android.view.Space in loader dalvik.system.PathClassLoader[/data/app/com.app.appgym-2.apk]
03-26 19:14:01.731: E/AndroidRuntime(448): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:251)
03-26 19:14:01.731: E/AndroidRuntime(448): at java.lang.ClassLoader.loadClass(ClassLoader.java:548)
03-26 19:14:01.731: E/AndroidRuntime(448): at java.lang.ClassLoader.loadClass(ClassLoader.java:508)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.view.LayoutInflater.createView(LayoutInflater.java:542)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:627)
03-26 19:14:01.731: E/AndroidRuntime(448): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:644)
03-26 19:14:01.731: E/AndroidRuntime(448): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
03-26 19:14:01.731: E/AndroidRuntime(448): ... 20 more

这是 fragmentRegistro2 的布局:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.devadvance.circulartest"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:ignore="NewApi" >

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="1184dp"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >

<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/section_label"
android:layout_toRightOf="@+id/section_label"
android:src="@drawable/ic_launcher" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_launcher" />

<Button
android:id="@+id/boton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/section_label"
android:layout_alignParentRight="true"
android:layout_below="@+id/imageView2"
android:layout_marginTop="60dp"
android:text="Nombre" />

<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/boton1"
android:layout_marginRight="22dp"
android:layout_marginTop="65dp"
android:layout_toLeftOf="@+id/imageView2" />

<TextView
android:id="@+id/textonombre"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/boton1"
android:layout_below="@+id/boton1"
android:gravity="center"
android:text="@string/descpnombre"
android:textStyle="italic" />

<Button
android:id="@+id/btnEstatura"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textonombre"
android:layout_below="@+id/txtnombre"
android:layout_marginTop="26dp"
android:text="@string/estatura" />

<EditText
android:id="@+id/txtnombre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textonombre"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:ems="10" >

<requestFocus />
</EditText>

<TextView
android:id="@+id/textoaltura"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnEstatura"
android:layout_below="@+id/btnEstatura"
android:gravity="center"
android:text="@string/txtestatura"
android:textStyle="italic" />

<TextView
android:id="@+id/txtEstatura"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/seekBar1"
android:layout_toLeftOf="@+id/imageView2"
android:text="@string/altura"
android:textSize="20sp" />

<SeekBar
android:id="@+id/seekBar1"
android:layout_width="200sp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/textoaltura"
android:layout_marginTop="92dp"
android:rotation="270" />

<Button
android:id="@+id/btnMas"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textoaltura"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:text="@string/btnmas" />

<Button
android:id="@+id/btnMenos"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnMas"
android:layout_below="@+id/seekBar1"
android:layout_marginTop="19dp"
android:text="@string/btnmenos" />

<Button
android:id="@+id/btnPeso"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/seekBar1"
android:layout_below="@+id/btnMenos"
android:layout_marginTop="26dp"
android:text="@string/peso" />

<TextView
android:id="@+id/textopeso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnPeso"
android:layout_below="@+id/btnPeso"
android:gravity="center"
android:text="@string/textopeso"
android:textStyle="italic" />

<com.devadvance.circularseekbar.CircularSeekBar
android:id="@+id/circularSeekBar1"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_below="@+id/textopeso"
android:layout_centerHorizontal="true" />

<Button
android:id="@+id/btnEdad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textopeso"
android:layout_below="@+id/circularSeekBar1"
android:layout_marginTop="28dp"
android:text="@string/edad" />

<TextView
android:id="@+id/textoedad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnEdad"
android:layout_below="@+id/btnEdad"
android:gravity="center"
android:text="@string/txtedad"
android:textStyle="italic" />

<DatePicker
android:id="@+id/fechaNacimiento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textoedad"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:calendarViewShown="false" />

<EditText
android:id="@+id/pesomanual"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/circularSeekBar1"
android:layout_alignParentRight="true"
android:layout_marginBottom="46dp"
android:layout_toRightOf="@+id/circularSeekBar1"
android:ems="10"
android:inputType="numberDecimal" />

</RelativeLayout>
</ScrollView>

这是代码:

public class FragmentRegistro2  extends Fragment  {
View view;
Button btn,btn2, btn3,btn4,btnMas,btnMenos;
TextView txt,txt2,txt3,txt4,txt5;
EditText txtnombre,txtaltura,pesomanual;
SeekBar barraestatura; CircularSeekBar barrapeso;
boolean isScrollable=false,eventoscroll=false;
DatePicker fechanacimiento;
ScrollView sView;

public FragmentRegistro2() {

}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

view = inflater.inflate(R.layout.registro2, container, false);
btn=(Button)view.findViewById(R.id.boton1);
btn2=(Button)view.findViewById(R.id.btnEstatura);
btnMas=(Button)view.findViewById(R.id.btnMas);
sView = (ScrollView) view.findViewById(R.id.ScrollView01);

/* sView.setOnTouchListener(new OnTouchListener() {


@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
sView.post(new Runnable() {
@Override
public void run() {
//Toast.makeText(getActivity().getApplicationContext(),"Current Y is : "+sView.getScrollY(),Toast.LENGTH_SHORT).show();

}
});
if (isScrollable==true){
if (sView.getScrollY()>250){
// isScrollable=false;
sView.smoothScrollTo(0,250);
eventoscroll=true;
}
}
/*if(isScrollable==false && eventoscroll==true){
if (sView.getScrollY()<250){

eventoscroll=false;
isScrollable=true;}
}*/
/* return !isScrollable;
}
});*/
btnMas.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
barraestatura.setProgress(barraestatura.getProgress()+1);
}

});
btnMenos=(Button)view.findViewById(R.id.btnMenos);
btnMenos.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
barraestatura.setProgress(barraestatura.getProgress()-1);
}

});

txt=(TextView)view.findViewById(R.id.textonombre);
txt2=(TextView)view.findViewById(R.id.textoaltura);
txt3=(TextView)view.findViewById(R.id.txtEstatura);
txtnombre=(EditText)view.findViewById(R.id.txtnombre);
barraestatura=(SeekBar)view.findViewById(R.id.seekBar1);

txt.setVisibility(View.GONE);
btnMas.setVisibility(View.GONE);
btnMenos.setVisibility(View.GONE);
txt2.setVisibility(View.GONE);
txt3.setVisibility(View.GONE);
barraestatura.setVisibility(View.GONE);
barraestatura.setMax(230);
barraestatura.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
//add here your implementation
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
//add here your implementation
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {

txt3.setText(progress+" cm");
}
});
txtnombre.setVisibility(View.GONE);
btn.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(txt.getVisibility()==View.GONE){
txt.setVisibility(View.VISIBLE);
txtnombre.setVisibility(View.VISIBLE);
cerrarBotones(1);
}
else{
txt.setVisibility(View.GONE);
txtnombre.setVisibility(View.GONE);
}

}

});
btn2.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(txt2.getVisibility()==View.GONE){
txt2.setVisibility(View.VISIBLE);
txt3.setVisibility(View.VISIBLE);
btnMas.setVisibility(View.VISIBLE);
btnMenos.setVisibility(View.VISIBLE);
barraestatura.setVisibility(View.VISIBLE);
cerrarBotones(2);
}
else{
txt2.setVisibility(View.GONE);
txt3.setVisibility(View.GONE);
btnMas.setVisibility(View.GONE);
btnMenos.setVisibility(View.GONE);
barraestatura.setVisibility(View.GONE);
}

}

});

txt4=(TextView)view.findViewById(R.id.textopeso);
txt4.setVisibility(View.GONE);
pesomanual=(EditText)view.findViewById(R.id.pesomanual);
pesomanual.setVisibility(View.GONE);
pesomanual.addTextChangedListener(new TextWatcher(){
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
if(!pesomanual.getText().toString().equals("")){
int peso= (int) (Float.parseFloat(pesomanual.getText().toString())*10);
if(peso>0){
barrapeso.setProgress(peso);}}
}
});
barrapeso= (CircularSeekBar) view.findViewById(R.id.circularSeekBar1);
barrapeso.setVisibility(View.GONE);
barrapeso.setMax(1700);
barrapeso.setOnSeekBarChangeListener(new CircularSeekBarListener(){
public void onProgressChanged(CircularSeekBar circularSeekBar, int progress, boolean fromUser) {

// pesomanual.setText(barrapeso.getProgress()*.5f+"");
}

@Override
public void onStopTrackingTouch(CircularSeekBar seekBar) {
// TODO Auto-generated method stub

}

@Override
public void onStartTrackingTouch(CircularSeekBar seekBar) {
// TODO Auto-generated method stub

}});


btn3=(Button)view.findViewById(R.id.btnPeso);
btn3.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(txt4.getVisibility()==View.GONE){
txt4.setVisibility(View.VISIBLE);
barrapeso.setVisibility(View.VISIBLE);
pesomanual.setVisibility(View.VISIBLE);
isScrollable=true;
cerrarBotones(3);
}
else{
txt4.setVisibility(View.GONE);
barrapeso.setVisibility(View.GONE);
pesomanual.setVisibility(View.GONE);
sView.smoothScrollTo(0,0);
isScrollable=false;
}

}

});
txt5=(TextView)view.findViewById(R.id.textoedad);
txt5.setVisibility(View.GONE);
fechanacimiento=(DatePicker)view.findViewById(R.id.fechaNacimiento);
fechanacimiento.setVisibility(View.GONE);

btn4=(Button)view.findViewById(R.id.btnEdad);
btn4.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(txt5.getVisibility()==View.GONE){
txt5.setVisibility(View.VISIBLE);
fechanacimiento.setVisibility(View.VISIBLE);
isScrollable=true;
cerrarBotones(4);
}
else{
txt5.setVisibility(View.GONE);
fechanacimiento.setVisibility(View.GONE);
sView.smoothScrollTo(0,0);
isScrollable=false;
}

}

});

return view;
}

public void cerrarBotones(int boton){
if(boton==1){
txt2.setVisibility(View.GONE);
txt3.setVisibility(View.GONE);
btnMas.setVisibility(View.GONE);
btnMenos.setVisibility(View.GONE);
barraestatura.setVisibility(View.GONE);

txt4.setVisibility(View.GONE);
barrapeso.setVisibility(View.GONE);
pesomanual.setVisibility(View.GONE);

txt5.setVisibility(View.GONE);
fechanacimiento.setVisibility(View.GONE);
sView.smoothScrollTo(0,0);
}
if(boton==2){
txt.setVisibility(View.GONE);
txtnombre.setVisibility(View.GONE);

txt4.setVisibility(View.GONE);
barrapeso.setVisibility(View.GONE);
pesomanual.setVisibility(View.GONE);

txt5.setVisibility(View.GONE);
fechanacimiento.setVisibility(View.GONE);
sView.smoothScrollTo(0,0);
}
if(boton==3){
txt.setVisibility(View.GONE);
txtnombre.setVisibility(View.GONE);

txt2.setVisibility(View.GONE);
txt3.setVisibility(View.GONE);
btnMas.setVisibility(View.GONE);
btnMenos.setVisibility(View.GONE);
barraestatura.setVisibility(View.GONE);

txt5.setVisibility(View.GONE);
fechanacimiento.setVisibility(View.GONE);

}

if(boton==4){

txt.setVisibility(View.GONE);
txtnombre.setVisibility(View.GONE);

txt2.setVisibility(View.GONE);
txt3.setVisibility(View.GONE);
btnMas.setVisibility(View.GONE);
btnMenos.setVisibility(View.GONE);
barraestatura.setVisibility(View.GONE);

txt4.setVisibility(View.GONE);
barrapeso.setVisibility(View.GONE);
pesomanual.setVisibility(View.GONE);
}
}
}

为什么我只在模拟器上收到错误?

最佳答案

<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/boton1"
android:layout_marginRight="22dp"
android:layout_marginTop="65dp"
android:layout_toLeftOf="@+id/imageView2" />

因为空格。它是在 Android 14 中引入的,可能您的模拟器使用的是旧版本(早于 14)。由于目的是在通用布局中的组件之间创建间隙,我认为您可以使用

更改它
<View
android:layout_width="2dip"
android:layout_height="wrap_content"
android:layout_below="@+id/boton1"
android:layout_marginRight="22dp"
android:layout_marginTop="65dp"
android:layout_toLeftOf="@+id/imageView2" />

关于Android布局膨胀异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22669857/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com