Getting IllegalStateException on button click and Application is stopped - java

I am creating an application using Android Studio and Genymotion as an emulator, in which i am entering the data in 3 EditTexts, when i click the button to store it in sqlite database then it is not working.. and this is what i see in LOGCAT
FATAL EXCEPTION: main
Process: com.example.aadeshmishra.com.sdk18, PID: 1551
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:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:4438) 
at android.view.View$PerformClick.run(View.java:18422) 
at android.os.Handler.handleCallback(Handler.java:733) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5001) 
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:785) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.NullPointerException
at com.example.aadeshmishra.com.sdk18.ThirdActitvity.addData(ThirdActitvity.java:64)
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288) 
at android.view.View.performClick(View.java:4438) 
at android.view.View$PerformClick.run(View.java:18422) 
at android.os.Handler.handleCallback(Handler.java:733) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5001) 
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:785) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
at dalvik.system.NativeStart.main(Native Method) 
The button will call a method named addData() which is in ThirdActivity.
here the code for ThirdActivity.java
public class ThirdActitvity extends AppCompatActivity {
EditText ed1,ed2,ed3;
Button B1;
UserDBHelper mydb;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_third);
ed1 = (EditText)findViewById(R.id.E1);
ed2 = (EditText)findViewById(R.id.E2);
ed3 = (EditText)findViewById(R.id.E3);
B1 = (Button) findViewById(R.id.addB);
}
public void addData(View view)
{
String name = ed1.getText().toString();
String desc = ed2.getText().toString();
String contact = ed3.getText().toString();
Boolean r1 = mydb.insertDataClient(name,desc,contact);
if(r1 == true)
{
Toast.makeText(this,"Data inserted",Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(this,"Data not inserted",Toast.LENGTH_LONG).show();
}
}
}
Here the Code for activity_third.xml
<EditText
android:id="#+id/E1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/client"
android:textSize="20sp"
android:layout_marginEnd="20dp"/>
<EditText
android:id="#+id/E2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/destail"
android:textSize="20sp"
android:layout_alignEnd="#+id/E1" />
<EditText
android:id="#+id/E3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="#string/EN"
android:textSize="20sp"
android:layout_marginBottom="18dp"
android:layout_above="#+id/addB"
/>
<Button
android:id="#+id/addB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="49dp"
android:text="#string/add"
android:textSize="20sp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="addData"
/>
And at Last the UserDbHelper.java
public class UserDBHelper extends SQLiteOpenHelper {
// Database Details
private static final int DB_VER = 1;
private static final String DB_NAME = "DIARY_DB";
// Table Name
private static final String table_clientinfo = "Client_Info";
// columns
private static final String name = "Name";
private static final String desc = "Desc";
private static final String cont = "Contact";
// Create table -- ClientInfo
private String Create_ClientInfo = "Create table "+ table_clientinfo +"(" + id + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ name + " TEXT ," + desc + " TEXT,"
+ cont + " INTEGER)";
public UserDBHelper(Context context)
{
super(context,DB_NAME,null,DB_VER);
}
#Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL(Create_ClientInfo);
db.close();
}
#Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
}
public Boolean insertDataClient(String Name, String Desc, String Contact)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues con = new ContentValues();
con.put(name,Name);
con.put(desc,Desc);
con.put(cont,Contact);
long r = db.insert(table_clientinfo,null,con);
db.close();
if(r == -1)
{
return false;
}
else
{
return true;
}
}}
Can anyone tell what's the problem..?
thanks in advance..!

You need to initialize mydb in onCreate (or before using it anywhere though oncreate executed only once so better to do it inside onCreate) as
UserDBHelper mydb;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_third);
mydb = new UserDBHelper(this);
//^^^^^^^^^^^^^^^^^^^^^
ed1 = (EditText)findViewById(R.id.E1);
ed2 = (EditText)findViewById(R.id.E2);
ed3 = (EditText)findViewById(R.id.E3);
B1 = (Button) findViewById(R.id.addB);
}

Related

Error inflating class <unknown> - app crashes

