This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 4 years ago.
I am having trouble adding items to my spinner from an Arraylist. I have it working in other parts of my code, but it wont work when I put it in my dialog.
The exact problem is that it causes the app to crash. The crash happens when I press the button to open the dialog.
Here is the problematic code:
public void transferButton(View view) {
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog_transfer);
ArrayList<String> file = new ArrayList();
List<String> accounts = new ArrayList();
File path = Environment.getExternalStorageDirectory();
File myExternalFile = new File(path.getAbsolutePath() + folderLoc, "accounts.txt");
try {
FileInputStream fis = new FileInputStream(myExternalFile);
DataInputStream in = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
file.add(strLine);
}
br.close();
in.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
ArrayAdapter<String> adapter1 = new ArrayAdapter(this, android.R.layout.simple_spinner_item);
ArrayAdapter<String> adapter2 = new ArrayAdapter(this, android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner fromSpinner = (Spinner) view.findViewById(R.id.fromAccountSpinner);
Spinner toSpinner = (Spinner) view.findViewById(R.id.toAccountSpinner);
for (int i = 0; i < file.size(); i++) {
String[] splitArray = file.get(i).split("//");
adapter1.add(splitArray[0]);
adapter2.add(splitArray[0]);
}
adapter1.insert("From...", 0);
fromSpinner.setAdapter(adapter1);
adapter2.insert("To...", 0);
toSpinner.setAdapter(adapter2);
Button dialogButton = (Button) dialog.findViewById(R.id.closeButton);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
Here is the error log:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.gstraatsma.gsfinancetracker, PID: 14493
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:6205)
at android.widget.TextView.performClick(TextView.java:11103)
at android.view.View$PerformClick.run(View.java:23653)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:6205)
at android.widget.TextView.performClick(TextView.java:11103)
at android.view.View$PerformClick.run(View.java:23653)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Spinner.setAdapter(android.widget.SpinnerAdapter)' on a null object reference
at com.gstraatsma.gsfinancetracker.MainActivity.transferButton(MainActivity.java:1258)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:6205)
at android.widget.TextView.performClick(TextView.java:11103)
at android.view.View$PerformClick.run(View.java:23653)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Change view.findViewById(R.id.fromAccountSpinner); to dialog.findViewById(R.id.fromAccountSpinner);
Related
This question already has answers here:
Unfortunately MyApp has stopped. How can I solve this?
(23 answers)
Closed 5 years ago.
I have a problem with my project. When I click the Search button, my application will crash on my phone. the "Search" button is a method where it retrieves information from SQLiteDatabase. This activity is Where Clause activity. Whenever I click the Search button, it crashes.
This is my coding:
package com.example.taza.rshinventorymanager;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Homepage extends AppCompatActivity
{
TextView locationoutput, quantityoutput, size1output, size2output, size3output,
size4output, size5output, size6output, size7output, size8output, size9output,
size10output, size11output, size12output, size13output, sizeXSoutput, sizeSoutput,
sizeMoutput, sizeLoutput, sizeXLoutput, size2XLoutput;
EditText searchproduct;
ProductDBHelper productDBHelper;
SQLiteDatabase sqLiteDatabase;
String Searchproduct;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homepage);
Button LoginButton = (Button)findViewById(R.id.HomepageLoginButton);
LoginButton.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent startIntent = new Intent(getApplicationContext(), LoginPage.class);
startActivity(startIntent);
}
});
searchproduct = (EditText)findViewById(R.id.HomepageET);
locationoutput = (TextView)findViewById(R.id.HPLocation);
quantityoutput = (TextView)findViewById(R.id.HPQuantity);
size1output = (TextView)findViewById(R.id.HP1);
size2output = (TextView)findViewById(R.id.HP2);
size3output = (TextView)findViewById(R.id.HP3);
size4output = (TextView)findViewById(R.id.HP4);
size5output = (TextView)findViewById(R.id.HP5);
size6output = (TextView)findViewById(R.id.HP6);
size7output = (TextView)findViewById(R.id.HP7);
size8output = (TextView)findViewById(R.id.HP8);
size9output = (TextView)findViewById(R.id.HP9);
size10output = (TextView)findViewById(R.id.HP10);
size11output = (TextView)findViewById(R.id.HP11);
size12output = (TextView)findViewById(R.id.HP12);
size13output = (TextView)findViewById(R.id.HP13);
sizeXSoutput = (TextView)findViewById(R.id.HPXS);
sizeSoutput = (TextView)findViewById(R.id.HPS);
sizeMoutput = (TextView)findViewById(R.id.HPM);
sizeLoutput = (TextView)findViewById(R.id.HPL);
sizeXLoutput = (TextView)findViewById(R.id.HPXL);
size2XLoutput = (TextView)findViewById(R.id.HP2XL);
locationoutput.setVisibility(View.GONE);
quantityoutput.setVisibility(View.GONE);
size1output.setVisibility(View.GONE);
size1output.setVisibility(View.GONE);
size2output.setVisibility(View.GONE);
size3output.setVisibility(View.GONE);
size4output.setVisibility(View.GONE);
size5output.setVisibility(View.GONE);
size6output.setVisibility(View.GONE);
size7output.setVisibility(View.GONE);
size8output.setVisibility(View.GONE);
size9output.setVisibility(View.GONE);
size10output.setVisibility(View.GONE);
size11output.setVisibility(View.GONE);
size12output.setVisibility(View.GONE);
size13output.setVisibility(View.GONE);
sizeXSoutput.setVisibility(View.GONE);
sizeSoutput.setVisibility(View.GONE);
sizeMoutput.setVisibility(View.GONE);
sizeLoutput.setVisibility(View.GONE);
sizeXLoutput.setVisibility(View.GONE);
size2XLoutput.setVisibility(View.GONE);
}
public void SearchProduct (View view)
{
Searchproduct = searchproduct.getText().toString();
productDBHelper = new ProductDBHelper(getApplicationContext());
sqLiteDatabase = productDBHelper.getReadableDatabase();
Cursor cursor = productDBHelper.getProduct(Searchproduct, sqLiteDatabase);
if(cursor.moveToFirst())
{
String locationsearch = cursor.getString(0);
String quantitysearch = cursor.getString(1);
String size1search = cursor.getString(2);
String size2search = cursor.getString(3);
String size3search = cursor.getString(4);
String size4search = cursor.getString(5);
String size5search = cursor.getString(6);
String size6search = cursor.getString(7);
String size7search = cursor.getString(8);
String size8search = cursor.getString(9);
String size9search = cursor.getString(10);
String size10search = cursor.getString(11);
String size11search = cursor.getString(12);
String size12search = cursor.getString(13);
String size13search = cursor.getString(14);
String sizeXSsearch = cursor.getString(15);
String sizeSsearch = cursor.getString(16);
String sizeMsearch = cursor.getString(17);
String sizeLsearch = cursor.getString(18);
String sizeXLsearch = cursor.getString(19);
String size2XLsearch = cursor.getString(20);
locationoutput.setText(locationsearch);
quantityoutput.setText(quantitysearch);
size1output.setText(size1search);
size2output.setText(size2search);
size3output.setText(size3search);
size4output.setText(size4search);
size5output.setText(size5search);
size6output.setText(size6search);
size7output.setText(size7search);
size8output.setText(size8search);
size9output.setText(size9search);
size10output.setText(size10search);
size11output.setText(size11search);
size12output.setText(size12search);
size13output.setText(size13search);
sizeXSoutput.setText(sizeXSsearch);
sizeSoutput.setText(sizeSsearch);
sizeMoutput.setText(sizeMsearch);
sizeLoutput.setText(sizeLsearch);
sizeXLoutput.setText(sizeXLsearch);
size2XLoutput.setText(size2XLsearch);
locationoutput.setVisibility(View.VISIBLE);
quantityoutput.setVisibility(View.VISIBLE);
size1output.setVisibility(View.VISIBLE);
size1output.setVisibility(View.VISIBLE);
size2output.setVisibility(View.VISIBLE);
size3output.setVisibility(View.VISIBLE);
size4output.setVisibility(View.VISIBLE);
size5output.setVisibility(View.VISIBLE);
size6output.setVisibility(View.VISIBLE);
size7output.setVisibility(View.VISIBLE);
size8output.setVisibility(View.VISIBLE);
size9output.setVisibility(View.VISIBLE);
size10output.setVisibility(View.VISIBLE);
size11output.setVisibility(View.VISIBLE);
size12output.setVisibility(View.VISIBLE);
size13output.setVisibility(View.VISIBLE);
sizeXSoutput.setVisibility(View.VISIBLE);
sizeSoutput.setVisibility(View.VISIBLE);
sizeMoutput.setVisibility(View.VISIBLE);
sizeLoutput.setVisibility(View.VISIBLE);
sizeXLoutput.setVisibility(View.VISIBLE);
size2XLoutput.setVisibility(View.VISIBLE);
}
}
}
I found the Logcat after i debug. Here's the error:
01-24 12:07:21.692 3720-3720/? E/DATABASE OPERATIONS: Database created / opened...
01-24 12:07:21.695 3720-3720/? E/SQLiteLog: (1) near "TABLEproduct_information": syntax error
01-24 12:07:21.695 3720-3720/? D/AndroidRuntime: Shutting down VM
01-24 12:07:21.696 3720-3720/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.taza.rshinventorymanager, PID: 3720
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.database.sqlite.SQLiteException: near "TABLEproduct_information": syntax error (code 1): , while compiling: CREATE TABLEproduct_information(product_codeTEXT,product_locationTEXT,product_quantityTEXT,size_1TEXT,size_2TEXT,size_3TEXT,size_4TEXT,size_5TEXT,size_6TEXT,size_7TEXT,size_8TEXT,size_9TEXT,size_10TEXT,size_11TEXT,size_12TEXT,size_13TEXT,size_XSTEXT,size_STEXT,size_MTEXT,size_LTEXT,size_XLTEXT,size_2XLTEXT)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1674)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605)
at com.example.taza.rshinventorymanager.ProductDBHelper.onCreate(ProductDBHelper.java:52)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187)
at com.example.taza.rshinventorymanager.Homepage.SearchProduct(Homepage.java:101)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
You are writing onClick method inside onCreate
#Override
public void onClick(View v)
{
Intent startIntent = new Intent(getApplicationContext(), LoginPage.class);
startActivity(startIntent);
}
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Null pointer Exception - findViewById()
(12 answers)
Closed 5 years ago.
My app is crashing everytime I try to click a button that inputs text into a listView, I am getting the "java.lang.IllegalStateException: Could not execute method for android:onClick"; I've tried other solutions to the problem but I can't seem to find my own solution. Any help is appreciated.
MainActivity.java
public class MainActivity extends AppCompatActivity {
ListView listView;
ArrayList<String> arrayList;
ArrayAdapter<String> arrayAdapter;
String infoText;
int position;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread thread = new Thread(new Runnable(){
#Override
public void run(){
SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean isFirstStart = getPrefs.getBoolean("started",true);
if(isFirstStart)
{
startActivity(new Intent (MainActivity.this,Intro.class));
SharedPreferences.Editor e = getPrefs.edit();
e.putBoolean("started", false);
e.apply();
}
}
});
thread.start();
listView = (ListView) findViewById(R.id.ListView);
arrayList = new ArrayList<>();
arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arrayList);
listView.setAdapter(arrayAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent();
intent.setClass(MainActivity.this,EditMessageClass.class);
intent.putExtra(Intent_Constants.INTENT_INFO_DATA,arrayList.get(position).toString());
intent.putExtra(Intent_Constants.INTENT_ITEM_POSITION,position);
startActivityForResult(intent,Intent_Constants.INTENT_REQUEST_CODE_2);
}
});
}
public void onClick(View v){
Intent intent = new Intent();
intent.setClass(MainActivity.this,EditFieldClass.class);
startActivityForResult(intent,Intent_Constants.INTENT_REQUEST_CODE);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (resultCode==Intent_Constants.INTENT_REQUEST_CODE){
infoText = data.getStringExtra(Intent_Constants.INTENT_INFO_FIELD);
arrayList.add(infoText);
arrayAdapter.notifyDataSetChanged();
}
else if(resultCode==Intent_Constants.INTENT_REQUEST_CODE_2){
infoText = data.getStringExtra(Intent_Constants.INTENT_CHANGED_INFO);
position = data.getIntExtra(Intent_Constants.INTENT_ITEM_POSITION,-1);
arrayList.remove(position);
arrayList.add(position,infoText);
arrayAdapter.notifyDataSetChanged();
}
}
}
Intent_Constants.java
public class Intent_Constants {
public final static int INTENT_REQUEST_CODE=1;
public final static int INTENT_RESULT_CODE=1;
public final static int INTENT_REQUEST_CODE_2=2;
public final static int INTENT_RESULT_CODE_2=2;
public final static String INTENT_INFO_FIELD="info_field";
public final static String INTENT_INFO_DATA="info_data";
public final static String INTENT_ITEM_POSITION="item_position";
public final static String INTENT_CHANGED_INFO="changed_info";
EditMessageClass.java
public class EditMessageClass extends AppCompatActivity {
String infoText;
int position;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_promo_layout);
Intent intent = getIntent();
infoText = intent.getStringExtra(Intent_Constants.INTENT_INFO_DATA);
position = intent.getIntExtra(Intent_Constants.INTENT_ITEM_POSITION,-1);
EditText infoData = (EditText) findViewById(R.id.info);
infoData.setText(infoText);
}
public void saveButtonClicked(View v){
String changedinfoText = ((EditText)findViewById(R.id.info)).getText().toString();
Intent intent = new Intent();
intent.putExtra(Intent_Constants.INTENT_CHANGED_INFO,changedinfoText);
intent.putExtra(Intent_Constants.INTENT_ITEM_POSITION, position);
setResult(Intent_Constants.INTENT_RESULT_CODE_2,intent);
finish();
}
}
EditFieldClass.java
public class EditFieldClass extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_promo_layout);
}
public void saveButtonClicked(View v){
String infoText = ((EditText)findViewById(R.id.info)).getText().toString();
if(infoText.equals("")){
}
else{
Intent intent = new Intent();
intent.putExtra(Intent_Constants.INTENT_INFO_FIELD,infoText);
setResult(Intent_Constants.INTENT_RESULT_CODE,intent);
finish();
}
}
}
Logs
FATAL EXCEPTION: main
Process: gabriel.com.prototype, PID: 15435
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
at gabriel.com.prototype.EditFieldClass.saveButtonClicked(EditFieldClass.java:27)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
According to your logcat message, I can say that your EditText object is null
the problem is caused by this line.
((EditText)findViewById(R.id.info)).getText().toString()
Make sure you have EditText with id 'info' in EditFieldClass.
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference
at gabriel.com.prototype.EditFieldClass.saveButtonClicked(EditFieldClass.java:27)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
your EditText is null , check editText id .
public class MainActivity extends AppCompatActivity {
public void grade (View view){
final EditText varEditBox = (EditText)findViewById(R.id.editBox);
TextView varText = (TextView) findViewById(R.id.textView);
Button button = (Button) findViewById(R.id.button);
if (varEditBox.getText().toString().isEmpty()){
Toast.makeText(getApplicationContext(), "EMPTY", Toast.LENGTH_SHORT).show();
varText.setText( "");
}
if ((Integer.parseInt(varEditBox.getText().toString() )>=101)||(Integer.parseInt(varEditBox.getText().toString() )<1) ){
Toast.makeText(getApplicationContext(), "Invalid", Toast.LENGTH_SHORT).show();
varText.setText( "");
} }
I have the above code with a condition to check if the EditText box is empty, but any time I press the button with an empty EditBox, the app crashes. I've been debugging but no success. Normally I get this error when I don't do the check, now I've done the check, it's still here. Plus the varEditBox isn't empty, because the other if statement runs as well. If I put in a number more than 100, it toasts "invalid" thus, the second condition works
LogCat error. I'm not sure if I have to post all of it, but this is the error I get
FATAL EXCEPTION: main
Process: com.listener.gradesystem, PID: 31936
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5156)
at android.view.View$PerformClick.run(View.java:20755)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5835)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5156)
at android.view.View$PerformClick.run(View.java:20755)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5835)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.NumberFormatException: Invalid int: ""
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parseInt(Integer.java:358)
at java.lang.Integer.parseInt(Integer.java:334)
at com.listener.gradesystem.MainActivity.grade(MainActivity.java:24)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5156)
at android.view.View$PerformClick.run(View.java:20755)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5835)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.NumberFormatException: Invalid int: ""
One of you Integer.parseInt calls is failing. I can only assume you somehow have whitespace in your string. If your EditText only allows more than just numbers, consider doing this:
public void grade (View view){
final EditText varEditBox = (EditText)findViewById(R.id.editBox);
TextView varText = (TextView) findViewById(R.id.textView);
Button button = (Button) findViewById(R.id.button);
// trim to remove whitespace
final String text = varEditBox.getText().toString().trim();
if (TextUtils.isEmpty(text) || !TextUtils.isDigitsOnly(text)){
Toast.makeText(getApplicationContext(), "EMPTY OR NOT NUMERIC", Toast.LENGTH_SHORT).show();
varText.setText("");
// quit early, don't need to parse this number
return;
}
// we should have already quit by now if we can't parse this number
int value = Integer.parseInt(text);
if (value >= 101 || value < 1) {
Toast.makeText(getApplicationContext(), "Invalid", Toast.LENGTH_SHORT).show();
varText.setText("");
}
}
If this still fails, at least it will highlight where your problem is.
Try this.The problem was in your if else condition.
final EditText varEditBox = (EditText)findViewById(R.id.editBox);
TextView varText = (TextView) findViewById(R.id.textView);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (varEditBox.getText().toString().trim().isEmpty()){
Toast.makeText(getApplicationContext(), "EMPTY", Toast.LENGTH_SHORT).show();
varText.setText( "");
}
else{
if ((Integer.parseInt(varEditBox.getText().toString())>=101)||(Integer.parseInt(varEditBox.getText().toString() )<1) ){
Toast.makeText(getApplicationContext(), "Invalid", Toast.LENGTH_SHORT).show();
varText.setText( "");
}
}
}
});
I'm begginer in Android programming, I'm trying to make the login function. This system will be accessed by two users which are admin and users. The admin just need to enter the "admin" for the username and password to access the system. However, the users needs to register their account before login the system.
I'm trying to find the errors but still don't know the error occurrence. Please help me to solve the errors. Thank You.
DatabaseOperations.java
public Cursor getInformation(DatabaseOperations dob)
{
SQLiteDatabase database=dob.getReadableDatabase();
String[] columns={TableInfo.USERNAME,TableInfo.USERPASS};
Cursor cr=database.query(TableInfo.TABLE_NAME,columns,null,null,null,null,null);
return cr;
}
MainActivity.java
public void onClick(View view)
Toast.makeText(getBaseContext(), "Please wait....", Toast.LENGTH_LONG).show();
txtusername = Username.getText().toString();
txtpassword = Password.getText().toString();
DatabaseOperations dop = new DatabaseOperations(this, null, null, 1);
Cursor CR = dop.getInformation(dop);
CR.moveToFirst();
boolean login_status = false;
String NAME = "";
if (txtusername.equals("Admin") && (txtpassword).equals("Admin")) {
Intent in = new Intent(MainActivity.this, AdminMenu.class);
startActivity(in);
} else {
do {
if (txtusername.equals(CR.getString(0)) && (txtpassword.equals(CR.getString(1)))) {
login_status = true;
NAME = CR.getString(0);
}
} while (CR.moveToNext());
if (login_status) {
Toast.makeText(getBaseContext(), "Login Success....\n Welcome " + NAME, Toast.LENGTH_LONG).show();
Intent i=new Intent(MainActivity.this,UserMenu.class);
Bundle bundle=new Bundle();
bundle.putString("username",NAME);
i.putExtras(bundle);
startActivity(i);
finish();
} else {
Toast.makeText(getBaseContext(), "Login Failed...", Toast.LENGTH_LONG).show();
Intent i = new Intent();
Bundle bundle=new Bundle();
bundle.putString("username",NAME);
i.putExtras(bundle);
startActivity(i);
finish();
}
}
}
This is the error...
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.mobile_flexi_parking, PID: 6777
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1798)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
at android.app.Activity.startActivityForResult(Activity.java:3917)
at android.app.Activity.startActivityForResult(Activity.java:3877)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:842)
at android.app.Activity.startActivity(Activity.java:4200)
at android.app.Activity.startActivity(Activity.java:4168)
at com.google.mobile_flexi_parking.MainActivity.onclickLogin(MainActivity.java:67)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
In your else part you have blank intent which doesn't point any activity
Intent i = new Intent();
I think this is causing error.
In my app the user can open the settings menu (which is a PreferenceActivity) by pressing a button. This works fine on the AVD, but when I try to use it on a real device it doesn't work. I don't know how this happened and I hope someone can help me.
Here is my PreferenceActivity:
public class ActivityPref extends PreferenceActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref);
Preference preferences=findPreference("key");
preferences.setIntent(new Intent(this, PwdChange.class));
showNoti();
checkForBackUp();
}
private void checkForBackUp() {
final CheckBoxPreference cb = (CheckBoxPreference) getPreferenceManager().findPreference("backUp");
cb.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
#Override
public boolean onPreferenceClick(Preference preference) {
if(preference.isEnabled()){
final String inFileName = "/data/data/com.sus.pwd/databases/my_d";
String outFileName = Environment.getExternalStorageDirectory()+"/database_copy.db";
OutputStream output = null;
FileInputStream fis=null;
File dbFile = new File(inFileName);
try {
fis = new FileInputStream(dbFile);
output = new FileOutputStream(outFileName);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// Transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
try {
while ((length = fis.read(buffer))>0){
try {
output.write(buffer, 0, length);
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
}
try {
output.flush();
output.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return true;
}
});
}
private void showNoti() {
final CheckBoxPreference cb = (CheckBoxPreference) getPreferenceManager().findPreference("key1");
cb.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
#Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean myValue = (Boolean) newValue;
if (newValue.toString().equals("true")) {
Context context = getApplicationContext();
Toast.makeText(context, "start..", Toast.LENGTH_SHORT).show();
Log.e("value", String.valueOf(myValue));
NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.delete);
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(context, 1, intent, 0);
builder.setContentIntent(pIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notif = builder.build();
mNotificationManager.notify(1, notif);
} else if (newValue.toString().equals("false")) {
Toast.makeText(getApplicationContext(), "stop..", Toast.LENGTH_SHORT).show();
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(1);
}
return true;
}
});
}
}
Here is my main activity:
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id==R.id.settings){
startActivity(new Intent(this, ActivityPref.class));
}
}
And here is the LogCat:
05-20 17:28:19.476 11771-11771/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sushanta.reminderpwd, PID: 11771
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sushanta.reminderpwd/com.sushanta.reminderpwd.ActivityPref}: android.view.InflateException: Binary XML file line #41: Error inflating class java.lang.reflect.Constructor
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #41: Error inflating class java.lang.reflect.Constructor
at android.preference.GenericInflater.createItem(GenericInflater.java:397)
at android.preference.GenericInflater.onCreateItem(GenericInflater.java:417)
at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:428)
at android.preference.GenericInflater.rInflate(GenericInflater.java:481)
at android.preference.GenericInflater.rInflate(GenericInflater.java:493)
at android.preference.GenericInflater.inflate(GenericInflater.java:326)
at android.preference.GenericInflater.inflate(GenericInflater.java:263)
at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:276)
at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:1512)
at com.sushanta.reminderpwd.ActivityPref.onCreate(ActivityPref.java:29)
at android.app.Activity.performCreate(Activity.java:5264)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.preference.GenericInflater.createItem(GenericInflater.java:383)
at android.preference.GenericInflater.onCreateItem(GenericInflater.java:417)
at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:428)
at android.preference.GenericInflater.rInflate(GenericInflater.java:481)
at android.preference.GenericInflater.rInflate(GenericInflater.java:493)
at android.preference.GenericInflater.inflate(GenericInflater.java:326)
at android.preference.GenericInflater.inflate(GenericInflater.java:263)
at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:276)
at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:1512)
at com.sushanta.reminderpwd.ActivityPref.onCreate(ActivityPref.java:29)
at android.app.Activity.performCreate(Activity.java:5264)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.content.res.AssetManager.getResourceTextArray(AssetManager.java:228)
at android.content.res.Resources.getTextArray(Resources.java:458)
at android.content.res.TypedArray.getTextArray(TypedArray.java:629)
at android.preference.ListPreference.<init>(ListPreference.java:51)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.preference.GenericInflater.createItem(GenericInflater.java:383)
at android.preference.GenericInflater.onCreateItem(GenericInflater.java:417)
at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:428)
at android.preference.GenericInflater.rInflate(GenericInflater.java:481)
at android.preference.GenericInflater.rInflate(GenericInflater.java:493)
at android.preference.GenericInflater.inflate(GenericInflater.java:326)
at android.preference.GenericInflater.inflate(GenericInflater.java:263)
at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:276)
at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:1512)
at com.sushanta.reminderpwd.ActivityPref.onCreate(ActivityPref.java:29)
at android.app.Activity.performCreate(Activity.java:5264)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
05-20 17:28:21.049 25577-25577/? E/NotificationService: unable to notify listener (removed): android.service.notification.INotificationListener$Stub$Proxy#428150b0
android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.service.notification.INotificationListener$Stub$Proxy.onNotificationRemoved(INotificationListener.java:120)
at com.android.server.NotificationManagerService$NotificationListenerInfo.notifyRemovedIfUserMatch(NotificationManagerService.java:273)
at com.android.server.NotificationManagerService$3.run(NotificationManagerService.java:854)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at com.android.server.ServerThread.initAndLoop(SystemServer.java:1452)
at com.android.server.SystemServer.main(SystemServer.java:1547)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
//pref.xml
<Preference
android:title="Change Master password"
android:key="key"/>
<CheckBoxPreference
android:title="Notification on Action Bar"
android:key="key1"
android:defaultValue="true"/>
<CheckBoxPreference
android:title="Back up"
android:key="backUp"
android:summary="Load data to external device"
android:defaultValue="false"/>
<CheckBoxPreference
android:title="Auto Exit"
android:summary="The Application will automatically exit when the screen turns off"
android:defaultValue="true"/>