Volley timeout error attempting to POST to localhost - android

I've battling a volley timeout error when attempting to post a registration form to a localhost (WAMP) for testing purposes. I've been looking at the code for sometime and cannot seem to find the issue. Timeout errors from what I understand are generally due to connection issues. I don't seem to be getting any errors via logcat, and the URL to my localhost php file seem to be correct.
I hope it's something small. In my db_function.php file, I did (include/connectiondb.php) but not sure if its correct. I originally had (connectiondb.php) but still no go.
Any assistance is appreciated.
All my code is below.
database details
CREATE TABLE jobseekerusers (
jobSeekerId int,
jobSeekerFirstName VARCHAR,
jobSeekerLastName VARCHAR,
jobSeekerEmaiLAddress VARCHAR,
jobSeekerPasswordVARCHAR,
);
connectdb.php
<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'Discover');
$con = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE);
?>
db_function.php
<?php
if($_SERVER['REQUEST_METHOD']=='POST')
{
$jobFirstName = $_POST['jobFirstName'];
$jobLastName = $_POST['jobLastName'];
$jobEmailAddress = $_POST['jobEmailAddress'];
$jobPassword = $_POST['jobPassword'];
require_once('include/connectdb.php');
$sql = "INSERT INTO jobseekerusers(jobSeekerFirstName, jobSeekerLastName,
jobSeekerEmailAddress, jobSeekerPassword)
values ('$jobFirstName', '$jobLastName', '$jobEmailAddress',
'$jobPassword')";
if(mysql_query($con,$sql))
{
echo "Success";
}
else
{
echo "Fail";
}
}
else
{
echo "Something Failed";
}
?>
job_seeker_sign_up.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="180dp"
android:background="#drawable/shape_gradient_orange"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/search_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_full_name"
android:textColor="#FAFAFA"
android:textSize="20sp" />
</LinearLayout>
<android.support.v7.widget.CardView
android:layout_width="350dp"
android:layout_height="320dp"
android:paddingBottom="20dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="160dp"
android:background="#drawable/border"
android:id="#+id/cardView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="6"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:padding="10dp"
android:text="#string/signUp"
android:textSize="20dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/jobFirstName"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:singleLine="true"
android:layout_weight="1"
android:layout_marginTop="15dp"
android:background="#FAFAFA"
android:drawableLeft="#mipmap/rate"
android:drawablePadding="10dp"
android:hint="#string/employerFirstName"
android:maxLines="1"
android:textSize="15sp" />
<EditText
android:id="#+id/jobLastName"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:singleLine="true"
android:layout_weight="1"
android:background="#FAFAFA"
android:drawableLeft="#mipmap/employer_icon"
android:drawablePadding="10dp"
android:hint="#string/employerLastName"
android:maxLines="1"
android:textSize="15sp" />
<EditText
android:id="#+id/jobEmailAddress"
android:layout_width="match_parent"
android:layout_height="50dp"
android:inputType="textEmailAddress"
android:layout_gravity="center"
android:singleLine="true"
android:layout_marginTop="15dp"
android:background="#FAFAFA"
android:layout_weight="1"
android:drawableLeft="#mipmap/email_icon"
android:drawablePadding="10dp"
android:hint="#string/employerEmailAddress"
android:maxLines="1"
android:textSize="15sp" />
<EditText
android:id="#+id/jobPassword"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="50dp"
android:singleLine="true"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:background="#FAFAFA"
android:drawableLeft="#mipmap/password_icon"
android:drawablePadding="10dp"
android:hint="#string/employerPassword"
android:maxLines="1"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_below="#+id/cardView"
android:gravity="center"
android:orientation="vertical"
android:layout_height="wrap_content">
<Button
android:id="#+id/jobSubmit"
android:layout_width="200dp"
android:layout_marginTop="10dp"
android:textColor="#FAFAFA"
android:layout_height="wrap_content"
android:text="Submit"
android:background="#drawable/shape_gradient_orange"/>
<TextView
android:layout_width="wrap_content"
android:id="#+id/jobHaveAccount"
android:layout_height="wrap_content"
android:textColor="#999"
android:padding="10dp"
android:text="#string/haveAccount"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
jobSeekerPage.java
package com.example.dennis.discover;
import android.app.DownloadManager;
import android.content.Intent;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.w3c.dom.Text;
import java.util.HashMap;
import java.util.Map;
public class JobSeekerSignUp extends AppCompatActivity implements
View.OnClickListener {
private TextView jobHaveAccount;
private TextView jobFirstName;
private TextView jobLastName;
private TextView jobEmailAddress;
private TextView jobPassword;
private Button jobSubmit;
String URL = "http://192.168.0.9/Discover/db_functions.php";
public static final String FIRSTNAME = "jobSeekerFirstName";
public static final String LASTNAME = "jobSeekerLastName";
public static final String EMAILADDRESSID = "jobSeekerEmailAddress";
public static final String PASSWORD = "jobSeekerPassword";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_job_seeker_sign_up);
jobHaveAccount = (TextView) findViewById(R.id.jobHaveAccount);
jobFirstName = (TextView) findViewById(R.id.jobFirstName);
jobLastName = (TextView) findViewById(R.id.jobLastName);
jobEmailAddress = (TextView) findViewById(R.id.jobEmailAddress);
jobPassword = (TextView) findViewById(R.id.jobPassword);
jobSubmit = (Button) findViewById(R.id.jobSubmit);
jobSubmit.setOnClickListener(this);
jobHaveAccount.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent jobSeekerSignIn = new Intent(JobSeekerSignUp.this,
JobSeekerLogIn.class);
startActivity(jobSeekerSignIn);
}
});
}
#Override
public void onClick(View view) {
final String firstName = jobFirstName.getText().toString().trim();
final String lastName = jobLastName.getText().toString().trim();
final String emailAddress = jobEmailAddress.getText().toString().trim();
final String password = jobPassword.getText().toString().trim();
//Initiate request queue
RequestQueue requestQueue = Volley.newRequestQueue(this);
//get String Response using URL (variable defined above - currently WAMP)
StringRequest stringrequest = new StringRequest(Request.Method.POST,
URL, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
Toast.makeText(JobSeekerSignUp.this, response,
Toast.LENGTH_LONG).show();
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(JobSeekerSignUp.this, error.toString(),
Toast.LENGTH_LONG).show();
}
})
{
#Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put(FIRSTNAME, firstName);
params.put(LASTNAME, lastName);
params.put(EMAILADDRESSID, emailAddress);
params.put(PASSWORD, password);
return super.getParams();
}
};
// Adding the request to the request queue
requestQueue.add(stringrequest);
}
}