In an Android app that I developed, the app crashes when I move to a certain activity. I saw that many people encountered a similar problem before, but none of the former answers solve my problem.
Here's the relevant code:
StillsActivity.java
the code crashes on the last line of this snippet
public class StillsActivity extends SpatialFilteringActivity {
private static final int SELECT_PICTURE = 1;
private static final String TAG = "Stills";
private Uri mURI;
private Bitmap mBitmap;
private ImageView mImageView;
private Mat mImToProcess = new Mat();
private Mat mImGray = new Mat();
private Mat mFilteredImage = new Mat();
private SeekBar mSeekBarSpatial;
private SeekBar mSeekBarIntensity;
private SeekBar mSeekBarAlpha;
private SeekBar mSeekBarBeta;
private TextView mTextViewSpatial;
private TextView mTextViewIntensity;
private TextView mTextViewAlpha;
private TextView mTextViewBeta;
private MenuItem mSelectedItem;
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SELECT_PICTURE) {
if (resultCode == RESULT_OK) {
mURI = data.getData();
if (mURI != null) {
try {
mBitmap = Util.getBitmap(this, mURI);
mImageView.setImageBitmap(Util.getResizedBitmap(mBitmap,
1000));
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stills);
// APP CRASHES HERE
mImageView = (ImageView) findViewById(R.id.imageView1);
Button loadButton = (Button) findViewById(R.id.loadButton);
loadButton.setOnClickListener(new View.OnClickListener() {
#SuppressLint("SimpleDateFormat")
#Override
public void onClick(View v) {
Log.i(TAG, "onClick event");
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select an image"), SELECT_PICTURE);
}
});
mSeekBarSpatial = (SeekBar) findViewById(R.id.seekBarSpatial);
mTextViewSpatial = (TextView) findViewById(R.id.sigmaSpatialTextView);
setSeekBar(mSeekBarSpatial, mTextViewSpatial, getResources().getString(R.string.stringSpatial), MyImageProc.SIGMA_SPATIAL_MAX);
mSeekBarIntensity = (SeekBar) findViewById(R.id.seekBarIntensity);
mTextViewIntensity = (TextView) findViewById(R.id.sigmaIntensityTextView);
setSeekBar(mSeekBarIntensity, mTextViewIntensity, getResources().getString(R.string.stringIntensity), MyImageProc.SIGMA_INTENSITY_MAX);
mSeekBarAlpha = (SeekBar) findViewById(R.id.seekBarAlpha);
mTextViewAlpha = (TextView) findViewById(R.id.alphaTextView);
setSeekBar(mSeekBarAlpha, mTextViewAlpha, getResources().getString(R.string.stringAlpha), MyImageProc.ALPHA_MAX);
mSeekBarBeta = (SeekBar) findViewById(R.id.seekBarBeta);
mTextViewBeta = (TextView) findViewById(R.id.betaTextView);
setSeekBar(mSeekBarBeta, mTextViewBeta, getResources().getString(R.string.stringBeta), MyImageProc.BETA_MAX);
}
// etc.
SpatialFilteringActivity.java
public class SpatialFilteringActivity extends AppCompatActivity {
private static final String TAG = "SpatialFiltering";
//menu members
private SubMenu mResolutionSubMenu;
private SubMenu mCameraSubMenu;
//flags
private Boolean mSettingsMenuAvailable =false;
protected static final int SETTINGS_GROUP_ID = 1;
protected static final int RESOLUTION_GROUP_ID = 2;
protected static final int CAMERA_GROUP_ID = 3;
protected static final int DEFAULT_GROUP_ID = 4;
protected static final int COLOR_GROUP_ID = 5;
protected static final int FILTER_GROUP_ID = 6;
protected static final int STILL_GROUP_ID = 7;
private MyJavaCameraView mOpenCvCameraView;
private CameraListener mCameraListener = new CameraListener();
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
#Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
Log.i(TAG, "OpenCV loaded successfully");
mOpenCvCameraView.enableView();
break;
default:
super.onManagerConnected(status);
break;
}
}
};
private String[] mCameraNames = {"Front", "Rear"};
private int[] mCameraIDarray = {CameraBridgeViewBase.CAMERA_ID_FRONT, CameraBridgeViewBase.CAMERA_ID_BACK};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_spatial_filtering);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mOpenCvCameraView = (MyJavaCameraView) findViewById(R.id.Java_Camera_View);
mOpenCvCameraView.setCameraIndex(CameraBridgeViewBase.CAMERA_ID_ANY);
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
mOpenCvCameraView.setCvCameraViewListener(mCameraListener);
Button saveButton = (Button) findViewById(R.id.saveButton);
saveButton.setOnClickListener(new View.OnClickListener() {
#SuppressLint("SimpleDateFormat")
#Override
public void onClick(View v) {
Log.i(TAG, "onClick event");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
String currentDateandTime = sdf.format(new Date());
String fileName = Environment.getExternalStorageDirectory().getPath() +
"/sample_picture_" + currentDateandTime + ".jpg";
mOpenCvCameraView.takePicture(fileName);
addImageToGallery(fileName, SpatialFilteringActivity.this);
Toast.makeText(SpatialFilteringActivity.this, fileName + " saved",
Toast.LENGTH_SHORT).show();
}
});
}
//etc.
activity_stills.xml
<?xml version="1.0" encoding="utf-8"?>
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="il.ac.tau.adviplab.iplab2_hn.StillsActivity">
<ImageView
android:contentDescription="#string/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView1"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:src="#drawable/loadimage"
android:adjustViewBounds="true"
android:layout_centerVertical="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/load_button"
android:id="#+id/loadButton"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/seekBarSpatial"
android:layout_marginTop="13dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="#+id/sigmaSpatialTextView"
android:layout_alignStart="#+id/sigmaSpatialTextView"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:id="#+id/sigmaSpatialTextView"
android:text="#string/stringSpatial"
android:layout_below="#+id/seekBarSpatial"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/seekBarIntensity"
android:layout_marginTop="15dp"
android:layout_below="#+id/sigmaSpatialTextView"
android:layout_alignLeft="#+id/sigmaSpatialTextView"
android:layout_alignStart="#+id/sigmaSpatialTextView"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:id="#+id/sigmaIntensityTextView"
android:text="#string/stringIntensity"
android:layout_below="#+id/seekBarIntensity"
android:layout_alignLeft="#+id/seekBarIntensity"
android:layout_alignStart="#+id/seekBarIntensity"/>
<SeekBar
android:id="#+id/seekBarAlpha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_below="#+id/sigmaIntensityTextView"
android:layout_alignLeft="#+id/alphaTextView"
android:layout_alignStart="#+id/alphaTextView"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/alphaTextView"
android:text="#string/stringAlpha"
android:layout_marginTop="12dp"
android:layout_below="#+id/seekBarAlpha"
android:layout_alignLeft="#+id/sigmaIntensityTextView"
android:layout_alignStart="#+id/sigmaIntensityTextView"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/seekBarBeta"
android:layout_marginTop="8dp"
android:layout_below="#+id/alphaTextView"
android:layout_alignLeft="#+id/alphaTextView"
android:layout_alignStart="#+id/alphaTextView"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/betaTextView"
android:text="#string/stringBeta"
android:layout_below="#+id/seekBarBeta"
android:layout_alignLeft="#+id/seekBarBeta"
android:layout_alignStart="#+id/seekBarBeta"/>
</RelativeLayout>
note: the #drawable/loadimage is 1000*978 pixels, if that matters
Logs
java.lang.RuntimeException: Unable to start activity ComponentInfo{il.ac.tau.adviplab.iplab2_hn/il.ac.tau.adviplab.iplab2_hn.StillsActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2450)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5466)
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.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at il.ac.tau.adviplab.iplab2_hn.StillsActivity.onCreate(StillsActivity.java:73)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5466) 
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.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at il.ac.tau.adviplab.iplab2_hn.StillsActivity.onCreate(StillsActivity.java:73) 
at android.app.Activity.performCreate(Activity.java:6251) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5466) 
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.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at il.ac.tau.adviplab.iplab2_hn.StillsActivity.onCreate(StillsActivity.java:73) 
at android.app.Activity.performCreate(Activity.java:6251) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5466) 
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.UnsupportedOperationException: Can't convert to dimension: type=0x1
at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:666)
at android.view.View.<init>(View.java:3969)
at android.view.ViewGroup.<init>(ViewGroup.java:573)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:248)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:244)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:240)
at java.lang.reflect.Constructor.newInstance(Native Method) 
at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58) 
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762) 
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at il.ac.tau.adviplab.iplab2_hn.StillsActivity.onCreate(StillsActivity.java:73) 
at android.app.Activity.performCreate(Activity.java:6251) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2520) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5466) 
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) 
I'd appreciate any help.
Thanks!
Please follow background image size
For Supported device
LDPI:
Portrait: 200x320px
Landscape: 320x200px
MDPI:
Portrait: 320x480px
Landscape: 480x320px
HDPI:
Portrait: 480x800px
Landscape: 800x480px
XHDPI:
Portrait: 720px1280px
Landscape: 1280x720px

