android:layout_marginTop="10dp"不报错 但是不起作用

android:layout_width="1dip"
android:layout_height="28dp"
android:background="@color/black"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal" />

                    android:layout_marginTop="10dp"不报错 但是不起作用其他控件都起作用就view不起作用

1个回答

去掉android:layout_gravity="center_horizontal" 就可以了

qq_43889278
qq_43889278 已经处理了谢谢
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Android studio报错 view is not constrained....

content_main.xml //在两个button和LinearLayout下都有这个错误,看了半天注释,似乎是要约束组件的位置?但内层的EditText却没有这个错误,试了很多方法都没法解决 <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.ryo.myapplication.MainActivity"> <Button android:id="@+id/button3" style="@style/Widget.AppCompat.Button.Borderless" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:fadingEdge="horizontal|vertical" android:text="@string/Login_Button_1" tools:layout_editor_absoluteX="67dp" tools:layout_editor_absoluteY="503dp" /> <Button android:id="@+id/button" style="@style/Widget.AppCompat.Button.Borderless" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:fadingEdge="horizontal|vertical" android:text="@string/Login_Button" tools:layout_editor_absoluteX="227dp" tools:layout_editor_absoluteY="503dp" /> <LinearLayout android:id="@+id/Login_text1" android:layout_width="385dp" android:layout_height="164dp" android:layout_alignLeft="@+id/button" android:layout_alignStart="@+id/button" android:layout_centerVertical="true" android:layout_marginTop="-23dp" android:orientation="vertical" android:weightSum="1" app:layout_constraintTop_toTopOf="parent" tools:layout_editor_absoluteX="0dp"> <EditText android:id="@+id/editText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.40" android:ems="10" android:hint="@string/Login_UserName" android:inputType="textPersonName" /> <EditText android:id="@+id/editText2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.51" android:ems="10" android:hint="@string/Login_Password" android:inputType="textPassword" /> </LinearLayout> </android.support.constraint.ConstraintLayout>

android studio报错XML:not well-formed

< 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= "@drawable/baidi" > < ImageView android:id ="@+id/login_button" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:layout_centerHorizontal ="true" android:layout_marginTop ="50dp" android:src ="@drawable/yezizhi" /> <!--整体边框块的颜色 --> <LinearLayout android:id ="@+id/input" android:layout_width ="fill_parent" android:layout_height ="wrap_content" android:layout_below ="@id/login_button" android:layout_marginLeft ="28.0dip" android:layout_marginRight ="28.0dip" android:background ="@drawable/baidi" android:orientation ="vertical" > <!--账号框颜色--> < LinearLayout android:layout_width ="fill_parent" android:layout_height ="44.0dip" android:background ="@drawable/baidi" android:gravity ="center_vertical" android:orientation ="horizontal" > < EditText android:id ="@+id/searchEditText" android:layout_width ="0dp" android:layout_height ="fill_parent" android:layout_weight ="1" android:background ="@null" android:ems ="10" android:imeOptions ="actionDone" android:singleLine ="true" android:textSize ="16sp" android:hint="输入账户名" android:text="输入账户名"> < requestFocus /> </ EditText> </ LinearLayout> < View android:layout_width ="fill_parent" android:layout_height ="1.0px" android:layout_marginLeft ="1.0px" android:layout_marginRight ="1.0px" android:background ="#ffc0c3c4" /> <!--隐形显示文字,点击消失--> < EditText android:id ="@+id/password" android:layout_width ="fill_parent" android:layout_height ="44.0dip" android:background ="#00ffffff" android:gravity ="center_vertical" android:inputType ="textPassword" android:maxLength ="16" android:maxLines ="1" android:textColor ="#ff1d1d1d" android:textColorHint ="#ff666666" android:textSize ="16.0sp" android:hint="密码" android:text="输入密码" /> </LinearLayout > <Button android:id ="@+id/buton1" android:layout_width ="270dp" android:background ="@drawable/landi" android:paddingTop ="5.0dip" android:layout_height ="50dp" android:gravity ="center" android:textSize ="20dp" android:text = "登录" android:layout_alignBottom="@id/input" android:layout_centerHorizontal="true" /> </ RelativeLayout> 报错XML:not well-formed 错误地方在 android:layout_alignBottom="@id/input" 和 android:layout_below ="@id/login_button"

Android Studio代码哪儿有错吗?为什么运行APP老是闪退

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="180dp" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginStart="150dp" android:layout_marginLeft="150dp" android:layout_marginTop="100dp" android:text="用户登陆" android:textColor="@android:color/holo_blue_dark" android:textSize="30sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="90dp" android:orientation="horizontal"> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="@+id/editText1" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginLeft="35dp" android:layout_marginStart="35dp" android:text="用户名" android:textSize="25sp" /> <EditText android:id="@+id/editText1" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginLeft="40dp" android:layout_marginStart="40dp" android:text="" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="90dp" android:orientation="horizontal"> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="@+id/editText2" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginLeft="35dp" android:layout_marginStart="35dp" android:text="密码" android:textSize="25sp" /> <EditText android:id="@+id/editText2" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginLeft="66dp" android:layout_marginStart="66dp" android:text="" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="90dp" android:orientation="horizontal"> <Button android:id="@+id/button5" android:layout_width="100dp" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginLeft="80dp" android:layout_marginStart="80dp" android:text="登陆" /> <Button android:id="@+id/button4" android:layout_width="100dp" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginLeft="45dp" android:layout_marginStart="45dp" android:text="注册" /> </LinearLayout> </LinearLayout>

求大神指导:Activity中setText显示为null,无法正常显示内容

未报错,内容显示为null,无法正确显示获取的内容 WeatherActivity代码显示如下: public class WeatherActivity extends AppCompatActivity { public DrawerLayout drawerLayout; private Button navButton; public SwipeRefreshLayout swipeRefresh; private ScrollView weatherLayout; private TextView titleCity; private TextView titleUpdateTime; private TextView degreeText; private TextView weatherInfoText; private LinearLayout forecastLayout; private TextView aqiText; private TextView pm25Text; private TextView comfortText; private TextView carWashText; private TextView sportText; private String mWeatherId; private ImageView bingPicImg; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_weather); /** * 处理并展示Weather实体类中的数据 */ private void showWeatherInfo(Weather weather){ String cityName=weather.basic.cityName; String updateTime=weather.basic.update.updateTime.split(" ")[1]; String degree=weather.now.temperature+"℃"; String weatherInfo=weather.now.more.info; titleCity.setText(cityName); titleUpdateTime.setText(updateTime); degreeText.setText(degree); weatherInfoText.setText(weatherInfo); forecastLayout.removeAllViews(); for (Forecast forecast:weather.forecastList){ View view= LayoutInflater.from(this).inflate(R.layout.forecast_item,forecastLayout,false); TextView dataText=view.findViewById(R.id.date_text); TextView infoText=view.findViewById(R.id.info_text); TextView maxText=view.findViewById(R.id.max_text); TextView minText=view.findViewById(R.id.min_text); dataText.setText(forecast.date); infoText.setText(forecast.more.info); maxText.setText(forecast.temperature.max); minText.setText(forecast.temperature.min); forecastLayout.addView(view); } if (weather.aqi!=null){ aqiText.setText(weather.aqi.city.aqi); pm25Text.setText(weather.aqi.city.pm25); } String comfort="舒适度:"+weather.suggestion.comfort.info; String carWash="洗车指数:"+weather.suggestion.carWash.info; String sport="运动建议:"+weather.suggestion.sport.info; comfortText.setText(comfort); carWashText.setText(carWash); sportText.setText(sport); weatherLayout.setVisibility(View.VISIBLE); Intent intent=new Intent(this, AutoUpdateService.class); startService(intent); } } xml布局文件代码如下: <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:orientation="vertical" android:layout_margin="15dp" android:background="#8000" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="15dp" android:layout_marginTop="15dp" android:text="生活建议" android:textColor="#fff" android:textSize="20sp"/> <TextView android:id="@+id/comfort_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="15dp" android:textColor="#fff"/> <TextView android:id="@+id/car_wash_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="15dp" android:textColor="#fff"/> <TextView android:id="@+id/sport_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="15dp" android:textColor="#fff"/> </LinearLayout> GSON解析JSON代码如下: public class Suggestion { @SerializedName("comf") public Comfort comfort; @SerializedName("cw") public CarWash carWash; public Sport sport; public class Comfort{ @SerializedName("text") public String info; } public class CarWash{ @SerializedName("text") public String info; } public class Sport{ @SerializedName("text") public String info; } } ![显示为null](https://img-ask.csdn.net/upload/202003/25/1585103330_429160.png)

为什么运用String里的equals方法没效果?

