我要去NullPointerException在SharedPreferences。这是我的代码:
public void onClick(View v) {
phone = (EditText) findViewById(R.id.phoneno);
final String number = phone.getText().toString();
new AlertDialog.Builder(MainActivity.this)
.setMessage("Confirm
错误: android.content.Context.getApplicationContext()‘:试图在com.adriitsolutions.prarthana.AdapterForListView.MyRequestForBloodRequirementListRecyclerView$1.onClick(MyRequestForBloodRequirementListRecyclerView.java:153) at android.view.View.performClick(View.java:6935)的空对象引用上调用虚拟方法的android.content.Contex
由于onAttach(Activity)已被弃用,因此我在运行此代码时遇到了问题:
public void onClick(View v) {
if (v == loginButton){
application.getAuth().getUser().setIsLogedIn(true);
callbacks.onLoggedIn();
}
}
public void onAttach(Activity activity){
super.onAttach(activity);
callbacks = (Callbacks) a
我目前正在学习明确的意图,我遵循了所指示的编码,它总是返回一个NullPointerException。
这是我输入数据返回到MainActivity的代码:
if (etSurname.getText().toString().isEmpty())
{
Toast.makeText(Activity3.this, "Fill In A Surname!", Toast.LENGTH_SHORT).show();
}
else
{
创建生成器的代码:
builder = new AlertDialog.Builder(this);
builder.setPositiveButton("connect",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
devices.get(currentPos).setConnected(true);
这怎么可能呢?
适配器使用该位置绑定视图固定器,因此用户可以在屏幕上看到项目视图。
但是,用户单击该项目后,由于getItem( NullPointerException )返回null,因此会产生位置。
我的实现有什么问题吗?
适配器:
// There will be more than 1000 items, so the SparseArray will face the performance problem. That's why I choose to use Map.
private Map<Integer, ArticleBean> articleBean
我有个奇怪的问题。我的应用程序有一个自定义的对话框,其中有一个保存密码的按钮。它工作得很好。但有时它会崩溃(我也做同样的交互)。Logcat抛出一个NullPointerException。但是我检查了代码,没有找到导致这个错误的部件。
问题是很难模拟误差。它只是偶尔会发生。可能的原因是什么?应用程序有时会挂起,如果我再次按下按钮,它就会崩溃。
这是logcat:
java.lang.NullPointerException
at de.tapps.guardian.free.MainActivity$7$1.onClick(MainActivity.java:1312)
at android
我使用.xml视图的onClick方法来捕获.java类上的单击事件。
通常运行得很好。但是,当我的Activity在后台运行了很长一段时间后,转到主线程,有人单击了视图,它会返回以下异常:
java.lang.NullPointerException
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3608)
at android.view.View.performClick(View.java:4101)
at
我不知道为什么会出现这个错误:/
Exception class java.lang.NullPointerException
Source method Jax$7.onClick()
java.lang.NullPointerException
at com.reg.lolsoundboard.Jax$7.onClick(Jax.java:83)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9089)
at android.o
我想在多个类中使用相同的AlertDialog。下面是我用来显示AlertDialog的函数:
public void incorrectFields()
{
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mActivity);
String emptyFields = "Empty Field(s)";
String emptyFieldsMessage = "Please ensure all fields are contain dat
我有进度对话框:
mProgressDialog = new ProgressDialog(WebViewActivity.this);
有些按钮是这样的:
mProgressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
我使用此代码获取上下文菜单上单击的项位置:
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
int index = info.position;
}
如下所示:
但我接到NullPointerException的电话:
int index = info.position;
为什么会这样呢?
编辑
我有2次contextMenu的注册浏览量如下:
button1.onC
我正在Android Studio上做一个应用程序,我在我的onClick方法中遇到了NullPointerException。我该如何修复它? 我的应用程序的调试器给了我这个: java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:414)
at