currency convertor app not working

activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
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="edu.uncc.sbagursu.currencyconvertor.MainActivity">
<EditText
android:hint="Input Amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="#+id/inputAmount" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/inputAmount"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:id="#+id/radioGroup2">
<RadioButton
android:id="#+id/aud"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/aud"
android:onClick="onRadioButtonClicked1"/>
<RadioButton
android:id="#+id/cad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cad"
android:onClick="onRadioButtonClicked1"/>
<RadioButton
android:id="#+id/inr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/inr"
android:onClick="onRadioButtonClicked1"/>
</RadioGroup>
<TextView
android:text="#string/convertTo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:id="#+id/textView2"
android:layout_below="#+id/radioGroup2"
android:layout_alignRight="#+id/radioGroup2"
android:layout_alignEnd="#+id/radioGroup2" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/inputAmount"
android:layout_centerHorizontal="true"
android:layout_marginTop="170dp"
android:id="#+id/radioGroup3">
<RadioButton
android:id="#+id/usd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/usd"
android:onClick="onRadioButtonClicked2"/>
<RadioButton
android:id="#+id/gbp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gbp"
android:onClick="onRadioButtonClicked2"/>
</RadioGroup>
<Button
android:text="#string/convert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/radioGroup3"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:id="#+id/convertButton"
android:onClick="onClickConvert"/>
<TextView
android:text="#string/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/convertButton"
android:layout_alignLeft="#+id/radioGroup3"
android:layout_alignStart="#+id/radioGroup3"
android:layout_marginTop="28dp"
android:id="#+id/textView3" />
<Button
android:text="Clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_alignLeft="#+id/convertButton"
android:layout_alignStart="#+id/convertButton"
android:layout_marginTop="23dp"
android:id="#+id/clearButton" />
</RelativeLayout>
MainActivity.java :
package com.example.shara.currencyconvertor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private TextView txt = (TextView) findViewById(R.id.textView3);
private RadioGroup grp1 = (RadioGroup) findViewById(R.id.radioGroup2);
private RadioGroup grp2 = (RadioGroup) findViewById(R.id.radioGroup3);
private EditText inputAmt = (EditText) findViewById(R.id.inputAmount);
private final String inputText = inputAmt.getText().toString();
private double inputAmount = Integer.parseInt(inputText);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.convertButton).setOnClickListener(this);
findViewById(R.id.clearButton).setOnClickListener(this);
grp1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton btn = (RadioButton) findViewById(checkedId);
}
});
grp2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton btn2 = (RadioButton) findViewById(checkedId);
}
});
}
#Override
public void onClick(View v) {
int radioId1 = grp1.getCheckedRadioButtonId();
int radioId2 = grp2.getCheckedRadioButtonId();
double result = 0;
if(v.getId()==R.id.convertButton){
if(radioId1 == R.id.aud){
if(radioId2 == R.id.usd){
result = inputAmount*1.34;
Log.d("test", "Result is" +result);
txt.setText(""+result);
}
else if(radioId2 == R.id.gbp){
result = inputAmount*(0.83/1.34);
Log.d("test", "Result is" +result);
txt.setText(""+result);
}
else {
Log.d("test", "nothing here");
}
}
if(radioId1 == R.id.cad){
if(radioId2 == R.id.usd){
result = inputAmount*1.32;
Log.d("test", "Result is" +result);
txt.setText(""+result);
}
else if (radioId2 == R.id.gbp) {
result = inputAmount * (0.83 / 1.32);
Log.d("test", "Result is" + result);
txt.setText(""+result);
}
}
else {
Log.d("test", "nothing here");
}
if(radioId1 == R.id.inr){
if(radioId2 == R.id.usd){
result = inputAmount*68.14;
Log.d("test", "Result is" +result);
txt.setText(""+result);
}
else if(radioId2 == R.id.gbp){
result = inputAmount*(0.83/68.14);
Log.d("test", "Result is" +result);
txt.setText(""+result);
}
else {
Log.d("test", "nothing here");
}
}
}
else if(v.getId()== R.id.clearButton){
txt.setText("");
}
}
}
Unfortunately though everything seems right I am unable to get the app to run and the app crashes. Any help in resolving this is appreciated. I am a novice in android.
Updated with Logcat file:
01-21 17:42:56.229 6017-6017/? I/art: Late-enabling -Xcheck:jni
01-21 17:42:56.244 6017-6023/? E/art: Failed sending reply to debugger: Broken pipe
01-21 17:42:56.244 6017-6023/? I/art: Debugger is no longer active
01-21 17:42:56.278 6017-6017/? W/System: ClassLoader referenced unknown path: /data/app/com.example.shara.currencyconvertor-1/lib/x86
01-21 17:42:56.278 6017-6017/? I/InstantRun: Instant Run Runtime started. Android package is com.example.shara.currencyconvertor, real application class is null.
01-21 17:42:56.526 6017-6017/? W/System: ClassLoader referenced unknown path: /data/app/com.example.shara.currencyconvertor-1/lib/x86
01-21 17:42:56.556 6017-6017/? D/AndroidRuntime: Shutting down VM
01-21 17:42:56.556 6017-6017/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.shara.currencyconvertor, PID: 6017
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.shara.currencyconvertor/com.example.shara.currencyconvertor.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
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.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java:120)
at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java:151)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:31)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:55)
at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java:33)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:203)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:525)
at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:193)
at com.example.shara.currencyconvertor.MainActivity.<init>(MainActivity.java:15)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
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)
01-21 17:47:56.701 6017-6017/com.example.shara.currencyconvertor I/Process: Sending signal. PID: 6017 SIG: 9
LogCat after making changes:
01-21 18:33:57.523 11590-11590/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.shara.currencyconvertor, PID: 11590
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.shara.currencyconvertor/com.example.shara.currencyconvertor.MainActivity}: java.lang.NumberFormatException: Invalid double: ""
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
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.NumberFormatException: Invalid double: ""
at java.lang.StringToReal.invalidReal(StringToReal.java:63)
at java.lang.StringToReal.parseDouble(StringToReal.java:267)
at java.lang.Double.parseDouble(Double.java:301)
at com.example.shara.currencyconvertor.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
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) 
You're initializing the views before the onCreate has loaded. It makes sense you're getting a NullPointerException.
Try the changes here. Notice that all the views are being declared at the top but initialized in the OnCreate. The "inputText" can't be final, Unless you declare it inside the onCreate.
package com.example.shara.currencyconvertor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private TextView txt;
private RadioGroup grp1;
private RadioGroup grp2;
private EditText inputAmt;
private String inputText;
private double inputAmount;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.convertButton).setOnClickListener(this);
findViewById(R.id.clearButton).setOnClickListener(this);
txt = (TextView) findViewById(R.id.textView3);
grp1 = (RadioGroup) findViewById(R.id.radioGroup2);
grp2 = (RadioGroup) findViewById(R.id.radioGroup3);
inputAmt = (EditText) findViewById(R.id.inputAmount);
inputText = inputAmt.getText().toString();
inputAmount = Integer.parseInt(inputText);
grp1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton btn = (RadioButton) findViewById(checkedId);
}
});
grp2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton btn2 = (RadioButton) findViewById(checkedId);
}
});
}
#Override
public void onClick(View v) {
int radioId1 = grp1.getCheckedRadioButtonId();
int radioId2 = grp2.getCheckedRadioButtonId();
double result = 0;
if(v.getId()==R.id.convertButton){
if(radioId1 == R.id.aud){
if(radioId2 == R.id.usd){
result = inputAmount*1.34;
Log.d("test", "Result is" +result);
txt.setText(""+result);
}
else if(radioId2 == R.id.gbp){
result = inputAmount*(0.83/1.34);
Log.d("test", "Result is" +result);
txt.setText(""+result);
}
else {
Log.d("test", "nothing here");
}
}
if(radioId1 == R.id.cad){
if(radioId2 == R.id.usd){
result = inputAmount*1.32;
Log.d("test", "Result is" +result);
txt.setText(""+result);
}
else if (radioId2 == R.id.gbp) {
result = inputAmount * (0.83 / 1.32);
Log.d("test", "Result is" + result);
txt.setText(""+result);
}
}
else {
Log.d("test", "nothing here");
}
if(radioId1 == R.id.inr){
if(radioId2 == R.id.usd){
result = inputAmount*68.14;
Log.d("test", "Result is" +result);
txt.setText(""+result);
}
else if(radioId2 == R.id.gbp){
result = inputAmount*(0.83/68.14);
Log.d("test", "Result is" +result);
txt.setText(""+result);
}
else {
Log.d("test", "nothing here");
}
}
}
else if(v.getId()== R.id.clearButton){
txt.setText("");
}
}
}
UPDATE:
Sorry I just now noticed the XML.
You are tring to parse the content of the EditText when it's empty. You need to parse it after the use wrote something. If you dont wanna add a button, you can use:
inputAmt.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
inputText = inputAmt.getText().toString();
inputAmount = Integer.parseInt(inputText);
}
#Override
public void afterTextChanged(Editable s) {
}
});