刚写了个本地验证码,发现验证码获取的是String数组,然后用StringBuffer转换成了String,接着就用EditText里面的getText().toString获取其中的内容与转换出来的验证码进行比较,结果发现无论怎么比较结果都是false。 代码如下: private String[] res = new String[4]; private StringBuffer zhuanhuan; res = mMyView.getValidataAndSetImage(); zhuanhuan=new StringBuffer(); for (String string:res){ zhuanhuan.append(string); } //这里Toast能显示出正确的验证码 Toast.makeText(zhuce.this,zhuanhuan,Toast.LENGTH_SHORT).show(); 尝试过用Toast打印出yanzheng.getText().toString(),结果与上面的是一模一样 if ((yanzheng.getText().toString()).equals(zhuanhuan)) {} else{Toast.makeText(zhuce.this,"错误",Toast.LENGTH_SHORT).show();} 但是就不会进入if里面,直接跳过else去,想了很久都没想到哪里出问题了 EditText的XML: <EditText android:layout_width="129dp" android:inputType="number" android:ems="4" android:background="#00000000" android:id="@+id/yanzhengma" android:hint="请输入验证码" android:layout_height="33dp" android:layout_marginStart="16dp" app:layout_constraintLeft_toLeftOf="parent" android:layout_marginEnd="16dp" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/checkView" android:layout_marginTop="8dp" />

Android Studio中Invalid escape sequence at line 1 column 37 path $[0].name的问题

第一次编译成功显示,但是之后编译却报错,报了这个Invalid escape sequence at line 1 column 37 path $[0].name XML布局文档 ``` <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!--普通文字效果--> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:gravity="center" android:text="跑马灯效果,点击暂停,再点击恢复"/> <!--跑马灯效果--> <TextView android:id="@+id/pmd" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:textColor="#000000" android:textSize="17sp" android:text="2018年08月28日04时17分将暴雨蓝色预警信号升级为暴雨红色预警信号。目前五莲县的槎河已经出现超过100毫米的降水,预计今天到29日,日照市仍有雷阵雨天气,雨量分布极为不均,五莲县东北部其他地区过程降水量仍有可能会超过100毫米。请注意防范。 "/> </LinearLayout> </android.support.constraint.ConstraintLayout> ``` java文档 ``` package com.example.android.helloworld; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.TextUtils; import android.widget.TextView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } ```

Android开发行列式逆矩阵计算器Java板块有些问题如何解决?