Try disabling your firewall if on windows, or disabling Avast shields. It worked for me.

Related

Android Initial Login Screen then use fragments to swipe between screens once login is successful

I am trying to create an Android app, then has an initial login screen that detects if a user is Admin or User. Once logged in, the user (depending on their role) will see different tabs to swipe between. I have a basic app that starts with a login activity and the login to decipher the users roles (using static values for now). First part is ok. Now when I try to use Fragments after the login screen, I'm getting stuck.
I have a LoginActivity that has an onClikcListener on a button after user enters credentials. Depending on whether the user is Amin or General Users, it will just to a new activity either activity_vote_admin or activity_vote_user. At this point I am stuck. Any ideas if what I am trying to do is valid. Or is there a better way to do this. At the moment I am getting this error.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.confidencevotefragmentrebuild/com.example.confidencevotefragmentrebuild.activity_vote_admin}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference.
LoginActivity (this is my main activity)
...
package com.example.confidencevotefragmentrebuild;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class LoginActivity extends AppCompatActivity {
private static EditText username;
private static EditText password;
public static TextView attempts;
private static Button submit_button;
int attempt_counter = 5;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
loginButton();
}
public void loginButton() {
username = (EditText) findViewById(R.id.editText);
password = (EditText) findViewById(R.id.editText2);
attempts = (TextView) findViewById(R.id.textView_Attempts);
//Reference button view
final Button submit_button = findViewById(R.id.submit_button);
// perform click event on button
submit_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (username.getText().toString().equals("admin") &&
password.getText().toString().equals("pass")) {
Toast.makeText(LoginActivity.this, "Welcome " + username.getText(),
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(LoginActivity.this, activity_vote_admin.class);
startActivity(intent);
} else if (username.getText().toString().equals("user") &&
password.getText().toString().equals("pass")) {
Toast.makeText(LoginActivity.this, "Welcome " + username.getText(),
Toast.LENGTH_SHORT).show();
Intent intentUser = new Intent(LoginActivity.this, activity_vote_user.class);
startActivity(intentUser);
} else {
Toast.makeText(LoginActivity.this, "User or Password incorrect",
Toast.LENGTH_SHORT).show();
attempt_counter--;
attempts.setText(Integer.toString(attempt_counter));
if (attempt_counter == 0) {
Toast.makeText(LoginActivity.this, "Too many failed attempts, please close app and try again",
Toast.LENGTH_SHORT).show();
submit_button.setEnabled(false);
}
}
}
}
);
}
}
...
Activity_vote_admin
...
package com.example.confidencevotefragmentrebuild;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.Spinner;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
public class activity_vote_admin extends AppCompatActivity {
/**
* Field for selecting the number of confidence votes
*/
RatingBar mResults;
private RatingBar rBar;
Button mBtn;
/**
* Spinner field to enter the project name
*/
private Spinner mProjectSpinner;
/**
* Projects. The possible values are:
* stored locally - Needs to get values from a database. TODO
*/
int mProject = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vote_main_admin);
// Find the view pager that will allow the user to swipe between fragments
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
// Create an adapter that knows which fragment should be shown on each page
AdminFragmentPagerAdapter adapter = new AdminFragmentPagerAdapter(getSupportFragmentManager());
// Set the adapter onto the view pager
viewPager.setAdapter(adapter);
// initiate a rating bar
rBar = findViewById(R.id.rating_bar);
//float vote = rBar.getRating();
// Find all relevant views for user input
mResults = findViewById(R.id.rating_bar);
mProjectSpinner = findViewById(R.id.spinner_project);
// Run getRating method to get rating number from a rating bar
//getRating();
// Initiate button
mBtn = findViewById(R.id.voteButton);
// perform click event on button
mBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// get values and then displayed in a toast
//String totalStars = "Total Stars:: " + RatingBar.getNumStars();
float vote = rBar.getRating();
String rating = "Rating : " + vote;
Toast.makeText(getApplicationContext(), rating + "\n", Toast.LENGTH_LONG).show();
}
});
projectSpinner();
}
// Setup the dropdown spinner that allows the user to select the role.
private void projectSpinner() {
// Create adapter for spinner. The list options are from the String array it will use
// the spinner will use the default layout
ArrayAdapter projectSpinnerAdapter = ArrayAdapter.createFromResource(this,
R.array.projects, android.R.layout.simple_spinner_item);
// Specify dropdown layout style - simple list view with 1 item per line
projectSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
// Apply the adapter to the project spinner
mProjectSpinner.setAdapter(projectSpinnerAdapter);
// Set the integer mSelected to the constant values
mProjectSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String selection = (String) parent.getItemAtPosition(position);
if(mProjectSpinner.getSelectedItem() == "This is Hint Text");
if (!TextUtils.isEmpty(selection)) {
if (selection.equals(getString(R.string.nextGEMS1_5))) {
mProject = 0 ;
return;
} else if (selection.equals(getString(R.string.nextGEMS1_6))) {
mProject = 1;
return;
} else if (selection.equals(getString(R.string.nextGEMS1_7))) {
mProject = 2;
return;
} else if (selection.equals(getString(R.string.nextGEMS1_8))) {
mProject = 3;
return;
} else if (selection.equals(getString(R.string.nextGEMS1_9))) {
mProject = 4;
return;
}
else mProject = 0;
}
}
// Because AdapterView is an abstract class, onNothingSelected must be defined
#Override
public void onNothingSelected(AdapterView<?> parent) {
mProject = 0; // User
}
});
}
}
...
activity_vote_main_admin.xml
...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.viewpager.widget.ViewPager
android:name="com.example.confidencevotefragmentrebuild.testFragment1"
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
...
activity_login.xml
...
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".LoginActivity"
tools:showIn="#layout/activity_login">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#5fb0c9"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
<TextView
android:id="#+id/login_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"
android:gravity="center_horizontal"
android:text="LOGIN"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="500dp"
android:background="#ffffff"
android:elevation="4dp"
android:orientation="vertical"
android:padding="20dp"
android:layout_below="#+id/login_title"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="80dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="450dp"
android:orientation="vertical"
android:paddingTop="30dp">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="70dp">
<EditText
android:id="#+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:drawableLeft="#drawable/usericon"
android:hint="User Name"
android:inputType="textEmailAddress"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/editText2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:drawableLeft="#drawable/lock"
android:hint="Password"
android:inputType="textPassword"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:paddingTop="5dp"
android:text="Forgot Password?" />
<Button
android:id="#+id/submit_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="22dp"
android:background="#drawable/action_buttom"
android:text="Sign in"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="20dp"
android:orientation="horizontal"
android:paddingTop="1dp">
<TextView
android:id="#+id/attempts_text"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_gravity="center_horizontal"
android:paddingTop="1dp"
android:text="Number of attempts remaining: " />
<TextView
android:id="#+id/textView_Attempts"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_gravity="center_horizontal"
android:paddingTop="1dp"
android:text="5" />
</LinearLayout>
<TextView
android:id="#+id/lnkRegister"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:gravity="center"
android:paddingTop="30dp"
android:text="Register here"
android:textColor="#5fb0c9"
android:textSize="16sp" />
</LinearLayout>
</RelativeLayout>
<ImageButton
android:id="#+id/conferencevote_logo"
android:layout_width="210dp"
android:layout_height="180dp"
android:layout_below="#+id/login_title"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:elevation="4dp"
android:background="#drawable/rounded_button"
android:src="#drawable/confvotenew"
/>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
...
AdminFragemntyPagerAdapter
...
package com.example.confidencevotefragmentrebuild;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
public class AdminFragmentPagerAdapter extends FragmentPagerAdapter {
public AdminFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
if (position == 0) {
return new testFragment1();
} else if (position == 1) {
return new testFragment2();
} else {
return new testFragment2();
}
}
#Override
public int getCount() {
return 3;
}
}
...
aactivity_vote_user.xml
...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#5fb0c9"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
<TextView
android:id="#+id/vote_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginTop="16dp"
android:gravity="center_horizontal"
android:text="USER VOTE"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="500dp"
android:background="#ffffff"
android:elevation="4dp"
android:orientation="vertical"
android:padding="20dp"
android:layout_below="#+id/vote_title"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="80dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="450dp"
android:orientation="vertical"
android:paddingTop="70dp">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<Spinner
android:id="#+id/spinner_project"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:hint="#string/spinner_hint"
android:maxLines="1"
android:singleLine="true"
android:backgroundTint="#color/attCobalt"
android:popupBackground="#color/myBlue"
android:dropDownSelector="#color/attBlue"
/>
</com.google.android.material.textfield.TextInputLayout
>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<RatingBar
android:id="#+id/rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stepSize="1.0"
android:layout_marginTop="40dp"
android:theme="#style/rating_bar"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="5dp"
android:text="Vote and Submit" />
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="#+id/voteButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="22dp"
android:background="#drawable/action_buttom"
android:text="Submit"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
/>
</LinearLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<ImageButton
android:id="#+id/conferencevote_logo"
android:layout_width="210dp"
android:layout_height="180dp"
android:layout_below="#+id/login_title"
android:layout_centerHorizontal="true"
android:layout_marginTop="55dp"
android:elevation="4dp"
android:background="#drawable/rounded_button"
android:src="#drawable/confvotenew"
/>
</RelativeLayout>
...
My fragments are as follows.
...
package com.example.confidencevotefragmentrebuild;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
public class testFragment1 extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_vote_user, container, false);
}
}
...
There are two reason for this issue :
You didn't declare any button on "activity_vote_main_admin.xml", thats why your view not binding with activity and giving null pointer exception.
May be you declare the button on fragment xml and trying to bind it with activity.

