- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我有一个这样的简单地址表格:
Java:
public class NewAddressActivity extends AppCompatActivity {
private TextInputLayout mStreetLayout;
private TextInputLayout mNumberLayout;
private TextInputLayout mNeighborhoodLayout;
private TextInputLayout mCityLayout;
private TextInputLayout mStateLayout;
private TextInputLayout mCepLayout;
private TextInputLayout mPhoneLayout;
private EditText mStreetText;
private EditText mNumberText;
private EditText mComplementText;
private EditText mNeighborhoodText;
private EditText mCityText;
private EditText mStateText;
private EditText mCepText;
private EditText mPhoneText;
private Address mAddressEditing;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_address);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
mStreetLayout = findViewById(R.id.street_layout);
mNumberLayout = findViewById(R.id.number_layout);
mNeighborhoodLayout = findViewById(R.id.neighborhood_layout);
mCityLayout = findViewById(R.id.city_layout);
mStateLayout = findViewById(R.id.state_layout);
mCepLayout = findViewById(R.id.cep_layout);
mPhoneLayout = findViewById(R.id.phone_layout);
mStreetText = findViewById(R.id.street_text);
mNumberText = findViewById(R.id.number_text);
mComplementText = findViewById(R.id.complement_text);
mNeighborhoodText = findViewById(R.id.neighborhood_text);
mCityText = findViewById(R.id.city_text);
mStateText = findViewById(R.id.state_text);
mCepText = findViewById(R.id.cep_text);
mPhoneText = findViewById(R.id.phone_text);
mAddressEditing = getIntent().getParcelableExtra(AppConstants.ADDRESS_EXTRA);
if (mAddressEditing != null) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
if (actionBar != null) {
actionBar.setTitle(R.string.edit_address);
}
mStreetText.setText(mAddressEditing.getStreet());
mNumberText.setText(mAddressEditing.getNumber());
mComplementText.setText(mAddressEditing.getComplement());
mNeighborhoodText.setText(mAddressEditing.getNeighborhood());
mCityText.setText(mAddressEditing.getCity());
mStateText.setText(mAddressEditing.getState());
mCepText.setText(mAddressEditing.getCep());
mPhoneText.setText(mAddressEditing.getPhone());
mStreetText.setSelection(mAddressEditing.getStreet().length());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_new_address, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.action_save:
save();
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressLint("StaticFieldLeak")
private void save() {
String street = mStreetText.getText().toString().trim();
String number = mNumberText.getText().toString().trim();
String complement = mComplementText.getText().toString().trim();
String neighborhood = mNeighborhoodText.getText().toString().trim();
String city = mCityText.getText().toString().trim();
String state = mStateText.getText().toString().trim();
String cep = mCepText.getText().toString().trim();
String phone = mPhoneText.getText().toString().trim();
boolean hasError = false;
if (TextUtils.isEmpty(street)) {
hasError = true;
mStreetLayout.setErrorEnabled(true);
mStreetLayout.setError(getString(R.string.fill_the_field));
}
if (TextUtils.isEmpty(number)) {
hasError = true;
mNumberLayout.setErrorEnabled(true);
mNumberLayout.setError(getString(R.string.fill_the_field));
}
if (TextUtils.isEmpty(neighborhood)) {
hasError = true;
mNeighborhoodLayout.setErrorEnabled(true);
mNeighborhoodLayout.setError(getString(R.string.fill_the_field));
}
if (TextUtils.isEmpty(city)) {
hasError = true;
mCityLayout.setErrorEnabled(true);
mCityLayout.setError(getString(R.string.fill_the_field));
}
if (TextUtils.isEmpty(state)) {
hasError = true;
mStateLayout.setErrorEnabled(true);
mStateLayout.setError(getString(R.string.fill_the_field));
}
if (TextUtils.isEmpty(cep)) {
hasError = true;
mCepLayout.setErrorEnabled(true);
mCepLayout.setError(getString(R.string.fill_the_field));
}
if (TextUtils.isEmpty(phone)) {
hasError = true;
mPhoneLayout.setErrorEnabled(true);
mPhoneLayout.setError(getString(R.string.fill_the_field));
}
if (hasError) {
return;
}
final Address address = new Address();
if (mAddressEditing != null) {
mAddressEditing.setStreet(street);
mAddressEditing.setNumber(number);
mAddressEditing.setComplement(complement);
mAddressEditing.setNeighborhood(neighborhood);
mAddressEditing.setCity(city);
mAddressEditing.setState(state);
mAddressEditing.setCep(cep);
mAddressEditing.setPhone(phone);
} else {
address.setStreet(street);
address.setNumber(number);
address.setComplement(complement);
address.setNeighborhood(neighborhood);
address.setCity(city);
address.setState(state);
address.setCep(cep);
address.setPhone(phone);
}
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
if (mAddressEditing != null) {
MainApplication.getInstance().getAddressDao().update(mAddressEditing);
} else {
MainApplication.getInstance().getAddressDao().insert(address);
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
Toast.makeText(NewAddressActivity.this,
mAddressEditing != null ? R.string.address_edited_successfully :
R.string.address_created_successfully, Toast.LENGTH_SHORT).show();
setResult(Activity.RESULT_OK);
finish();
}
}.execute();
}
}
xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="wrap_content">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:id="@+id/street_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="50dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toTopOf="parent">
<EditText
android:id="@+id/street_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/street"
android:imeOptions="actionNext"
android:inputType="textCapSentences"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/number_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="50dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/street_layout">
<EditText
android:id="@+id/number_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/number"
android:imeOptions="actionNext"
android:inputType="textCapSentences"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/complement_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="50dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/number_layout">
<EditText
android:id="@+id/complement_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/complement"
android:imeOptions="actionNext"
android:inputType="textCapSentences"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/neighborhood_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="50dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/complement_layout">
<EditText
android:id="@+id/neighborhood_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/neighborhood"
android:imeOptions="actionNext"
android:inputType="textCapSentences"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/city_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="50dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/neighborhood_layout">
<EditText
android:id="@+id/city_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/city"
android:imeOptions="actionNext"
android:inputType="textCapSentences"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/state_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="50dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/city_layout">
<EditText
android:id="@+id/state_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/state"
android:imeOptions="actionNext"
android:inputType="textCapSentences"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/cep_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="50dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/state_layout">
<EditText
android:id="@+id/cep_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/cep"
android:imeOptions="actionNext"
android:inputType="number"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/phone_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="50dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/cep_layout">
<EditText
android:id="@+id/phone_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/phone"
android:imeOptions="actionDone"
android:inputType="phone|textCapSentences"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
如何在 java 上看到,mAddressEditing
变量是从 Intent 接收的,当它不为 null 时表示用户想要编辑其地址。
所有字段都按预期填写,但是当我点击编辑文本以更改其值时,它崩溃了...
崩溃:
FATAL EXCEPTION: main
Process: br.com.fornaro.armariovirtual, PID: 5540
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.getBoundsOnScreen(android.graphics.Rect)' on a null object reference at android.app.assist.AssistStructure$WindowNode.<init>(AssistStructure.java:484)
at android.app.assist.AssistStructure.<init>(AssistStructure.java:1908)
at android.app.ActivityThread.handleRequestAssistContextExtras(ActivityThread.java:3035)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1807)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
我不知道它为什么会崩溃。
重现步骤:1. 编辑上一个屏幕中的地址,将地址对象作为参数传递给 Intent 2.单击编辑文本以更改其值3. 崩溃!
最佳答案
问题是一个已知的 Android 错误。从 Google 问题跟踪器建议来看,在 TextInputEditText 上设置提示似乎会导致崩溃。仅在 TextInputLayout 上设置提示可修复崩溃。
This issue only happens IF the hint is set on the nested EditText inside the TextInputLayout. I resolved it by setting the hint on the TextInputLayout.
关于Android - 尝试在空对象引用上调用虚拟方法 'void android.view.View.getBoundsOnScreen(android.graphics.Rect)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45898228/
我已经为使用 JGroups 编写了简单的测试。有两个像这样的简单应用程序 import org.jgroups.*; import org.jgroups.conf.ConfiguratorFact
我有一个通过 ajax 检索的 json 编码数据集。我尝试检索的一些数据点将返回 null 或空。 但是,我不希望将那些 null 或空值显示给最终用户,或传递给其他函数。 我现在正在做的是检查
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: Why does one often see “null != variable” instead of “
嗨在我们公司,他们遵循与空值进行比较的严格规则。当我编码 if(variable!=null) 在代码审查中,我收到了对此的评论,将其更改为 if(null!=variable)。上面的代码对性能有影
我正在尝试使用 native Cordova QR 扫描仪插件编译项目,但是我不断收到此错误。据我了解,这是代码编写方式的问题,它向构造函数发送了错误的值,或者根本就没有找到构造函数。那么我该如何解决
我在装有 Java 1.8 的 Windows 10 上使用 Apache Nutch 1.14。我已按照 https://wiki.apache.org/nutch/NutchTutorial 中提
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: what is “=null” and “ IS NULL” Is there any difference bet
Three-EyedRaven 内网渗透初期,我们都希望可以豪无遗漏的尽最大可能打开目标内网攻击面,故,设计该工具的初衷是解决某些工具内网探测速率慢、运行卡死、服务爆破误报率高以及socks流
我想在Scala中像在Java中那样做: public void recv(String from) { recv(from, null); } public void recv(String
我正在尝试从一组图像补丁中创建一个密码本。我已将图像(Caltech 101)分成20 X 20图像块。我想为每个补丁创建一个SIFT描述符。但是对于某些图像补丁,它不返回任何描述符/关键点。我尝试使
我在验证器类中自动连接的两个服务有问题。这些服务工作正常,因为在我的 Controller 中是自动连接的。我有一个 applicationContext.xml 文件和 MyApp-servlet.
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 已关闭10 年前。 问题必须表现出对要解决的问题的最低程度的了解。告诉我们您尝试过做什么,为什么不起作用,以
大家好,我正在对数据库进行正常的选择,但是 mysql_num_rowsis 为空,我不知道为什么,我有 7 行选择。 如果您发现问题,请告诉我。 真的谢谢。 代码如下: function get_b
我想以以下格式创建一个字符串:id[]=%@&stringdata[]=%@&id[]=%@&stringdata[]=%@&id[]=%@&stringdata[]=%@&等,在for循环中,我得到
我正在尝试使用以下代码将URL转换为字符串: NSURL *urlOfOpenedFile = _service.myURLRequest.URL; NSString *fileThatWasOpen
我正在尝试将NSNumber传递到正在工作的UInt32中。然后,我试图将UInt32填充到NSData对象中。但是,这在这里变得有些时髦... 当我尝试将NSData对象中的内容写成它返回的字符串(
我正在进行身份验证并收到空 cookie。我想存储这个 cookie,但服务器没有返回给我 cookie。但响应代码是 200 ok。 httpConn.setRequestProperty(
我认为 Button bTutorial1 = (Button) findViewById(R.layout.tutorial1); bTutorial1.setOnClickListener
我的 Controller 中有这样的东西: model.attribute("hiringManagerMap",hiringManagerMap); 我正在访问此 hiringManagerMap
我想知道如何以正确的方式清空列表。在 div 中有一个列表然后清空 div 或列表更好吗? 我知道这是一个蹩脚的问题,但请帮助我理解这个 empty() 函数:) 案例)如果我运行这个脚本会发生什么:
我是一名优秀的程序员,十分优秀!