Android RadioGroup/RadioButton NullPointerException

Hello I'm starting at Android Development and I need to do a user registration in two tables at the same time.
I have the User table and I have Patient and Caregiver tables, in the Register Activity I have two radio buttons to check the user type. If "Patient" is selected then I want to insert into user and patient.
But, my radiogroup (i think) is always returning null. I have checked other posts and tried different solutions but neither of them worked.
So my RegisterActivity code:
public class RegisterActivity extends AppCompatActivity {
DatabaseHelper helper = new DatabaseHelper(this);
private AlphaAnimation buttonClick = new AlphaAnimation(0.0F, 0.8F);
//RadioButton rb1, rb2, rb3;
RadioGroup radiogroup;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
radiogroup = (RadioGroup) findViewById(R.id.radiogroup);
//rb1 = (RadioButton) findViewById(R.id.radioButton);
//rb2 = (RadioButton) findViewById(R.id.radioButton2);
}
//get selected radio button id (also returns null)
/* public int getIDRadio() {
int idRadio = radiogroup.getCheckedRadioButtonId();
if (idRadio == R.id.radioButton) {
return 1; //patient
} else if (idRadio == R.id.radioButton2) {
return 2; //caregiver
} else {
return -1; //erro não esta nenhum selecionado
}
}*/
//another try
public boolean radioGroup(){
int checkedID = radiogroup.getCheckedRadioButtonId(); //LINE 51
if(checkedID == R.id.radioButton) {
return true; //for patient
} else {
return false; //for caregiver
}
//return radiogroup.getCheckedRadioButtonId() == R.id.radioButton;
}
public void onRegisterClick(View v) {
if (v.getId() == R.id.REGISTARBUTTON) {
EditText name = (EditText) findViewById(R.id.TFNAME);
EditText email = (EditText) findViewById(R.id.TFEMAIL);
EditText uname = (EditText) findViewById(R.id.TFUNAME);
EditText password1 = (EditText) findViewById(R.id.TFPASSWORD1);
EditText password2 = (EditText) findViewById(R.id.TFPASSWORD2);
String namestr = name.getText().toString();
String emailstr = email.getText().toString();
String unamestr = uname.getText().toString();
String pass1str = password1.getText().toString();
String pass2str = password2.getText().toString();
if (namestr.isEmpty() || emailstr.isEmpty() || unamestr.isEmpty() || pass1str.isEmpty()) { //se os campos estiverem null
Toast fields = Toast.makeText(RegisterActivity.this, "Por favor, preencha os campos!", Toast.LENGTH_SHORT);
fields.show();
} else if (!pass1str.equals(pass2str)) { //se as passwords não forem iguais
Toast pass = Toast.makeText(RegisterActivity.this, "Password incorrecta, tente de novo!", Toast.LENGTH_SHORT);
pass.show();
/*} else if (getIDRadio() == -1) { //se nenhum radiobutton estiver selecionado
Toast userType = Toast.makeText(RegisterActivity.this, "Por favor, selecione um tipo de utilizador!", Toast.LENGTH_SHORT);
userType.show();*/
} else {
if (radioGroup()) {
//if patient radiobutton selected inserts into user and patient tables
UsersRegister userPatient = new UsersRegister();
userPatient.setName(namestr);
userPatient.setEmail(emailstr);
userPatient.setUname(unamestr);
userPatient.setPassword(pass1str); //pass1 ou pass2 e igual
Patient patient = new Patient();
patient.setName(namestr);
patient.setEmail(emailstr);
patient.setPassword(pass1str);
helper.insertUser(userPatient); //LINE 103
} else { //inserts into user and caregiver tables (...)
Now my RegisterActivity Layout:
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
android:layout_marginBottom="90dp"
android:orientation="horizontal"
android:id="#+id/radiogroup">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Paciente"
android:id="#+id/radioButton"
android:checked="false"
android:layout_marginLeft="50dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cuidador"
android:id="#+id/radioButton2"
android:layout_marginLeft="50dp"/>
</RadioGroup>
Logcat
Process: com.example.dc.smoveen, PID: 25361
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3848)
at android.view.View.performClick(View.java:4463)
at android.view.View$PerformClick.run(View.java:18770)
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 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.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3843)
            at android.view.View.performClick(View.java:4463)
            at android.view.View$PerformClick.run(View.java:18770)
            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 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 com.example.dc.smoveen.RegisterActivity.radioGroup(RegisterActivity.java:51)
at com.example.dc.smoveen.DatabaseHelper.insertUser(DatabaseHelper.java:108)
at com.example.dc.smoveen.RegisterActivity.onRegisterClick(RegisterActivity.java:103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at android.view.View$1.onClick(View.java:3843)
            at android.view.View.performClick(View.java:4463)
            at android.view.View$PerformClick.run(View.java:18770)
            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 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)
So since it always returns null giving the NullPointerException error I can't do the signup.
Can anyone help me discover what have I done wrong?

RecyclerView app crash

I have a problem when I'm trying to use a RecyclerView. The app crashes directly on launch.
Here is the error in logcat:
`Process: com.test.alvar.temadagar, PID: 14522
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.alvar.temadagar/com.test.alvar.temadagar.Temadagar} : android.view.InflateException: Binary XML file line #182: Error inflating class RecyclerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #182: Error inflating class RecyclerView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at com.test.alvar.temadagar.Temadagar.onCreate(Temadagar.java:73)
at android.app.Activity.performCreate(Activity.java:5248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
 at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.RecyclerView" on path: DexPathList[[zip file "/data/app/com.test.alvar.temadagar-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.test.alvar.temadagar-2, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.view.LayoutInflater.createView(LayoutInflater.java:559)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at com.test.alvar.temadagar.Temadagar.onCreate(Temadagar.java:73)
at android.app.Activity.performCreate(Activity.java:5248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)`
</pre>
Temadagar.java (Main activity)
package com.test.alvar.temadagar;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import java.util.ArrayList;
import android.os.StrictMode;
import android.util.Log;
public class Temadagar extends AppCompatActivity {
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_temadagar);
StrictMode.enableDefaults(); //STRICT MODE ENABLED
mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new MyRecyclerViewAdapter(getDataSet());
mRecyclerView.setAdapter(mAdapter);
}
#Override
protected void onResume() {
super.onResume();
((MyRecyclerViewAdapter) mAdapter).setOnItemClickListener(new
MyRecyclerViewAdapter.MyClickListener() {
#Override
public void onItemClick(int position, View v) {
// Log.i(LOG_TAG, " Clicked on Item " + position);
}
});
}
private ArrayList<DataObject> getDataSet() {
ArrayList results = new ArrayList<DataObject>();
for (int index = 0; index < 20; index++) {
DataObject obj = new DataObject("Some Primary Text " + index,
"Secondary " + index);
results.add(index, obj);
}
return results;
}
}
DataObject.java
package com.test.alvar.temadagar;
public class DataObject {
private String mText1;
private String mText2;
DataObject (String text1, String text2){
mText1 = text1;
mText2 = text2;
}
public String getmText1() {
return mText1;
}
public void setmText1(String mText1) {
this.mText1 = mText1;
}
public String getmText2() {
return mText2;
}
public void setmText2(String mText2) {
this.mText2 = mText2;
}
}
MyRecyclerViewAdapter.java
package com.test.alvar.temadagar;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.ArrayList;
public class MyRecyclerViewAdapter extends RecyclerView
.Adapter<MyRecyclerViewAdapter
.DataObjectHolder> {
private static String LOG_TAG = "MyRecyclerViewAdapter";
private ArrayList<DataObject> mDataset;
private static MyClickListener myClickListener;
public static class DataObjectHolder extends RecyclerView.ViewHolder
implements View
.OnClickListener {
TextView label;
TextView dateTime;
public DataObjectHolder(View itemView) {
super(itemView);
label = (TextView) itemView.findViewById(R.id.textView);
dateTime = (TextView) itemView.findViewById(R.id.textView2);
Log.i(LOG_TAG, "Adding Listener");
itemView.setOnClickListener(this);
}
#Override
public void onClick(View v) {
myClickListener.onItemClick(getPosition(), v);
}
}
public void setOnItemClickListener(MyClickListener myClickListener) {
this.myClickListener = myClickListener;
}
public MyRecyclerViewAdapter(ArrayList<DataObject> myDataset) {
mDataset = myDataset;
}
#Override
public DataObjectHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_item, parent, false);
DataObjectHolder dataObjectHolder = new DataObjectHolder(view);
return dataObjectHolder;
}
#Override
public void onBindViewHolder(DataObjectHolder holder, int position) {
holder.label.setText(mDataset.get(position).getmText1());
holder.dateTime.setText(mDataset.get(position).getmText2());
}
public void addItem(DataObject dataObj, int index) {
mDataset.add(dataObj);
notifyItemInserted(index);
}
public void deleteItem(int index) {
mDataset.remove(index);
notifyItemRemoved(index);
}
#Override
public int getItemCount() {
return mDataset.size();
}
public interface MyClickListener {
public void onItemClick(int position, View v);
}
}
list_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:background="?android:attr/selectableItemBackground"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingTop="5dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
activity_temdagar.xml (main)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/coming_text"
android:id="#+id/my_recycler_view"/>
</RelativeLayout>
you have to use <android.support.v7.widget.RecyclerView in your activity_temdagar.xml, not <RecyclerView. The widget is only part of the support library