I'm having trouble with phone number authentication. Verify_otp generates a unique code for any verified number

I'm having trouble with phone number authentication. Verify_otp generates a unique code for any verified number. But the biggest problem is that it only generates the code if the numbers start with 6599 ..... a number 6598 .... it no longer generates the code.
I can not find an outlet for him to accept any phone number.
this is a part of the RegistrationModel.java file
public static class OTP_Details{
/**
* status : 2
* message : Otp Sent to phone for Verification
* otp : 2017
* auto_otp : 1
*/
private int status;
private String message;
private String otp;
private int auto_otp;
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getOtp() {
return otp;
}
public void setOtp(String otp) {
this.otp = otp;
}
public int getAuto_otp() {
return auto_otp;
}
public void setAuto_otp(int auto_otp) {
this.auto_otp = auto_otp;
}
}
}
This is Vetify_otp
package com.motofacil.passageiro;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.motofacil.passageiro.accounts.RegistrationModel;
import com.motofacil.passageiro.accounts.ResultCheckMessage;
import com.motofacil.passageiro.accounts.ResultChecker;
import com.motofacil.passageiro.manager.ApiManager;
import com.motofacil.passageiro.manager.SessionManager;
import com.motofacil.passageiro.samwork.Config;
import com.motofacil.passageiro.urls.Apis;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hbb20.CountryCodePicker;
import java.util.HashMap;
public class Verify_OTP extends AppCompatActivity implements ApiManager.APIFETCHER {
ApiManager apiManager ;
GsonBuilder gsonBuilder;
RegistrationModel.OTP_Details otp_details;
private TextView otpError_txt;
private EditText otp_input, edt_enter_phone;
private LinearLayout submit_otp_layout;
SessionManager sessionManager ;
Gson gson;
String code, input_phone_number, otp;
CountryCodePicker codePicker;
private static final int KEY_REGISTER = 110;
Button generate_otp;
LinearLayout submit_otp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gsonBuilder = new GsonBuilder();
gson = gsonBuilder.create();
apiManager = new ApiManager(this , this , this );
sessionManager = new SessionManager(Verify_OTP.this);
otp_details = new RegistrationModel.OTP_Details();
setContentView(R.layout.activity_verify__otp);
gsonBuilder = new GsonBuilder();
gson = gsonBuilder.create();
submit_otp = (LinearLayout) findViewById(R.id.otp_submit);
generate_otp = (Button) findViewById(R.id.generate_otp);
edt_enter_phone = (EditText)findViewById(R.id.edt_enter_phone);
otp_input = (EditText)findViewById(R.id.otp_edt);
otpError_txt = (TextView)findViewById(R.id.otp_verifier_txt);
submit_otp_layout = (LinearLayout)findViewById(R.id.otp_submit);
codePicker = (CountryCodePicker)findViewById(R.id.otp_ccp);
submit_otp.setEnabled(false);
generate_otp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
input_phone_number = edt_enter_phone.getText().toString().trim();
Log.e("input_phone_number====", input_phone_number);
code = codePicker.getSelectedCountryCodeWithPlus();
Log.e("COUNTRY_CODE_PICKER===", code);
if (input_phone_number.equals("")){
Toast.makeText(Verify_OTP.this, R.string.required_field_missing, Toast.LENGTH_SHORT).show();
}else {
getOTP(code+input_phone_number);
}
}
});
submit_otp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (otp_input.getText().toString().equals("")) {
Toast.makeText(Verify_OTP.this, R.string.required_field_missing, Toast.LENGTH_SHORT).show();
} else if (!otp_input.getText().toString().equals(otp)) {
// Toast.makeText(Verify_OTP.this, R.string.invalid_otp, Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.putExtra("phone_number", code + input_phone_number);
setResult(Activity.RESULT_OK, intent);
finish();
} else {
Intent intent = new Intent();
intent.putExtra("phone_number", code + input_phone_number);
setResult(Activity.RESULT_OK, intent);
finish();
}
}
});
}
private void getOTP(String phone) {
HashMap<String , String > bodyparameters = new HashMap<String, String>();
bodyparameters.put("phone" , phone);
bodyparameters.put("flag" ,"1");
apiManager.execution_method_post(Config.ApiKeys.KEY_VERIFY_OTP ,""+ Apis.SEND_OTP, bodyparameters, true,ApiManager.ACTION_SHOW_TOP_BAR);
}
#Override
public void onFetchComplete(Object script, String APINAME) {
if(APINAME.equals(""+Config.ApiKeys.KEY_VERIFY_OTP)){
submit_otp.setEnabled(true);
RegistrationModel.OTP_Details otp_response = gson.fromJson("" + script, RegistrationModel.OTP_Details.class);
// finilalizeActivity();
Log.e("**OTP_SCRIPT-----", String.valueOf(otp_response.getMessage() + otp_response.getOtp() + otp_response.getStatus()));
otp = otp_response.getOtp();
Log.d("otp==normal sign up==", otp);
otp_input.setText(""+otp);
otp_input.requestFocus();
if(otp_response.getAuto_otp() == 1){
otp_input.setText(""+otp);
}
}else {
try{ResultChecker rcheck = gson.fromJson("" + script, ResultChecker.class);
Log.e("**OTP_SCRIPT-----", String.valueOf(script));
if(rcheck.getResult() == 1){
Log.e("**RCHHECKK---", String.valueOf(rcheck.getResult()));
RegistrationModel.OTP_Details otp_response = gson.fromJson("" + script, RegistrationModel.OTP_Details.class);
}else {
ResultCheckMessage rr = gson.fromJson("" + script, ResultCheckMessage.class);
Toast.makeText(this, ""+rr.getMessage(), Toast.LENGTH_SHORT).show();
}
}catch (Exception e){}
}
}
#Override
public void onFetchResultZero(String s) {
}
}
This is Activity_forgotpass_verify_otp.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.motofacil.passageiro.ForgotPass_Verify_OTP">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/pure_white"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/otp_back"
android:layout_width="50dp"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="invisible">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="#drawable/ic_left_sort"
android:tint="#color/icons_8_muted_grey"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<com.motofacil.passageiro.accounts.TypefaceDosisRegular
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/verifyOTP"
android:textColor="#color/icons_8_muted_grey"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="50dp"
android:layout_height="match_parent" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/icons_8_muted_grey" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/login_banner"></ImageView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bf000000"></RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/icons_8_muted_grey" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|top"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:id="#+id/phone_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="15dp"
android:background="#drawable/shapes_white_transparent"
android:layout_marginRight="15dp"
android:gravity="center"
android:orientation="horizontal">
<com.hbb20.CountryCodePicker
android:id="#+id/otp_ccp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:hideNameCode="true"
app:keyboardAutoPopOnSearch="false"
app:showFlag="false"
android:layout_marginLeft="5dp"
app:defaultCode="55"
app:textSize="15dp"/>
<EditText
android:id="#+id/edt_enter_phone"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:background="#android:color/transparent"
android:ems="10"
android:drawableTint="#color/icons_8_muted_grey"
android:gravity="center|left"
android:hint="Enter Phone Number"
android:inputType="phone"
android:maxLength="10"
android:minLines="1"
android:padding="5dp"
android:textColor="#color/pure_black"
android:textSize="17dp" />
</LinearLayout>
<!--
<View
android:layout_width="match_parent"
android:layout_height="0.85dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="6dp"
android:background="#color/icons_8_muted_yellow" />-->
<Button
android:id="#+id/generate_otp"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/generateOTP" />
<TextView
android:id="#+id/otp_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:text="#string/otp_text"
android:textColor="#color/pure_white"
android:textSize="17dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="70dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="30dp"
android:background="#drawable/shapes_white_transparent"
android:orientation="horizontal">
<EditText
android:id="#+id/otp_edt"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent"
android:drawableTint="#color/icons_8_muted_grey"
android:gravity="center|left"
android:hint="#string/enter_otp"
android:inputType="number"
android:paddingLeft="10dp"
android:textColor="#color/pure_black"
android:textSize="17dp" />
<TextView
android:id="#+id/otp_verifier_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:gravity="center|right"
android:padding="10dp"
android:text="Email not valid"
android:textColor="#color/icons_8_muted_red"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/otp_submit"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/colorPrimary"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/submitOTP"
android:textColor="#color/pure_white"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
Ready! I've submitted below the files I've listed. After typing the phone and clicking send otp, the code that comes back is always the code 2017, that is the first code I sent, but it only sends this code 2017 if the numbers start like this: 6599 .... if the number is so for example: 6598 .... it does not generate the code 2017 and can not continue the registration.