学校作业:我想开发一个能求n阶行列式和n阶矩阵逆矩阵的计算器,xml已写是6x6的格子,想首先判断输入几阶方阵反馈n的值,就通过判断第一行到第几个格子有值决定。之后求n阶行列式值用了行列式公式,设了int p[][]的矩阵,可是不会在静态函数中给矩阵赋textview里的值,只学过p[0][0] = (EditText)this.findViewById(R.id.editText1); 此外能不能直接在公用里给p数组赋值然后复制p1来计算,(这样应该就不用在静态里赋值)但公用的我不知道放在哪里放这个头下会报错public class MainActivity extends Activity {。逆矩阵的思路是在右侧补充单位矩阵,将左侧矩阵化为单位矩阵右侧就变成逆矩阵了。可以复制一个同阶数组然后将左侧转化为单位矩阵同时对右侧做相同操作,最后在6x6文本框里输出复制的矩阵。有没有大佬可以帮助我修改一下行列式代码写一下逆矩阵代码让它能实现目标并解释一下修改的问题。谢谢谢谢了真写不动了没系统学过Java就要写这个作业,如果逆矩阵不行只有行列式部分也可吧---xml文件在这应该没有问题----------------------------------------------------Java文件在下侧是半成品但我实在不知道怎么完善了。 ``` <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" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:ems="2" android:inputType="numberDecimal" > <requestFocus /> </EditText> <EditText android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText1" android:layout_alignBottom="@+id/editText1" android:layout_toRightOf="@+id/editText1" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText2" android:layout_alignBottom="@+id/editText2" android:layout_toRightOf="@+id/editText2" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/editText3" android:layout_toRightOf="@+id/editText3" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText4" android:layout_alignBottom="@+id/editText4" android:layout_toRightOf="@+id/editText4" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText5" android:layout_alignBottom="@+id/editText5" android:layout_toRightOf="@+id/editText5" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/editText1" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText1" android:layout_toRightOf="@+id/editText1" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText8" android:layout_alignBottom="@+id/editText8" android:layout_toRightOf="@+id/editText8" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText10" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText9" android:layout_alignBottom="@+id/editText9" android:layout_toRightOf="@+id/editText9" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText10" android:layout_alignBottom="@+id/editText10" android:layout_toLeftOf="@+id/editText6" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText12" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText11" android:layout_alignBottom="@+id/editText11" android:layout_alignLeft="@+id/editText6" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText13" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/editText7" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText14" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText13" android:layout_alignBottom="@+id/editText13" android:layout_toRightOf="@+id/editText13" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText15" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText14" android:layout_alignBottom="@+id/editText14" android:layout_toRightOf="@+id/editText14" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText16" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText15" android:layout_alignBottom="@+id/editText15" android:layout_toRightOf="@+id/editText15" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText17" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText16" android:layout_alignBottom="@+id/editText16" android:layout_toLeftOf="@+id/editText12" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText18" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText17" android:layout_alignBottom="@+id/editText17" android:layout_alignLeft="@+id/editText12" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText19" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/editText13" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText20" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText19" android:layout_alignBottom="@+id/editText19" android:layout_toRightOf="@+id/editText19" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText21" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText20" android:layout_alignBottom="@+id/editText20" android:layout_toRightOf="@+id/editText20" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText22" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText21" android:layout_alignBottom="@+id/editText21" android:layout_toRightOf="@+id/editText21" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText23" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText22" android:layout_alignBottom="@+id/editText22" android:layout_toLeftOf="@+id/editText18" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText24" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText23" android:layout_alignBottom="@+id/editText23" android:layout_alignLeft="@+id/editText18" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText25" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/editText19" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText26" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText25" android:layout_alignBottom="@+id/editText25" android:layout_toRightOf="@+id/editText25" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText27" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText26" android:layout_alignBottom="@+id/editText26" android:layout_toRightOf="@+id/editText26" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText28" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText27" android:layout_alignBottom="@+id/editText27" android:layout_toRightOf="@+id/editText27" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText29" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/editText28" android:layout_toLeftOf="@+id/editText24" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText30" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText29" android:layout_alignBottom="@+id/editText29" android:layout_alignLeft="@+id/editText24" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText31" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/editText25" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText32" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText31" android:layout_alignBottom="@+id/editText31" android:layout_alignLeft="@+id/editText26" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText33" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText32" android:layout_alignBottom="@+id/editText32" android:layout_alignLeft="@+id/editText27" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText34" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText33" android:layout_alignBottom="@+id/editText33" android:layout_toRightOf="@+id/editText33" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText35" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText34" android:layout_alignBottom="@+id/editText34" android:layout_toLeftOf="@+id/editText30" android:ems="2" android:inputType="numberDecimal" /> <EditText android:id="@+id/editText36" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/editText35" android:layout_alignBottom="@+id/editText35" android:layout_alignLeft="@+id/editText30" android:ems="2" android:inputType="numberDecimal" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button1" android:layout_alignBottom="@+id/button1" android:layout_alignLeft="@+id/editText33" android:layout_toLeftOf="@+id/editText35" android:text="求逆" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button2" android:layout_alignBottom="@+id/button2" android:layout_alignLeft="@+id/editText35" android:layout_alignRight="@+id/editText36" android:text="清空" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/button2" android:layout_alignLeft="@+id/editText31" android:layout_alignRight="@+id/editText36" android:layout_alignTop="@+id/textView1" android:text="" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView2" android:layout_alignRight="@+id/editText32" android:layout_below="@+id/editText31" android:layout_marginTop="50dp" android:text="计算" android:onClick="GetValue"/> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/button1" android:layout_alignLeft="@+id/editText31" android:layout_below="@+id/editText31" android:text="TextView" /> </RelativeLayout> ``` Java文件 ``` package com.example.calculatorstrong; import com.example.calculator.R; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } p[0][0] = (EditText)this.findViewById(R.id.editText1); //直接这么赋值吗但之前在哪里定义数组p 其余省略 TextView anwser = (TextView)this.findViewById(R.id.textView2); } public static double GetValue(int p[][], int n) { if (n == 1) // 如果是一阶行列式,直接返回该元素 return p[0][0]; double sum = 0; // 累加求和变量 for (int j = 0; j < n; j++) {// 遍历最后一行各元素,p[n - 1][j] int pt = (n - 1) + j; // 符号判断指数 double[][] p1 = new double[n][n]; for (int row = 0; row < n; row++) { for (int col = 0; col < n; col++) { p1[row][col] = p[row][col]; } } for (int index = 0; index < n - 1; index++) { for (int index1 = j; index1 < n - 1; index1++) { p1[index][index1] = p1[index][index1 + 1]; } } // 此过程,截取临时数组 p1 左上角 n-1 阶行列式,提取元素 p[n-1][j] 的余子式 double[][] temp = new double[n - 1][n - 1]; for (int row = 0; row < n - 1; row++) { for (int col = 0; col < n - 1; col++) { temp[row][col] = p1[row][col]; } } sum += p[n - 1][j] * Math.pow(-1, pt) * GetValue(temp, n - 1); // System.out.println(p[n - 1][j] + " * " + Math.pow(-1, pt) + " * " + GetValue(p1, n - 1)); } return sum; } } ```

关于android R文件丢失的问题,详情请看截图

![图片说明](https://img-ask.csdn.net/upload/201710/25/1508903399_768495.jpg)网上的各种方法基本试过了搞了好久都不行,请大神指点!!!下面是布局 ``` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="fill_parent" android:layout_height="fill_parent" android:keepScreenOn="true" android:orientation="vertical" android:fitsSystemWindows="false"> <RelativeLayout android:id="@+id/cortex_scanner_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerInParent="true" android:layout_marginLeft="0dp" android:layout_marginRight="0dp" android:layout_marginTop="0dp" android:layout_marginBottom="0dp"> <!-- This view will be inserted by CortexScan.onCreate(). <com.codecorp.cortex_scan.CameraPreview /> --> <com.hongshan.myapplication.CrosshairsView android:id="@id/crosshairs_view" android:layout_width="fill_parent" android:layout_height="fill_parent" android:onClick="resetContinuousScan"/> <android.support.percent.PercentRelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <com.hongshan.myapplication.PicklistView android:id="@+id/picklist_view" android:layout_width="0dp" app:layout_widthPercent="87%" android:layout_height="24dp" android:layout_centerInParent="true" android:onClick="resetContinuousScan"/> </android.support.percent.PercentRelativeLayout> <TextView android:id="@+id/tap_to_scan_again" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="#c0000000" android:clickable="false" android:padding="10dp" android:text="@string/tap_to_scan_again" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FFFFFF" android:visibility="invisible" android:layout_centerInParent="true" /> </RelativeLayout> <ImageView android:id="@+id/code_corp_logo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:src="@drawable/code_logo" android:contentDescription="@string/code_corp_logo" android:paddingTop="10dp" /> <ImageView android:id="@+id/settingsButton" android:layout_width="30dp" android:layout_height="30dp" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_alignParentTop="true" android:layout_marginTop="30dp" android:layout_marginRight="20dp" android:layout_marginEnd="20dp" android:src="@mipmap/ic_menu_settings_white" android:contentDescription="@string/settings_desc" android:onClick="onSettingsClicked" /> <ImageView android:id="@+id/infoButton" android:layout_width="30dp" android:layout_height="30dp" android:layout_toLeftOf="@id/settingsButton" android:layout_toStartOf="@id/settingsButton" android:layout_alignTop="@id/settingsButton" android:layout_marginRight="20dp" android:layout_marginEnd="20dp" android:src="@android:drawable/ic_dialog_info" android:contentDescription="@string/info" android:onClick="onInfoClicked" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/image_capture" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:visibility="invisible" android:onClick="captureImage" android:src="@drawable/image_capture_selector" android:paddingRight="20dp"/> <!-- <TextView android:id="@id/demo_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_above="@+id/info_bar" android:gravity="center" android:paddingBottom="0dp" android:text="" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FFFFFF" />--> <RelativeLayout android:id="@+id/info_bar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/background_gradient" android:layout_alignParentBottom="true" android:paddingBottom="0dp"> <GridLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="2dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingTop="0dp" android:rowCount="3" android:columnCount="2"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingRight="10dp" android:paddingLeft="10dp" android:layout_row="0" android:layout_column="0" android:text="@string/barcode_colon" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FFFFFF" /> <TextView android:id="@+id/barcode_result" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_row="0" android:layout_column="1" android:ellipsize="end" android:maxLines="2" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FFFFFF" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_row="1" android:layout_column="0" android:paddingRight="10dp" android:paddingLeft="10dp" android:text="@string/length_colon" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FFFFFF" /> <TextView android:id="@+id/length_result" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_row="1" android:layout_column="1" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FFFFFF" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_row="2" android:layout_column="0" android:paddingRight="10dp" android:paddingLeft="10dp" android:text="@string/symbology_colon" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FFFFFF" /> <TextView android:id="@+id/symbology_result" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_row="2" android:layout_column="1" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#FFFFFF" /> </GridLayout> <ImageView android:id="@+id/scanButton" android:layout_width="220dp" android:layout_height="100dp" android:layout_centerHorizontal="true" app:layout_widthPercent="33%" android:paddingBottom="0dp" android:src="@drawable/button_background_tablet_selector" android:contentDescription="@string/scan_button_desc" android:onClick="onScanClicked" /> </RelativeLayout> </RelativeLayout> ```

开发时遇到了addview错误

在`setAdapter()`命令报错: "addview is not supported in adapterview"。源码如下: **FilmAdapter.java** package com.pabeda.bicaps.adapters; import java.util.List; import com.pabeda.bicaps.R; import com.pabeda.bicaps.classes.Film; import android.app.Activity; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.TextView; public class FilmAdapter extends ArrayAdapter<Film> { Context context; int layoutResourceId; Film data[]=null; public FilmAdapter(Context context, int resource,Film[] objects) { super(context, resource, objects); // TODO Auto-generated constructor stub this.layoutResourceId=layoutResourceId; this.context=context; this.data=objects; } @Override public View getView(int position, View convertView, ViewGroup parent) { View row=convertView; if (row==null) { LayoutInflater inflater=((Activity)context).getLayoutInflater(); inflater.inflate(R.layout.film_list,null); } ((TextView)row.findViewById(R.id.film_name)).setText(data[position].filmName); ((TextView)row.findViewById(R.id.imdb_rating)).setText(data[position].imdbRating); return row; } } 设置adapter如下: FilmAdapter filmadapter=new FilmAdapter(this, R.layout.film_list, film); GridView gw=(GridView) findViewById(R.id.gridView1); gw.setAdapter(filmadapter); res > Layout > film_list.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/film_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/imageView1" android:layout_marginLeft="18dp" android:layout_marginTop="16dp" android:layout_toRightOf="@+id/imageView1" android:text="Film İsmi Buraya Gelecek" android:textSize="22sp" /> <ImageView android:id="@+id/film_image" android:layout_width="85dp" android:layout_height="125dp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:layout_marginTop="18dp" android:text="IMDB Rating" /> <TextView android:id="@+id/imdb_rating" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/textView2" android:layout_alignBottom="@+id/textView2" android:layout_marginLeft="16dp" android:layout_toRightOf="@+id/textView2" android:text="4.9/5" /> </RelativeLayout>

跪求:listview如何只占布局中央位置,怎么将json数组传到list中?

紧急求问各位高手: listview只能独占一个xml文件吗?我想做一个与微博客户端相似的界面,上面是一个layout放各种按钮,中间是一个listview(可以滚动),最底端是一个layout(用于提交信息)。这样的listview应该如何设置呢? activity又如何使用这个listview,将网络中获取到的json数组中的字符串一个一个地传到listview里面呢? 求助求助。 以下是我尝试的activity和xml代码,不过总是报错: //xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff" android:orientation="vertical" > <RelativeLayout android:id="@+id/rl_layout" android:layout_width="fill_parent" android:layout_height="45dp" android:background="#0562C2" android:gravity="center_vertical" > <Button android:id="@+id/room_back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:background="#0562c2" android:onClick="chat_back" android:text="返回" android:textColor="#ffffff" android:textSize="20sp" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="思考" android:textColor="#ffffff" android:textSize="40dip" /> </RelativeLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="40dp" android:orientation="horizontal" > <Button android:id="@+id/roombutton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/blue1" android:gravity="center_horizontal" /> <Button android:id="@+id/roombutton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/blue2" android:gravity="center_horizontal" /> <Button android:id="@+id/roombutton3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/blue3" android:gravity="center_horizontal" /> <Button android:id="@+id/roombutton4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/blue4" android:gravity="center_horizontal" /> <Button android:id="@+id/roominfo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/whitepoint" android:gravity="center_horizontal" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center_horizontal" android:layout_marginTop="14dp" android:clickable="true" android:gravity="center_vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:padding="8dp" android:text="房间信息" android:textColor="#000" android:textSize="17sp" /> </RelativeLayout> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:background="@drawable/preference_first_item" android:clickable="true" android:gravity="center_vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="8dp" android:text="房间ID" android:textColor="#000" android:textSize="17sp" /> <TextView android:id="@+id/roomid" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:padding="8dp" android:textColor="#000" android:textSize="17sp" /> </RelativeLayout> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/preference_item" android:clickable="true" android:gravity="center_vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="8dp" android:text="房间主题" android:textColor="#000" android:textSize="17sp" /> <TextView android:id="@+id/theme" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:padding="8dp" android:textColor="#000" android:textSize="17sp" /> </RelativeLayout> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/preference_last_item" android:clickable="true" android:gravity="center_vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="8dp" android:text="主持人" android:textColor="#000" android:textSize="17sp" /> <TextView android:id="@+id/host" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:padding="8dp" android:textColor="#000" android:textSize="17sp" /> </RelativeLayout> <!-- *********************************************************************** --> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical|center_horizontal" android:layout_marginTop="14dp" android:clickable="true" android:gravity="center_vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:text="房间成员" android:textColor="#000" android:textSize="17sp" /> </RelativeLayout> <!-- *********************************************************************** --> </LinearLayout> <LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <ListView android:id="@+id/MycreatedteamList" android:layout_width="match_parent" android:layout_height="350dp" > <TextView android:id="@+id/text0" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="" android:textColor="#000000" /> </ListView> </LinearLayout> </LinearLayout> //activity: import android.app.Activity; import android.os.Bundle; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import cn.edu.uibe.brainstorming.R; import android.content.Intent; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.TextView; import android.app.ListActivity; public class RoomActivity extends ListActivity { private CookieStore cookies; public static String roomid; public static String theme; public static String host; public static JSONArray onlineuser; public static String[] user = new String[100]; public static String[] strs = new String[100]; public static String PHPSESSID = null; public EditText new_roomsubject; public Button roombutton1; public Button roombutton2; public Button roombutton3; public Button roombutton4; public Button room_back; private Intent intent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 设置布局 setContentView(R.layout.room); // roombutton(); // getRoomId(); TextView room_id = (TextView) findViewById(R.id.roomid); room_id.setText(roomid); TextView room_theme = (TextView) findViewById(R.id.theme); room_theme.setText(theme); TextView room_host = (TextView) findViewById(R.id.host); room_host.setText(host); try { for (int i = 0; i < 10; i++) { user[i] = onlineuser.getJSONObject(i).getString("username"); } } catch (JSONException e) { e.printStackTrace(); } try { for (int i = 0; i < onlineuser.length(); i++) { user[i] = onlineuser.getJSONObject(i).getString("username"); } StringBuffer buffer = new StringBuffer(); ArrayList<HashMap<String, String>> items = new ArrayList<HashMap<String, String>>(); HashMap<String, String> item = null; int i = 0; while (i < onlineuser.length()) { item = new HashMap<String, String>(); item.put(user[i], onlineuser.getJSONObject(i).getString("username")); items.add(item); String[] from = {user[i]}; int[] to = { R.id.text0 }; SimpleAdapter adapter = new SimpleAdapter(this, items, R.layout.room, from, to); ListView listView = getListView(); listView.setAdapter(adapter); i++; } } catch (JSONException e) { e.printStackTrace(); } }

在layout建立一个attrs.xml文件,在布局testinfo.xml 会报错

error: Error: No resource found that matches the given name (at 'background' with value '@drawable/ok'). [2015-05-13 06:41:13 - example] [2015-05-13 06:41:13 - example] : error: Error: No resource found that matches the given name (at 'background' with value '@drawable/cancle'). attrs.xml <resources> <!-- Declare custom theme attributes that allow changing which styles are used for button bars depending on the API level. ?android:attr/buttonBarStyle is new as of API 11 so this is necessary to support previous API levels. --> <declare-styleable name="ButtonBarContainerTheme"> <attr name="buttonBarStyle" format="reference" /> <attr name="buttonBarButtonStyle" format="reference" /> </declare-styleable> </resources> testinfo.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:id="@+id/testlist" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_weight="4" > <ScrollView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="5dp" android:background="@drawable/bg" > <LinearLayout android:id="@+id/testlinear" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="25dp" android:layout_marginRight="25dp" android:layout_marginTop="5dp" android:background="@drawable/bg" android:orientation="vertical" android:gravity="bottom"> </LinearLayout> </ScrollView> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="bottom" android:layout_weight="1" android:orientation="horizontal" android:background="@drawable/share_bg_tab_normal" > <Button android:id="@+id/ok" android:layout_marginLeft="15dp" android:layout_marginRight="30dp" android:layout_height="wrap_content" android:layout_width="wrap_content" android:paddingLeft="10dp" android:paddingRight="5dp" android:paddingBottom="6dp" android:layout_weight="1" android:paddingTop="6dp" android:background="@drawable/ok" /> <Button android:layout_marginLeft="30dp" android:layout_marginRight="15dp" android:id="@+id/cancle" android:paddingLeft="5dp" android:paddingRight="10dp" android:paddingBottom="6dp" android:paddingTop="6dp" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/cancle" /> </LinearLayout> </LinearLayout>

如何使组合控件可悬浮拖动实现返回顶部的功能?(问题已经解决,原因是FloatingView写的有问题)

我有一个创建了一个组合控件,然后想让这个组合控件在页面内随意拖动实现返回顶部的功能,然后FloatingView继承了这个组合控件后,使用报运行时异常,请问我该怎么修改?谢谢 下面是组合控件: ``` public class BackTopView extends RelativeLayout { private TextView text_view; private View rootView; private String back_text; public BackTopView(Context context) { super(context); init(); } public BackTopView(Context context, AttributeSet attrs) { super(context, attrs); init(); back_text=attrs.getAttributeValue("http://schemas.android.com/apk/res-auto","setting_text"); text_view.setText(back_text); } public BackTopView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init(){ rootView=View.inflate(getContext(), R.layout.back_top_layout,this); text_view=rootView.findViewById(R.id.back_text); } public void setText(String text){ text_view.setText(text); } } ``` 下面是悬浮实现 ``` public class FloatingView extends BackTopView { int startX; int startY; int left; int top; int[] temp = new int[]{ 200, 200 }; public FloatingView(Context context) { super(context); } @Override public boolean onTouchEvent(MotionEvent event) { boolean isMove = false; int x = (int) event.getRawX(); int y = (int) event.getRawY(); switch (event.getAction()){ case MotionEvent.ACTION_DOWN: // touch down so check if the startX = x; startY = y; temp[0] = (int) event.getX(); temp[1] = y - getTop(); break; case MotionEvent.ACTION_MOVE: // touch drag with the ball left = x - temp[0]; top = y - temp[1]; if(left < 0){//控制左边界不超出 left = 0; } layout(left, top, left + getWidth(),top + getHeight());//自由拖拽 break; case MotionEvent.ACTION_UP: if (Math.abs(x - startX) > 2 || Math.abs(y - startY) > 2){//判断是否移动,再一定范围内不算是移动,解决触发事件冲突 //将最后拖拽的位置定下来,否则页面刷新渲染后按钮会自动回到初始位置 //注意父容器 RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) getLayoutParams(); lp.setMargins(left, top,0,0); setLayoutParams(lp); //确定是拖拽 isMove = true; } break; } return isMove ? true : super.onTouchEvent(event); } } ``` 引用到的XML ``` <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/first_layout" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".AssetsActivity" android:orientation="vertical" android:clickable="true" android:focusableInTouchMode="true"> <RelativeLayout android:id="@+id/edit_relativew" android:layout_marginTop="15dp" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:background="@drawable/edit_frame_shape"> <EditText android:id="@+id/assets_edit" android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginLeft="16dp" android:layout_marginRight="15dp" android:background="@null" android:hint=" 搜索设备" android:imeOptions="actionSearch" android:singleLine="true"></EditText> <ImageButton android:id="@+id/assets_btu" android:layout_alignRight="@id/assets_edit" android:layout_centerVertical="true" android:layout_width="25dp" android:layout_height="25dp" android:layout_gravity="center" android:background="@drawable/select"> </ImageButton> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/edit_relativew" android:layout_marginTop="10dp" android:orientation="vertical"> <com.zxkj.e_delivermaintain.Adapter.LoadListView android:id="@+id/assets_list" android:layout_width="match_parent" android:layout_height="match_parent" android:divider="@null"> </com.zxkj.e_delivermaintain.Adapter.LoadListView> </RelativeLayout> <include android:id="@+id/emptyview" layout="@layout/list_empty"/> <com.zxkj.e_delivermaintain.Adapter.FloatingView android:id="@+id/back_top" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center"> </com.zxkj.e_delivermaintain.Adapter.FloatingView> </RelativeLayout> ``` 报错内容 ``` java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zxkj.e_delivermaintain/com.zxkj.e_delivermaintain.AssetsActivity}: android.view.InflateException: Binary XML file line #68: Binary XML file line #68: Error inflating class com.zxkj.e_delivermaintain.Adapter.FloatingView ``` 谢谢你的帮助!!

安卓开发 java.lang.RuntimeException: Unable to start activity ComponentInfo{(xxx)}: java.lang.NullPointerException

安卓开发实验预习,代码没有报错,虚拟机运行(API19)闪退,不知道哪里出了问题 Activity: ``` package com.example.ght201621111093_yuxi3_1; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.os.Bundle; import android.os.Environment; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity { SharedPreferences sp;//数据读写变量 Editor edit; //Editor编辑对象 /* 定义账户 和密码的控件变量 定义登录按钮的控件变量 */ private Button delete,saveINSIDE,saveSD,saveSP,readINSIDE,readSD,readSP; private EditText stu_name,stu_age,stu_number; // 1 定义记住密码控件变量以及文件操作变量 private File sdCardDir;//sd卡路径 private File saveFile;//文件名 private FileOutputStream outStream;//输入文件流 private FileInputStream inStream;//输入文件 @Override protected void onCreate(Bundle savedInstanceState) { delete = (Button) findViewById(R.id.delete); saveINSIDE = (Button) findViewById(R.id.saveINSIDE); saveSD = (Button) findViewById(R.id.saveSD); saveSP = (Button) findViewById(R.id.saveSP); readINSIDE = (Button) findViewById(R.id.readINSIDE); readSD = (Button) findViewById(R.id.readSD); readSP = (Button) findViewById(R.id.readSP); stu_name = (EditText) findViewById(R.id.et_name); stu_age = (EditText) findViewById(R.id.et_age); stu_number = (EditText) findViewById(R.id.et_num); super.onCreate(savedInstanceState); setContentView(R.layout.login); //利用edit()方法获取Editor对象。 edit = sp.edit(); /* 账户 和密码的控件变量赋值 登录按钮的控件变量 赋值 */ // 4 完成用户名密码的保存功能 //m_pswSave = (CheckBox) findViewById(R.id.checkBox1); // 为每一个选项设置监听 //清除 delete.setOnClickListener(new OnClickListener(){ public void onClick(View v){ stu_name.setText(""); stu_age.setText(""); stu_number.setText(""); } }); //保存内部 saveINSIDE.setOnClickListener(new OnClickListener(){ public void onClick(View v) { final String a=stu_age.getText().toString(); int a1= Integer.parseInt(a); if (a1<1||a1>100) { Toast toast = Toast.makeText(getApplicationContext(), "请输入正确的年龄", Toast.LENGTH_SHORT); toast.show(); } else { Write_Files_INSIDE("name.txt",stu_name.getText().toString()); Write_Files_INSIDE("age.txt",stu_age.getText().toString()); Write_Files_INSIDE("number.txt",stu_number.getText().toString()); } } }); //保存SD saveSD.setOnClickListener(new OnClickListener(){ public void onClick(View v) { final String a=stu_age.getText().toString(); int a1= Integer.parseInt(a); if (a1<1||a1>100) { Toast toast = Toast.makeText(getApplicationContext(), "请输入正确的年龄", Toast.LENGTH_SHORT); toast.show(); } else { Write_Files_SD("name.txt",stu_name.getText().toString()); Write_Files_SD("age.txt",stu_age.getText().toString()); Write_Files_SD("number.txt",stu_number.getText().toString()); } } }); //保存SP saveSP.setOnClickListener(new OnClickListener(){ public void onClick(View v) { final String a=stu_age.getText().toString(); int a1= Integer.parseInt(a); if (a1<1||a1>100) { Toast toast = Toast.makeText(getApplicationContext(), "请输入正确的年龄", Toast.LENGTH_SHORT); toast.show(); } else { //通过Editor对象存储key-value键值对数据 edit.putString("name",stu_name.getText().toString()); edit.putString("age",stu_age.getText().toString()); edit.putString("number",stu_number.getText().toString()); //通过commit()方法提交数据 edit.commit(); } } }); //读取INSIDE readINSIDE.setOnClickListener(new OnClickListener(){ public void onClick(View v) { if(null!=Read_Files_INSIDE("name.txt")) { stu_name.setText(Read_Files_INSIDE("name.txt")); } if(null!=Read_Files_INSIDE("age.txt")) { stu_age.setText(Read_Files_INSIDE("age.txt")); } if(null!=Read_Files_INSIDE("number.txt")) { stu_number.setText(Read_Files_INSIDE("number.txt")); } } }); //读取SD readSD.setOnClickListener(new OnClickListener(){ public void onClick(View v) { if(null!=Read_Files_INSIDE("name.txt")) { stu_name.setText(Read_Files_INSIDE("name.txt")); } if(null!=Read_Files_INSIDE("age.txt")) { stu_age.setText(Read_Files_INSIDE("age.txt")); } if(null!=Read_Files_INSIDE("number.txt")) { stu_number.setText(Read_Files_INSIDE("number.txt")); } } }); //读取SP readSP.setOnClickListener(new OnClickListener(){ public void onClick(View v) { if(null!=sp.getString("name","")) { stu_name.setText(sp.getString("name","")); } if(null!=sp.getString("age","")) { stu_age.setText(sp.getString("age","")); } if(null!=sp.getString("number","")) { stu_number.setText(sp.getString("number","")); } } }); } /* //5 INSIDE读取功能 if(null!=Read_Files_INSIDE("name.txt")) { name.setText(Read_Files_INSIDE("name.txt")); } if(null!=Read_Files_INSIDE("age.txt")) { age.setText(Read_Files_INSIDE("age.txt")); } if(null!=Read_Files_INSIDE("number.txt")) { number.setText(Read_Files_INSIDE("number.txt")); } //5 SD读取功能 if(null!=Read_Files_SD("name.txt")) { name.setText(Read_Files_SD("name.txt")); } if(null!=Read_Files_SD("age.txt")) { age.setText(Read_Files_SD("age.txt")); } if(null!=Read_Files_SD("number.txt")) { number.setText(Read_Files_SD("number.txt")); } //5 SP读取功能 if(null!=sp.getString("name","")) { name.setText(sp.getString("name","")); } if(null!=sp.getString("age","")) { age.setText(sp.getString("age","")); } if(null!=sp.getString("number","")) { number.setText(sp.getString("number","")); } */ @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } //2 INSIDE完成文件写操作功能 private void Write_Files_INSIDE(String fileName, String strContent) { try { FileOutputStream outStream=this.openFileOutput(fileName,Context.MODE_WORLD_READABLE); outStream.write(strContent.getBytes()); outStream.close(); Toast.makeText(this,"文件保存成功",Toast.LENGTH_LONG).show(); } catch (FileNotFoundException e) { return; } catch (IOException e){ return ; } } // 3 INSIDE读操作功能 private String Read_Files_INSIDE(String fileName) { try { FileInputStream inStream=this.openFileInput(fileName); ByteArrayOutputStream stream=new ByteArrayOutputStream(); byte[] buffer=new byte[1024]; int length=-1; while((length=inStream.read(buffer))!=-1) { stream.write(buffer,0,length); } stream.close(); inStream.close(); Toast.makeText(this,"文件读取成功",Toast.LENGTH_LONG).show(); return stream.toString(); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } catch (IOException e){ return null; } } //2 SD文件写操作功能 private void Write_Files_SD(String fileName, String strContent) { sdCardDir = Environment.getExternalStorageDirectory(); saveFile = new File(sdCardDir, fileName); if (Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) { // 创建 初始化 流对象 try { outStream = new FileOutputStream(saveFile); } catch (FileNotFoundException e) { Toast.makeText(this, "文件不存在!", Toast.LENGTH_SHORT).show(); return; } try { // 把内容写入文件 outStream.write(strContent.getBytes()); } catch (FileNotFoundException e) { // TODO Auto-generated catch block Toast.makeText(this, "文件未发现异常!", Toast.LENGTH_SHORT).show(); } catch (IOException e) { // TODO Auto-generated catch block Toast.makeText(this, "文件读写异常!", Toast.LENGTH_SHORT).show(); } catch (NullPointerException e) { Toast.makeText(this, "文件读写空指针异常!", Toast.LENGTH_SHORT).show(); } finally { try { // 关闭文件输出流 outStream.close(); } catch (IOException e) { // TODO Auto-generated catch block Toast.makeText(this, "文件读写异常!", Toast.LENGTH_SHORT).show(); } Toast.makeText(this, "文件写入成功!", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(this, "内存卡不存在!", Toast.LENGTH_SHORT).show(); return; } } // 3 SD文件读操作功能 private String Read_Files_SD(String fileName) { sdCardDir = Environment.getExternalStorageDirectory(); saveFile = new File(sdCardDir, fileName); int len; // 然后创建一个字节数组输出流 byte[] buffer = new byte[1024]; ByteArrayOutputStream ostream = new ByteArrayOutputStream(); if (Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) { // 创建 初始化 流对象 try { inStream = new FileInputStream(saveFile); Log.v("Instance inStream", "实例化inStream!"); } catch (FileNotFoundException e) { Toast.makeText(this, "文件不存在!", Toast.LENGTH_SHORT).show(); return null; } try { Log.v("Read", "读数据!"); Toast.makeText(this, "文件读取成功!", Toast.LENGTH_SHORT).show(); while ((len = inStream.read(buffer)) != -1) { ostream.write(buffer, 0, len); } Log.v("Read", "读成功!"); } catch (IOException e) { Toast.makeText(this, "读 异常!", Toast.LENGTH_SHORT).show(); } try { // 最后关闭输入流和输出流 inStream.close(); ostream.close(); Log.v("Read", "读成功!"); } catch (IOException e) { Toast.makeText(this, "读 异常!", Toast.LENGTH_SHORT).show(); } String str = new String(ostream.toByteArray()); Log.v("Disp", "文本显示!"); return str; } else { Toast.makeText(this, "内存卡不存在!", Toast.LENGTH_SHORT).show(); return null; } } } ``` layout: ``` <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" > <EditText android:id="@+id/et_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:ems="10" /> <Button android:id="@+id/saveINSIDE" android:layout_width="135dp" android:layout_height="50dp" android:layout_alignLeft="@+id/delete" android:layout_below="@+id/delete" android:layout_marginTop="21dp" android:text="保存内部" /> <Button android:id="@+id/saveSD" android:layout_width="135dp" android:layout_height="50dp" android:layout_alignLeft="@+id/saveINSIDE" android:layout_below="@+id/saveINSIDE" android:layout_marginTop="18dp" android:text="保存SD" /> <Button android:id="@+id/saveSP" android:layout_width="135dp" android:layout_height="50dp" android:layout_alignLeft="@+id/saveSD" android:layout_below="@+id/saveSD" android:layout_marginTop="22dp" android:text="保存SP" /> <Button android:id="@+id/readINSIDE" android:layout_width="135dp" android:layout_height="50dp" android:layout_alignBottom="@+id/saveINSIDE" android:layout_alignRight="@+id/et_age" android:text="读取内部" /> <Button android:id="@+id/readSD" android:layout_width="135dp" android:layout_height="50dp" android:layout_alignBaseline="@+id/saveSD" android:layout_alignBottom="@+id/saveSD" android:layout_alignLeft="@+id/readINSIDE" android:text="读取SD" /> <Button android:id="@+id/readSP" android:layout_width="135dp" android:layout_height="50dp" android:layout_alignBaseline="@+id/saveSP" android:layout_alignBottom="@+id/saveSP" android:layout_alignRight="@+id/readSD" android:text="读取SP" /> <TextView android:id="@+id/age" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/delete" android:layout_below="@+id/name" android:layout_marginTop="34dp" android:text="年龄:" /> <EditText android:id="@+id/et_age" android:layout_width="wrap_content" android:inputType="number" android:layout_height="wrap_content" android:layout_alignBottom="@+id/age" android:layout_alignLeft="@+id/et_name" android:ems="10" /> <EditText android:id="@+id/et_num" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/et_age" android:layout_below="@+id/et_age" android:layout_marginTop="18dp" android:ems="10" /> <TextView android:id="@+id/number" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/et_num" android:layout_alignLeft="@+id/age" android:text="学号:" /> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/et_name" android:layout_alignLeft="@+id/age" android:text="姓名:" /> <Button android:id="@+id/delete" android:layout_width="135dp" android:layout_height="50dp" android:layout_below="@+id/et_num" android:layout_marginTop="17dp" android:text="清除" /> </RelativeLayout> ``` Logcat: ``` 04-07 13:23:38.877: W/dalvikvm(1340): threadid=1: thread exiting with uncaught exception (group=0xb3a77b90) 04-07 13:23:38.887: E/AndroidRuntime(1340): FATAL EXCEPTION: main 04-07 13:23:38.887: E/AndroidRuntime(1340): Process: com.example.ght201621111093_yuxi3_1, PID: 1340 04-07 13:23:38.887: E/AndroidRuntime(1340): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ght201621111093_yuxi3_1/com.example.ght201621111093_yuxi3_1.MainActivity}: java.lang.NullPointerException 04-07 13:23:38.887: E/AndroidRuntime(1340): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176) 04-07 13:23:38.887: E/AndroidRuntime(1340): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226) 04-07 13:23:38.887: E/AndroidRuntime(1340): at android.app.ActivityThread.access$700(ActivityThread.java:135) 04-07 13:23:38.887: E/AndroidRuntime(1340): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397) 04-07 13:23:38.887: E/AndroidRuntime(1340): at android.os.Handler.dispatchMessage(Handler.java:102) 04-07 13:23:38.887: E/AndroidRuntime(1340): at android.os.Looper.loop(Looper.java:137) 04-07 13:23:38.887: E/AndroidRuntime(1340): at android.app.ActivityThread.main(ActivityThread.java:4998) 04-07 13:23:38.887: E/AndroidRuntime(1340): at java.lang.reflect.Method.invokeNative(Native Method) 04-07 13:23:38.887: E/AndroidRuntime(1340): at java.lang.reflect.Method.invoke(Method.java:515) 04-07 13:23:38.887: E/AndroidRuntime(1340): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777) 04-07 13:23:38.887: E/AndroidRuntime(1340): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 04-07 13:23:38.887: E/AndroidRuntime(1340): at dalvik.system.NativeStart.main(Native Method) 04-07 13:23:38.887: E/AndroidRuntime(1340): Caused by: java.lang.NullPointerException 04-07 13:23:38.887: E/AndroidRuntime(1340): at com.example.ght201621111093_yuxi3_1.MainActivity.onCreate(MainActivity.java:57) 04-07 13:23:38.887: E/AndroidRuntime(1340): at android.app.Activity.performCreate(Activity.java:5243) 04-07 13:23:38.887: E/AndroidRuntime(1340): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 04-07 13:23:38.887: E/AndroidRuntime(1340): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140) 04-07 13:23:38.887: E/AndroidRuntime(1340): ... 11 more ```

Eclipse报了一个没见过的错

报错如下 ``` 07-26 17:23:45.679: E/AndroidRuntime(26216): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myweathertest/com.example.myweathertest.activities.WeatherActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x0 ``` Activity如下 ``` public class WeatherActivity extends Activity implements OnClickListener { private LinearLayout weatherInfoLayout; private TextView cityNameText; private TextView publishText; ; private TextView weatherDespText; private TextView temp1Text; private TextView temp2Text; private TextView currentDateText; private Button switchCity; private Button refreshWeather; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.weather_layout); weatherInfoLayout=(LinearLayout)findViewById(R.id.weather_info_layout); cityNameText=(TextView)findViewById(R.id.city_name); publishText=(TextView)findViewById(R.id.publish_text); weatherDespText=(TextView)findViewById(R.id.weather_desp); temp1Text=(TextView)findViewById(R.id.temp1); temp2Text=(TextView)findViewById(R.id.temp2); currentDateText=(TextView)findViewById(R.id.current_date); switchCity=(Button)findViewById(R.id.switch_city); refreshWeather=(Button)findViewById(R.id.refresh_weather); switchCity.setOnClickListener(this); refreshWeather.setOnClickListener(this); String countyName=getIntent().getStringExtra("county_name"); if(!TextUtils.isEmpty(countyName))//若从菜单中点击进去 { publishText.setText("同步中"); weatherInfoLayout.setVisibility(View.INVISIBLE); cityNameText.setVisibility(View.INVISIBLE); queryWeatherInfo(countyName); showWeather(); }else//若直接打开app { Log.d("haha", "countyName is null"); showWeather(); } } private void showWeather() { // TODO Auto-generated method stub Log.d("haha", "进入showweather"); SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this); cityNameText.setText(prefs.getString("city_name", "未知错误")); temp1Text.setText(prefs.getString("temp1", "")); temp2Text.setText(prefs.getString("temp2", "")); weatherDespText.setText(prefs.getString("weather_desp", "")); publishText.setText(prefs.getString("publish_time", "")+"发布"); currentDateText.setText(prefs.getString("current_time", "")); weatherInfoLayout.setVisibility(View.VISIBLE); cityNameText.setText(View.VISIBLE); } private void queryWeatherInfo(String countyName) { // TODO Auto-generated method stub Log.d("haha", "开始查询天气"); String address="http://apis.baidu.com/heweather/weather/free";//http://apis.baidu.com/heweather/weather/free Parameters param=new Parameters(); countyName=ChangeHanziToPinyin.getPinYin(countyName); Log.d("haha", "cityName is "+countyName); param.put("city", countyName); ApiStoreSDK.execute(address, ApiStoreSDK.GET, param,new ApiCallBack() { @Override public void onSuccess(int status, String responseString) { Log.d("haha", "请求成功"); Utility.handleWeatherResponse(WeatherActivity.this, responseString);//存入了sharepreferce } @Override public void onComplete() { } @Override public void onError(int status, String responseString, Exception e) { Log.d("haha", "错误进入onerror,参数为"+status); } }); } @Override public void onClick(View arg0) { // TODO Auto-generated method stub } } ``` 布局文件 ``` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <RelativeLayout android:layout_width="match_parent" android:layout_height="50dp" android:background="#484E61" > <Button android:id="@+id/switch_city" android:layout_width="30dp" android:layout_height="30dp" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:background="@drawable/home"/> <TextView android:id="@+id/city_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:textColor="#fff" android:textSize="24sp" /> <Button android:id="@+id/refresh_weather" android:layout_width="30dp" android:layout_height="30dp" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="10dp" android:background="@drawable/refresh" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#27A5F9" > <TextView android:id="@+id/publish_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginRight="10dp" android:layout_marginTop="10dp" android:textColor="#FFF" android:textSize="18sp"/> <LinearLayout android:id="@+id/weather_info_layout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:orientation="vertical"> <TextView android:id="@+id/current_date" android:layout_width="wrap_content" android:layout_height="40dp" android:gravity="center" android:textColor="#FFF" android:textSize="18sp"/> <TextView android:id="@+id/weather_desp" android:layout_width="wrap_content" android:layout_height="60dp" android:layout_gravity="center_horizontal" android:gravity="center" android:textColor="#FFF" android:textSize="40sp"/> <LinearLayout android:layout_width="wrap_content" android:layout_height="60dp" android:layout_gravity="center_horizontal" android:orientation="horizontal"> <TextView android:id="@+id/temp1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:textColor="#FFF" android:textSize="40sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:text="~" android:textColor="#FFF" android:textSize="40sp"/> <TextView android:id="@+id/temp2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:textColor="#FFF" android:textSize="40sp" /> </LinearLayout> </LinearLayout> </RelativeLayout> </LinearLayout> ``` 为什么就不能启动这个Activity 呢,而且 ``` ApiStoreSDK.execute(address, ApiStoreSDK.GET, param,new ApiCallBack() { ``` 这行代码直接跳过去没执行,为什么?

安卓模拟器运行出现unfortunately,xxx has stoped是什么原因啊,小白刚学

activity_main.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:orientation="vertical" > <TextView android:id="@+id/text_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="This is TextView" /> <Button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button"/> <EditText android:id="@+id/edit_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/button" android:layout_marginTop="14dp" android:ems="10" android:hint="Type something here" > <requestFocus /> </EditText> </RelativeLayout> MainActivity.java代码: package com.example.class3; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity { private Button button; private EditText editText; @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = (Button) findViewById(R.id.button); editText=(EditText) findViewById(R.id.edit_text); button.setOnClickListener((OnClickListener) this); } public void onClick(View v){ switch(v.getId()){ case R.id.button: String inputText=editText.getText().toString(); Toast.makeText(MainActivity.this,inputText, Toast.LENGTH_SHORT).show(); break; default: break; } } }

安卓中的R文件错误,不知道怎么解决

不加上import android.R;之前是这样报错的 ![图片说明](https://img-ask.csdn.net/upload/201607/03/1467537426_755961.png) 加上import android.R;之后是这样报错的 ![图片说明](https://img-ask.csdn.net/upload/201607/03/1467537456_509423.png) xml中的代码应该没有问题,我是放在fragment_main.xml中的 <LinearLayout 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="com.example.loginstate.MainActivity$PlaceholderFragment" > <EditText android:id="@+id/et_username" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/input_username" android:background="#ff33b5e5" /> <EditText android:layout_marginTop="15dp" android:layout_marginBottom="15dp" android:id="@+id/et_password" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/input_password" android:inputType="textPassword" android:background="#ff33b5e5" /> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content"> <CheckBox android:layout_alignParentLeft="true" android:id="@+id/cb_rem" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/rem_password" /> <Button android:paddingRight="50dp" android:paddingLeft="50dp" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/login" /> /> </RelativeLayout> </LinearLayout> ``` ``` MainActivity.java代码如下 package com.itheima.login; import java.security.PublicKey; import java.util.Map; import javax.security.auth.PrivateCredentialPermission; import javax.security.auth.login.LoginException; import com.itheima.login.util.UserInfoUtil; import android.R; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity implements OnClickListener{ public EditText et_username; private EditText et_password; private CheckBox cb_rem; private Button bt_login; private Context mContext; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_main); mContext = this; // a.找到相应控件 et_username = (EditText) findViewById(R.id.et_username); et_password = (EditText) findViewById(R.id.et_password); cb_rem = (CheckBox) findViewById(R.id.cb_rem); bt_login = (Button) findViewById(R.id.bt_login); // b.设置按钮的点击事件 bt_login.setOnClickListener(this); //f.回显用户名密码 Map<String, String> map = UserInfoUtil.getUserInfo_android(mContext); if(map != null){ String username = map.get("username"); String password = map.get("password"); et_username.setText(username);//设置用户名 et_password.setText(password); cb_rem.setChecked(true);//设置复选框选中状态 } } private void login() { // c.在onclick方法中,获取用户输入的用户名密码和是否记住密码 String username = et_username.getText().toString().trim(); String userpassword = et_password.getText().toString().trim(); boolean isrem = cb_rem.isChecked(); //d.判断用户名密码是否为空,不为空请求服务器(省略,默认请求成功) if(username.isEmpty() || userpassword.isEmpty()){ Toast.makeText(mContext, "用户名密码不为空", Toast.LENGTH_SHORT).show(); return; } // e.判断是否记住密码,如果记住,将用户名密码保存本地。 if(isrem){ boolean result = UserInfoUtil.saveUserInfo_android(mContext, username, userpassword); if(result){ Toast.makeText(mContext, "保存成功", Toast.LENGTH_SHORT).show(); }else{ Toast.makeText(mContext, "保存失败", Toast.LENGTH_SHORT).show(); } }else{ Toast.makeText(mContext, "不用保存", Toast.LENGTH_SHORT).show(); } } public void onClick(View v){ switch (v.getId()) { case R.id.bt_login: Login(); break; default: break; } } } ``` ```

想把GridView添加到ViewPager里面。加载无效

用TabLayout和ViewPager关联后,想把GridView添加到ViewPager里面。报空指针异常。 -------------------------------------------------------------------- 上面那个问题解决了,没有加载layout所以空对象。 View view = this.getLayoutInflater().inflate(R.layout.grid_view,null); 现在不报错,但是GridView没有加载进来,各位大神帮忙看一下是不是适配器写错了![图片说明](https://img-ask.csdn.net/upload/201804/13/1523585384_433958.png) 04-12 08:39:37.363 25278-25278/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.chenshenglei.tablayouttest, PID: 25278 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chenshenglei.tablayouttest/com.example.chenshenglei.tablayouttest.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.GridView.setAdapter(android.widget.ListAdapter)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.GridView.setAdapter(android.widget.ListAdapter)' on a null object reference at com.example.chenshenglei.tablayouttest.MainActivity.onCreate(MainActivity.java:46) at android.app.Activity.performCreate(Activity.java:6662) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) 下面贴代码MyGridViewAdapter.java ``` import android.content.Context; import android.view.View; import android.view.ViewGroup; import android.widget.SimpleAdapter; import java.util.List; import java.util.Map; /** * Created by chenshenglei on 18-4-12. */ public class MyGridViewAdapter extends SimpleAdapter { private Context mContext; public MyGridViewAdapter(Context context, List<Map<String, Object>> dataLists, int layout, String[] key, int[] item){ super(context, dataLists,layout, key, item); this.mContext = context; } @Override public int getCount() { return 0; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { convertView = super.getView(position, convertView, parent); return convertView; } } ``` 代码TabPagerAdapter.java ``` package com.example.chenshenglei.tablayouttest; import android.content.Context; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.widget.GridView; import android.widget.TextView; import java.security.PublicKey; import java.util.List; /** * Created by chenshenglei on 18-4-12. */ //自定义ViewPager页面适配器 public class TabPagerAdapter extends PagerAdapter { private Context mContext; private String[] mTitleArray; private List<GridView> mList; public TabPagerAdapter (Context context, String[] title) { super(); this.mContext = context; this.mTitleArray = title; } public TabPagerAdapter (Context context, String[] title, List<GridView> array) { super(); this.mContext = context; this.mTitleArray = title; this.mList = array; } @Override public int getCount() { return mTitleArray.length; } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } @Override public Object instantiateItem(ViewGroup container, int position) { View view = mList.get(position); container.addView(view); return view; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } @Override public CharSequence getPageTitle(int position) { return mTitleArray[position]; } } ``` 代码 MainActivity.java import android.support.design.widget.TabLayout; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.GridView; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class MainActivity extends AppCompatActivity { private TabLayout mTabLayout; private ViewPager mViewPager; private String[] mTitleArray = {"酒标","葡萄品种"}; private GridView gridView1; private GridView gridView2; private MyGridViewAdapter myGridViewAdapter; private List<GridView> mList; private List<Map<String, Object>> dataList; private List<Map<String, Object>> dataList2; private int[] img = {R.mipmap.ic_launcher_round,R.mipmap.ic_launcher}; private int[] img2 = {R.mipmap.ic_launcher_round,R.mipmap.ic_launcher}; private String[] imgName = {"1","2"}; private String[] imgName2 = {"3","4"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_weibo_timeline); gridView1 = (GridView)findViewById(R.id.grid_test); dataList = new ArrayList<Map<String, Object>>(); myGridViewAdapter = new MyGridViewAdapter(this, getData(), R.layout.grid_item, new String[] {"img", "txt"}, new int[] {R.id.img_item,R.id.txt_item}); gridView1.setAdapter(myGridViewAdapter); gridView2 = (GridView)findViewById(R.id.grid_test); dataList2 = new ArrayList<Map<String, Object>>(); myGridViewAdapter = new MyGridViewAdapter(this, getData2(), R.layout.grid_item, new String[] {"img", "txt"}, new int[] {R.id.img_item,R.id.txt_item}); gridView2.setAdapter(myGridViewAdapter); mList = new ArrayList<GridView>(); mList.add(gridView1); mList.add(gridView2); mViewPager = (ViewPager) findViewById(R.id.view); TabPagerAdapter adapter = new TabPagerAdapter(getApplicationContext(),mTitleArray,mList); mViewPager.setAdapter(adapter); mTabLayout = (TabLayout) findViewById(R.id.tab); mTabLayout.setupWithViewPager(mViewPager); } private List<Map<String,Object>> getData() { for (int i=0; i<img.length; i++) { Map<String,Object> map = new HashMap<String, Object>(); map.put("img", img[i]); map.put("txt", imgName[i]); dataList.add(map); } return dataList; } private List<Map<String,Object>> getData2() { for (int i=0; i<img.length; i++) { Map<String,Object> map = new HashMap<String, Object>(); map.put("img", img2[i]); map.put("txt", imgName2[i]); dataList2.add(map); } return dataList2; } } ``` grid_view.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <GridView android:id="@+id/grid_test" android:layout_width="wrap_content" android:layout_height="wrap_content" android:numColumns="4" android:verticalSpacing="5dp" android:horizontalSpacing="5dp" android:layout_marginTop="40dp"/> </LinearLayout> grid_item.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center" android:background="#ffffff"> <ImageView android:id="@+id/img_item" android:src="@mipmap/ic_launcher" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/txt_item" android:textColor="#000000" android:text="文字区域" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>``` activity_weibo_timeline.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v4.view.ViewPager android:id="@+id/view" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/> <LinearLayout android:layout_width="200dp" android:layout_height="wrap_content" android:layout_gravity="center_horizontal"> <android.support.design.widget.TabLayout android:id="@+id/tab" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabMode="scrollable"/> </LinearLayout> </LinearLayout>

Android 自定义ImageView出现的问题

package com.qnear.wechat; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapShader; import android.graphics.Canvas; 这是自定义的类 来源:http://www.cnblogs.com/goagent/p/5159126.html public class ImageViewPlus extends ImageView { private Paint mPaintBitmap = new Paint(Paint.ANTI_ALIAS_FLAG); private Bitmap mRawBitmap; private BitmapShader mShader; private Matrix mMatrix = new Matrix(); public ImageViewPlus(Context context, AttributeSet attrs) { super(context,attrs); } @Override protected void onDraw(Canvas canvas){ Bitmap rawBitmap = getBitmap(getDrawable()); if(rawBitmap!=null){ int viewWidth = getWidth(); int viewHeight = getHeight(); int viewMinSize = Math.min(viewWidth, viewHeight); float dstWidth = viewMinSize; float dstHeight = viewMinSize; if(mShader==null||!rawBitmap.equals(mRawBitmap)){ mRawBitmap = rawBitmap; mShader = new BitmapShader(mRawBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); } if(mShader!=null){ mMatrix.setScale(dstWidth/rawBitmap.getWidth(),dstHeight/rawBitmap.getHeight()); mShader.setLocalMatrix(mMatrix); } mPaintBitmap.setShader(mShader); float radius =viewMinSize/2.0f; canvas.drawCircle(radius,radius,radius,mPaintBitmap); }else{ super.onDraw(canvas); } } private Bitmap getBitmap(Drawable drawable) { if(drawable instanceof BitmapDrawable){ return ((BitmapDrawable) drawable).getBitmap(); }else if(drawable instanceof ColorDrawable){ Rect rect = drawable.getBounds(); int width = rect.right - rect.left; int height = rect.bottom - rect.top; int color = ((ColorDrawable) drawable).getColor(); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawARGB(Color.alpha(color),Color.red(color),Color.blue(color),Color.green(color)); return bitmap; }else{ return null; } } } 这是引用语句: <com.qnear.wechat.ImageViewPlus android:layout_width="150dp" android:layout_height="150dp" android:src="@drawable/mwinbag" android:scaleType="centerInside" android:layout_marginTop="146dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> 然后我就遇到了这个问题: ![图片说明](https://img-ask.csdn.net/upload/201612/22/1482385305_296726.png)![图片说明](https://img-ask.csdn.net/upload/201612/22/1482385317_826178.png) 一个显示正常,一个黑屏

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

点沙成金:英特尔芯片制造全过程揭密

“亚马逊丛林里的蝴蝶扇动几下翅膀就可能引起两周后美国德州的一次飓风……” 这句人人皆知的话最初用来描述非线性系统中微小参数的变化所引起的系统极大变化。 而在更长的时间尺度内,我们所生活的这个世界就是这样一个异常复杂的非线性系统…… 水泥、穹顶、透视——关于时间与技艺的蝴蝶效应 公元前3000年,古埃及人将尼罗河中挖出的泥浆与纳特龙盐湖中的矿物盐混合,再掺入煅烧石灰石制成的石灰,由此得来了人...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

外包程序员的幸福生活

今天给你们讲述一个外包程序员的幸福生活。男主是Z哥,不是在外包公司上班的那种,是一名自由职业者,接外包项目自己干。接下来讲的都是真人真事。 先给大家介绍一下男主,Z哥,老程序员,是我十多年前的老同事,技术大牛,当过CTO,也创过业。因为我俩都爱好喝酒、踢球,再加上住的距离不算远,所以一直也断断续续的联系着,我对Z哥的状况也有大概了解。 Z哥几年前创业失败,后来他开始干起了外包,利用自己的技术能...

C++11:一些微小的变化(新的数据类型、template表达式内的空格、nullptr、std::nullptr_t)

本文介绍一些C++的两个新特性,它们虽然微小,但对你的编程十分重要 一、Template表达式内的空格 C++11标准之前建议在“在两个template表达式的闭符之间放一个空格”的要求已经过时了 例如: vector&lt;list&lt;int&gt; &gt;; //C++11之前 vector&lt;list&lt;int&gt;&gt;; //C++11 二、nullptr ...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

深入剖析Springboot启动原理的底层源码,再也不怕面试官问了!

大家现在应该都对Springboot很熟悉,但是你对他的启动原理了解吗?

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

【阿里P6面经】二本,curd两年,疯狂复习,拿下阿里offer

二本的读者,在老东家不断学习,最后逆袭

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《经典算法案例》01-08:如何使用质数设计扫雷(Minesweeper)游戏

我们都玩过Windows操作系统中的经典游戏扫雷(Minesweeper),如果把质数当作一颗雷,那么,表格中红色的数字哪些是雷(质数)?您能找出多少个呢?文中用列表的方式罗列了10000以内的自然数、质数(素数),6的倍数等,方便大家观察质数的分布规律及特性,以便对算法求解有指导意义。另外,判断质数是初学算法,理解算法重要性的一个非常好的案例。

《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)

正确选择比瞎努力更重要!

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

微软为一人收购一公司?破解索尼程序、写黑客小说,看他彪悍的程序人生!...

作者 | 伍杏玲出品 | CSDN(ID:CSDNnews)格子衬衫、常掉发、双肩包、修电脑、加班多……这些似乎成了大众给程序员的固定标签。近几年流行的“跨界风”开始刷新人们对程序员的...

终于,月薪过5万了!

来看几个问题想不想月薪超过5万?想不想进入公司架构组?想不想成为项目组的负责人?想不想成为spring的高手,超越99%的对手?那么本文内容是你必须要掌握的。本文主要详解bean的生命...

我说我懂多线程,面试官立马给我发了offer

不小心拿了几个offer,有点烦

自从喜欢上了B站这12个UP主,我越来越觉得自己是个废柴了!

不怕告诉你,我自从喜欢上了这12个UP主,哔哩哔哩成为了我手机上最耗电的软件,几乎每天都会看,可是吧,看的越多,我就越觉得自己是个废柴,唉,老天不公啊,不信你看看…… 间接性踌躇满志,持续性混吃等死,都是因为你们……但是,自己的学习力在慢慢变强,这是不容忽视的,推荐给你们! 都说B站是个宝,可是有人不会挖啊,没事,今天咱挖好的送你一箩筐,首先啊,我在B站上最喜欢看这个家伙的视频了,为啥 ,咱撇...

代码注释如此沙雕,会玩还是你们程序员!

某站后端代码被“开源”,同时刷遍全网的,还有代码里的那些神注释。 我们这才知道,原来程序员个个都是段子手;这么多年来,我们也走过了他们的无数套路… 首先,产品经理,是永远永远吐槽不完的!网友的评论也非常扎心,说看这些代码就像在阅读程序员的日记,每一页都写满了对产品经理的恨。 然后,也要发出直击灵魂的质问:你是尊贵的付费大会员吗? 这不禁让人想起之前某音乐app的穷逼Vip,果然,穷逼在哪里都是...

立即提问
相关内容推荐