Application crashes when i sign in [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 7 years ago.
I am not maintaining a session right now for users but when I sign up it works ok and it moves to the next activity but when I sign in it crashes the application while if the data is not correct even then it should display a toast but its not happening.
This is the list of errors
04-15 11:56:51.180 12421-12421/com.example.ali.projectbuddy E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3607)
at android.view.View.performClick(View.java:4212)
at android.view.View$PerformClick.run(View.java:17476)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5371)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at android.view.View$1.onClick(View.java:3602)
            at android.view.View.performClick(View.java:4212)
            at android.view.View$PerformClick.run(View.java:17476)
            at android.os.Handler.handleCallback(Handler.java:800)
            at android.os.Handler.dispatchMessage(Handler.java:100)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5371)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.ali.projectbuddy.SignIn.Sign(SignIn.java:44)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at android.view.View$1.onClick(View.java:3602)
            at android.view.View.performClick(View.java:4212)
            at android.view.View$PerformClick.run(View.java:17476)
            at android.os.Handler.handleCallback(Handler.java:800)
            at android.os.Handler.dispatchMessage(Handler.java:100)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5371)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)
My sign in code SignIn.java
package com.example.ali.projectbuddy;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.database.Cursor;
import android.widget.Toast;
public class SignIn extends Activity {
LoginDataBaseAdapter loginDataBaseAdapter;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);
// create a instance of SQLite Database
}
public void Sign(View v)
{
Toast.makeText(this,"I m working",Toast.LENGTH_LONG).show();
// get the Refferences of views
EditText editTextUserName=(EditText)findViewById(R.id.Email);
EditText editTextPassword=(EditText)findViewById(R.id.Password);
// get The User name and Password
String userName=editTextUserName.getText().toString();
String password=editTextPassword.getText().toString();
Toast.makeText(this,"I m working",Toast.LENGTH_LONG).show();
// fetch the Password form database for respective user name
String storedPassword=loginDataBaseAdapter.getSinlgeEntry(userName);
// check if the Stored password matches with Password entered by user
if(password.equals(storedPassword))
{
Toast.makeText(this, "Congrats: Login Successfull", Toast.LENGTH_LONG).show();
Intent i = new Intent(this,Welcome_Page.class);
startActivity(i);
}
else
{
Toast.makeText(SignIn.this, "User Name or Password does not match", Toast.LENGTH_LONG).show();
Intent i = new Intent(this, SignIn.class);
startActivity(i);
}
}
/*
#Override
public void onDestroy() {
super.onDestroy();
// Close The Database
loginDataBaseAdapter.close();
}
*/
public void SignUpClick(View v)
{
Intent i = new Intent(this, SignUp.class);
startActivity(i);
}
}
My activity_sign_in
<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="#color/material_blue_grey_800"
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.ali.projectbuddy..Login" >
<GridLayout
android:layout_width="fill_parent"
android:layout_height="300px"
android:layout_alignParentStart="true"
android:id="#+id/gridLayout">
<ImageView
android:layout_width="96dp"
android:layout_height="143dp"
android:id="#+id/imageView"
android:layout_row="0"
android:layout_column="0"
android:background="#drawable/icon1"/>
<TextView android:text="#string/Project"
android:textSize="18pt"
android:textAlignment="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#73e0f4"
style="#style/Base.TextAppearance.AppCompat.Title"
android:background="#color/material_blue_grey_800"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_row="0"
android:layout_column="8" />
</GridLayout>
<EditText
android:id="#+id/Email"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp"
android:textSize="22dp"
android:textColor="#FFFFFF"
android:background="#07000000"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress"
>
<requestFocus />
</EditText>
<EditText
android:id="#+id/Password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#id/Email"
android:layout_marginTop="27dp"
android:ems="10"
android:textSize="22dp"
android:textColor="#FFFFFF"
android:background="#07000000"
android:hint="Password"
android:inputType="textWebPassword" />
<Button
android:id="#+id/Login"
android:layout_width="120dp"
android:layout_height="65dp"
android:background="#drawable/signin"
android:onClick="Sign"
android:layout_below="#+id/ForgetPassword"
android:layout_alignEnd="#+id/Password"
android:clickable="true" />
<TextView
android:id="#+id/ForgetPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:text="ForgetPassword"
android:textSize="22dp"
android:onClick="ForgetPasswordClick"
android:layout_below="#+id/SignUp"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/SignUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New User? Want to SignUp?"
android:textSize="22dp"
android:onClick="SignUpClick"
android:layout_marginTop="40dp"
android:textColor="#FFFFFF"
android:layout_below="#+id/Password"
android:layout_alignParentStart="true" />
</RelativeLayout>
My database adapter
package com.example.ali.projectbuddy;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
public class LoginDataBaseAdapter
{
static final String DATABASE_NAME = "login.db";
static final int DATABASE_VERSION = 1;
public static final int NAME_COLUMN = 1;
public static final String KEY_NAME = "user_name";
// TODO: Create public field for each column in your table.
// SQL Statement to create a new database.
static final String DATABASE_CREATE = "create table "+"User"+
"( " +"ID"+" integer primary key autoincrement,"+ "user_name string not null, email string unique not null, password string not null, mobileNo string not null, country string not null, city string not null, location string);";
// Variable to hold the database instance
public SQLiteDatabase db;
// Context of the application using the database.
private final Context context;
// Database open/upgrade helper
private DataBaseHelper dbHelper;
public LoginDataBaseAdapter(Context _context)
{
context = _context;
dbHelper = new DataBaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public LoginDataBaseAdapter open() throws SQLException
{
db = dbHelper.getWritableDatabase();
return this;
}
public void close()
{
db.close();
}
public SQLiteDatabase getDatabaseInstance()
{
return db;
}
public void insertEntry(String userName, String email, String password, String mobileNo, String country, String city )
{
ContentValues newValues = new ContentValues();
// Assign values for each row.
newValues.put("user_name", userName);
newValues.put("password",password);
newValues.put("email",email);
newValues.put("mobileNo",mobileNo);
newValues.put("country",country);
newValues.put("city",city);
// Insert the row into your table
db.insert("User", null, newValues);
///Toast.makeText(context, "Reminder Is Successfully Saved", Toast.LENGTH_LONG).show();
}
public int deleteEntry(String UserName)
{
//String id=String.valueOf(ID);
String where="user_name=?";
int numberOFEntriesDeleted= db.delete("User", where, new String[]{UserName}) ;
// Toast.makeText(context, "Number fo Entry Deleted Successfully : "+numberOFEntriesDeleted, Toast.LENGTH_LONG).show();
return numberOFEntriesDeleted;
}
public String getSinlgeEntry(String userName)
{
Cursor cursor=db.query("User", new String[]{KEY_NAME}, "user_name=?"+userName, null, null, null,null);
if(cursor.getCount()<1) // UserName Not Exist
{
cursor.close();
return "NOT EXIST";
}
cursor.moveToFirst();
String password= cursor.getString(cursor.getColumnIndex("password"));
cursor.close();
return password;
}
public void updateEntry(String userName,String password)
{
// Define the updated row content.
ContentValues updatedValues = new ContentValues();
// Assign values for each row.
updatedValues.put("user_name", userName);
updatedValues.put("password",password);
String where="username = ?";
db.update("User",updatedValues, where, new String[]{userName});
}
}
When I try to sign in my app crashes while when I sign up it work ok. what do I have to do? now please help
But where you initialized loginDataBaseAdapter? i can't see in your code.
loginDataBaseAdapter=new LoginDataBaseAdapter(context);

Categories