Toolbar doesn't set elevation on create or in XML

I'm currently creating an Android app for school but still want to give my best. I'm pretty new to Android development and coding in general.
The app is supposed to be a stock market game.
(Btw, I'm German, so there might be some German variables)
The app should have a similar style to Google's recent one with the Pixel 2 and Android Pie. Thus, the toolbar should have no drop shadow when created but it should appear when scrolling, like in the Pixel 2's settings app (e.g. the battery tab).
The drop shadow appears when scrolling and disappears when arriving at the top, but the toolbar starts with a drop shadow although I have set the android:elevation to 0 in the XML and also toolbar.setElevation(0) in the onCreate method.
Why does this happen? This method works in the OnScrollChangedListener!
The Java code:
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.widget.NestedScrollView;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
ArrayList<JSONObject> jObjList = new ArrayList<>();
private FloatingActionButton fab;
private TextView moneyTxt;
private TextView sharesTxt;
private TextView sumTxt;
private Toolbar toolbar;
private AppBarLayout toolbarLayout;
private RecyclerView recyclerShares;
private SharesAdapter sAdapter;
private NestedScrollView scrollMain;
private SwipeRefreshLayout refreshMain;
private float money;
private float sharesWorth;
private boolean isRefreshing;
private JSONObject jObj = new JSONObject();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = findViewById(R.id.abMain);
toolbar.setTitleTextColor(getResources().getColor(R.color.colorPrimary));
setSupportActionBar(toolbar);
fab = findViewById(R.id.fabMain);
moneyTxt = findViewById(R.id.moneyTxt);
sharesTxt = findViewById(R.id.sharesTxt);
sumTxt = findViewById(R.id.sumTxt);
toolbarLayout = findViewById(R.id.abMainLayout);
recyclerShares = findViewById(R.id.recyclerShares);
scrollMain = findViewById(R.id.scrollMain);
scrollMain.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
refreshMain = findViewById(R.id.refreshMain);
isRefreshing = false;
try {
jObj.put("name", "BMW");
jObj.put("worth", 143.23);
jObj.put("count", 5);
jObj.put("change", -1.5);
jObjList.add(jObj);
} catch (JSONException e) {
}
sAdapter = new SharesAdapter(jObjList);
RecyclerView.LayoutManager cLayoutManager = new CustomGridLayoutManager(getApplicationContext()) {
#Override
public boolean canScrollVertically() {
return false;
}
};
recyclerShares.setLayoutManager(cLayoutManager);
recyclerShares.setItemAnimator(new DefaultItemAnimator());
recyclerShares.setAdapter(sAdapter);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SharesActivity.class);
startActivity(intent);
}
});
toolbarLayout.setElevation(0); //TODO: Stackoverflow nach Lösung fragen
scrollMain.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
#Override
public void onScrollChanged() {
int scroll = scrollMain.getScrollY();
if (scroll == 0) {
toolbarLayout.setElevation(0);
} else {
toolbarLayout.setElevation(8);
}
}
});
refreshMain.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
refresh(MainActivity.this);
}
});
refresh(MainActivity.this);
}
private void refresh(Context context) {
isRefreshing = true;
SharedPreferences sharedPref = context.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
SharedPreferences.Editor sharedPrefEdit = sharedPref.edit();
if (sharedPref.getBoolean("isFirstRun", true)) {
sharedPrefEdit.putBoolean("isFirstRun", false);
sharedPrefEdit.putFloat(getString(R.string.moneyShared), 5000);
sharedPrefEdit.apply();
}
float shareWorth = 0;
for (int i = 0; i < jObjList.size(); i++) {
try {
shareWorth += jObjList.get(i).getDouble("worth") * jObjList.get(i).getDouble("count");
} catch (JSONException e) {
}
}
sharedPrefEdit.putFloat(getString(R.string.sharesWorthShared), shareWorth);
sharedPrefEdit.commit();
money = sharedPref.getFloat(getString(R.string.moneyShared), 0);
sharesWorth = sharedPref.getFloat(getString(R.string.sharesWorthShared), 0);
moneyTxt.setText(String.format("%.2f€", money));
sharesTxt.setText(String.format("%.2f€", sharesWorth));
sumTxt.setText(String.format("%.2f€", money + sharesWorth));
if(isRefreshing) {
isRefreshing = false;
refreshMain.setRefreshing(isRefreshing);
}
Toast.makeText(MainActivity.this, "Alles neugeladen", Toast.LENGTH_SHORT).show();
}
public void onShareClick(View v) {
Intent i = new Intent(MainActivity.this, CompanyActivity.class);
try {
i.putExtra("name", jObj.getString("name"));
i.putExtra("worth", jObj.getDouble("worth"));
} catch (JSONException e) {
i.putExtra("name", "Fehler");
i.putExtra("worth", 0);
}
startActivity(i);
}
}
The XML code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorBackground"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/abMainLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="#+id/abMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorBackgroundAccent"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:backgroundTint="#color/colorBackground"
android:src="#drawable/ic_note_add"
app:borderWidth="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/refreshMain"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/abMainLayout">
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
app:layout_constraintTop_toBottomOf="#+id/abMainLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<GridLayout
android:id="#+id/gridMoney"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorBackgroundAccent"
android:orientation="horizontal"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingTop="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/abMain">
<TextView
android:id="#+id/sumTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_columnSpan="5"
android:layout_columnWeight="1"
android:layout_gravity="center"
android:layout_marginBottom="16dp"
android:layout_marginTop="8dp"
android:layout_row="1"
android:textColor="#color/colorDarkText"
android:textSize="50sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/moneyImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_columnWeight="1"
android:layout_gravity="right|center_vertical"
android:layout_row="2"
android:background="#android:color/transparent"
android:scaleX="0.5"
android:scaleY="0.5"
app:srcCompat="#drawable/ic_money" />
<TextView
android:id="#+id/moneyTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_columnWeight="1"
android:layout_gravity="left|center_vertical"
android:layout_row="2"
android:background="#android:color/transparent"
android:textColor="#color/colorLightText"
android:textSize="15sp" />
<ImageView
android:id="#+id/sharesImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:layout_columnWeight="1"
android:layout_gravity="right|center_vertical"
android:layout_row="2"
android:background="#android:color/transparent"
android:scaleX="0.5"
android:scaleY="0.5"
app:srcCompat="#drawable/outline_assessment_black_36" />
<TextView
android:id="#+id/sharesTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="4"
android:layout_columnWeight="1"
android:layout_gravity="left|center_vertical"
android:layout_row="2"
android:background="#android:color/transparent"
android:textColor="#color/colorLightText"
android:textSize="15sp" />
</GridLayout>
<View
android:id="#+id/dividerMoney"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorDivider"
app:layout_constraintTop_toBottomOf="#id/gridMoney" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/recycler_horizontal_margin"
android:layout_marginStart="#dimen/recycler_horizontal_margin"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:text="Aktien"
android:textColor="#color/colorPrimary"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="#+id/dividerMoney"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/gridMoney" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerShares"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/recycler_title_bottom_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.constraint.ConstraintLayout>
So #NileshRathod answered it:
It's app:elevation, not android:elevation.
But I still don't get why the method in onCreate() doesn't work.
Of course, setElevation(0); won't work.
But I still don't get why the method in onCreate() doesn't work.
AppbarLayout uses StateListAnimator from v24.0.0 and that is why setElevation will has no effect on it: https://stackoverflow.com/a/37992366/4409113
So:
StateListAnimator stateListAnimator = new StateListAnimator();
stateListAnimator.addState(new int[0], ObjectAnimator.ofFloat(view, "elevation", 0));
appBarLayout.setStateListAnimator(stateListAnimator);
Or:
toolbarLayout = findViewById(R.id.abMainLayout);
toolbarLayout.StateListAnimator = null;
In your case.

Why pass textInput content to string into ArrayList

I want pass values from a form making with TextInputLayout but Android Studio detects my content as INT.
I put the complete class of my activity as well as the view in .xml to determine the problem
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.design.widget.TextInputEditText;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import com.prosegma.rso.R;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class AccionActivity extends AppCompatActivity {
ImageView imageView;
private Context activity;
private String[]header={"Campo","Respuesta"};
private String shortText="RSO PROSEGMA";
private String longText="Eliminamos Riesgos Sumamos Valor";
private AccionPdf accionPdf;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_accion);
Button btnCamera1 = (Button)findViewById(R.id.BtnCamera1);
imageView = (ImageView)findViewById(R.id.reporte1);
btnCamera1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,0);
}
});
Date date = new Date();
String timeStamp = new SimpleDateFormat("dd/MM/yyyy").format(date);
accionPdf=new AccionPdf(getApplicationContext());
accionPdf.openDocument();
accionPdf.addMetaData("Reporte","Acción Insegura","www.prosegma.com");
accionPdf.addTitle("Reporte Acción Insegura","RSO Prosegma"," " +timeStamp);
accionPdf.addParagraph(shortText);
accionPdf.addParagraph(longText);
accionPdf.createTable(header,getClients());
accionPdf.closeDocument();
}
TextInputEditText Nreport = (TextInputEditText) findViewById(R.id.nReporta);
private ArrayList<String[]>getClients(){
ArrayList<String[]>rows=new ArrayList<>();
rows.add(new String[]{"Nombre de quien reporta", Nreport });
rows.add(new String[]{"Nombre del trabajador","No"});
rows.add(new String[]{"Empresa contratista","ju"});
rows.add(new String[]{"Medidas Necesarias","hu"});
return rows;
}
public void pdfAccion(View view)
{
accionPdf.verReporteAccion();
}
public void enviarA(View view) {
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, "receiver_email_address");
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "email body");
Uri uri = Uri.fromFile(new File(android.os.Environment.getExternalStorageDirectory(), "pdfFileName"));
email.putExtra(Intent.EXTRA_STREAM, uri);
email.setType("application/pdf");
email.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getActivity().startActivity(email);
}
public Context getActivity() {
return activity;
}
}
I update the publication with the activity, I have tried to change the InputTextLayout by EditText but the situation is the same, it throws me an incompatibility error.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include layout="#layout/actionbar_toolbar"/>
<ScrollView
android:id="#+id/reportes0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
>
<LinearLayout
android:id="#+id/reportes1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/activity_vertical_margin"
android:orientation="vertical"
android:weightSum="10"
>
<View
android:layout_width="match_parent"
android:layout_height="7dp"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"
/>
<View
android:layout_width="match_parent"
android:layout_height="7dp"
/>
<ImageView
android:id="#+id/reporte1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="#+id/BtnCamera1"
android:layout_weight="1"
android:layout_height="64sp"
android:layout_width="64sp"
android:background="#drawable/camera"
android:gravity="center"
/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/EditTextBlack"
android:layout_marginTop="4dp"
>
<android.support.design.widget.TextInputEditText
android:id="#+id/nReporta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="NOMBRE DE QUIEN REPORTA"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/EditTextBlack"
android:layout_marginTop="4dp"
>
<android.support.design.widget.TextInputEditText
android:id="#+id/nTrabajador"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="NOMBRE DEL TRABAJADOR"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/EditTextBlack"
android:layout_marginTop="4dp"
>
<android.support.design.widget.TextInputEditText
android:id="#+id/eContratista"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EMPRESA CONTRATISTA"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/EditTextBlack"
android:layout_marginTop="4dp"
>
<android.support.design.widget.TextInputEditText
android:id="#+id/aMedidas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:hint="ACCIÓN, MEDIDAS CORRECTIVAS INMEDIATAS"
android:inputType="textShortMessage"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/EditTextBlack"
android:layout_marginTop="4dp"
>
</android.support.design.widget.TextInputLayout>
<CheckBox
android:id="#+id/checkAccidente"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ACCIDENTE" />
<CheckBox
android:id="#+id/checkImpacto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="IMPACTO AMBIENTAL" />
<CheckBox
android:id="#+id/checkEnfermedad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ENFERMEDAR PROFESIONAL" />
<CheckBox
android:id="#+id/checkReincidente"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="REINCIDENTE" />
<CheckBox
android:id="#+id/checkSancion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="¿APLICA SANCIÓN?"
/>
<Button
android:id="#+id/guardarAccion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="GUARDAR REPORTE"
android:theme="#style/RaisedButtonDark"
android:onClick="pdfAccion"
/>
</LinearLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
TextInputEditText Nreport = (TextInputEditText) findViewById(R.id.nReporta);
this line is outside OnCreate(Bundle savedInstanceState) method. Thats why it throws null. It should be like this
public class MainActivity extends AppCompatActivity {
TextInputEditText Nreport;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Button btnCamera1 = (Button)findViewById(R.id.BtnCamera1);
// imageView = (ImageView)findViewById(R.id.reporte1);
Date date = new Date();
String timeStamp = new SimpleDateFormat("dd/MM/yyyy").format(date);
Nreport = (TextInputEditText) findViewById(R.id.nReporta);
getClients();
}
private ArrayList<String[]> getClients(){
ArrayList<String[]>rows=new ArrayList<>();
rows.add(new String[]{"Nombre de quien reporta", Nreport.getText().toString() }); // get text like this
rows.add(new String[]{"Nombre del trabajador","No"});
rows.add(new String[]{"Empresa contratista","ju"});
rows.add(new String[]{"Medidas Necesarias","hu"});
return rows;
}

What is (D/NSD: curPkgName is not in list)?

I am working on new project when I enter to RegisterActivity the logCat printing
11-07 20:12:09.305 26674-26674/com.rosheta D/NSD: curPkgName is not in list
too much and not stop printing it.
what is this? is this is an error? could this lot of logs printing reduce the performance of app?
here is my RegisterActivity
package com.rosheta.activities;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.AppCompatImageButton;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.rosheta.R;
import com.rosheta.api.Api;
import com.rosheta.api.ApiHelper;
import com.rosheta.api.response.UsernameResponse;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Created by Tefa on 07/11/2016.
*/
public class Reg extends Activity implements View.OnClickListener {
EditText fName, lName, username, email, password, confirmPassword, phone;
Button signUp;
TextView login;
AppCompatImageButton checkUsername;
Api api;
private static final String TAG = Reg.class.getSimpleName();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
initializeViewItems();
}
private void initializeViewItems() {
fName = (EditText) findViewById(R.id.act_register_et_firstName);
lName = (EditText) findViewById(R.id.act_register_et_lastName);
username = (EditText) findViewById(R.id.act_register_et_username);
email = (EditText) findViewById(R.id.act_register_et_email);
password = (EditText) findViewById(R.id.act_register_et_password);
confirmPassword = (EditText) findViewById(R.id.act_register_et_confirm_password);
phone = (EditText) findViewById(R.id.act_register_et_phone);
signUp = (Button) findViewById(R.id.act_register_b_signup);
signUp.setOnClickListener(this);
login = (TextView) findViewById(R.id.act_register_tv_login);
login.setOnClickListener(this);
checkUsername = (AppCompatImageButton) findViewById(R.id.act_register_ib_check_username);
checkUsername.setOnClickListener(this);
}
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.act_register_b_signup:
attemptLogin();
break;
case R.id.act_register_ib_check_username:
String inputUsername = username.getText().toString();
if (TextUtils.isEmpty(inputUsername)) {
username.setError("Username can not be blank");
return;
} else {
checkUsernameValidity(inputUsername);
}
break;
}
}
private void checkUsernameValidity(String inputUsername) {
Log.d(TAG,"checkUsernameValidity");
try {
ApiHelper.base_url = getString(R.string.base_url);
api = ApiHelper.getClient().create(Api.class);
api.checkUsername(inputUsername).enqueue(new Callback<UsernameResponse>() {
#Override
public void onResponse(Call<UsernameResponse> call, Response<UsernameResponse> response) {
if (response.code() == 200) {
Log.d(TAG, "response = 200");
UsernameResponse uResponse = response.body();
if (uResponse.getCode() == 20) {
checkUsername.setImageResource(R.drawable.ic_accepted_username);
} else if (uResponse.getCode() == 3) {
checkUsername.setImageResource(R.drawable.ic_invalid_username);
username.setError(uResponse.getErrorMessage());
}
} else {
Log.e(TAG, "response != 200");
if (!TextUtils.isEmpty(response.message())) {
Log.e(TAG, response.message());
}
}
}
#Override
public void onFailure(Call<UsernameResponse> call, Throwable t) {
Log.e(TAG, "fail");
t.printStackTrace();
}
});
}catch (Exception e){
Log.e(TAG,"Exceptio");
e.printStackTrace();
}
}
private void attemptLogin() {
String firstName = fName.getText().toString();
String lastName = lName.getText().toString();
String inputUsername = username.getText().toString();
String inputEmail = email.getText().toString();
String inputPass = password.getText().toString();
String inputCPass = confirmPassword.getText().toString();
String inputPhone = phone.getText().toString();
if (TextUtils.isEmpty(firstName)) {
fName.setError("First name can not be blank");
return;
}
if (TextUtils.isEmpty(lastName)) {
lName.setError("Last name can not be blank");
return;
}
if (TextUtils.isEmpty(inputUsername)) {
username.setError("Email can not be blank");
return;
}
if (TextUtils.isEmpty(inputEmail)) {
email.setError("Email can not be blank");
return;
}
if (TextUtils.isEmpty(inputPass)) {
password.setError("Password can not be blank");
return;
}
if (TextUtils.isEmpty(inputCPass)) {
confirmPassword.setError("Please confirm your password");
return;
}
if (inputPass.equals(inputCPass)) {
password.setError("Passwords don't match");
return;
}
//TODO handle phone number
//TODO register request
}
}
and activity_register.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_register"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backgroundColor"
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.rosheta.activities.RegisterActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true">
<LinearLayout
android:id="#+id/act_register_main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/ll_names_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:weightSum="1">
<EditText
android:id="#+id/act_register_et_firstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:hint="First name"
android:inputType="text" />
<EditText
android:id="#+id/act_register_et_lastName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:hint="Last name"
android:inputType="text" />
</LinearLayout>
<EditText
android:id="#+id/act_register_et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:hint="E-mail"
android:inputType="textEmailAddress" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="5dp"
>
<EditText
android:id="#+id/act_register_et_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Username"
android:inputType="text" />
<android.support.v7.widget.AppCompatImageButton
android:id="#+id/act_register_ib_check_username"
android:layout_width="35dp"
android:layout_height="match_parent"
android:src="#drawable/ic_refresh_username"
/>
</LinearLayout>
<EditText
android:id="#+id/act_register_et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:hint="Password"
android:inputType="textPassword" />
<EditText
android:id="#+id/act_register_et_confirm_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:hint="Confirm Password"
android:inputType="textPassword" />
<EditText
android:id="#+id/act_register_et_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:hint="Phone number"
android:inputType="phone" />
<Button
android:id="#+id/act_register_b_signup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Sign up" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_have_account"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:text="#string/have_account_text" />
<TextView
android:id="#+id/act_register_tv_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/tv_have_account"
android:layout_toEndOf="#+id/tv_have_account"
android:layout_toRightOf="#+id/tv_have_account"
android:text="login"
tools:textColor="?android:attr/textColorLink" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
[update]
I found a way to filter this Log from spamming my logcat
in top right corner of logcat select Edit Filter Configuration
1-in filter name write your app name
2-in package name write your app_package_name
3-in (Log message write ^((?!(?:THE_TAG_YOU_NEED_TO_IGNORE)).)$ or Log tag write ^((?!(?:THE_TAG_YOU_NEED_TO_IGNORE)).)$ )
Then it is not bug in your code. Huawei phones shows this log and they have not fixed it. So ignore it.
It seems to me this might be related to the Theme Creator tool nsd.solutions.huaweithemecreator (https://www.apk-s.com/nsd.solutions.huaweithemecreator/), e.g., the UI is changing and the theme creator is checking if a custom theme should be applied given the package name.

Categories

Resources