This question already has answers here:
Can not find a View with findViewById()
(4 answers)
Unfortunately MyApp has stopped. How can I solve this?
(23 answers)
What is a stack trace, and how can I use it to debug my application errors?
(7 answers)
Closed 5 years ago.
I'm trying to write a messaging application, but when I start it, it crashes, and I do not get an error message, so I have no clue why.
Launch Activity:
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.*;
public class ConnectActivity extends AppCompatActivity {
private Client client;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final EditText txtServerAddress = (EditText) findViewById(R.id.edit_text_server_address);
final EditText txtPortNumber = (EditText) findViewById(R.id.edit_text_port_number);
final EditText txtUsername = (EditText) findViewById(R.id.edit_text_username);
final Button btnLogIn = (Button) findViewById(R.id.button_log_in);
btnLogIn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String username = txtUsername.getText().toString();
if(username.length() == 0)
return;
String portNumber = txtPortNumber.getText().toString();
if(portNumber.length() == 0)
return;
String serverAddress = txtServerAddress.getText().toString();
if(serverAddress.length() == 0)
return;
int port = 0;
try
{
port = Integer.parseInt(portNumber);
}
catch(Exception en)
{
return;
}
ClientActivity clientActivity = new ClientActivity(client);
client = new Client(serverAddress, port, username, clientActivity);
if(!client.start())
return;
Intent intent = new Intent(ConnectActivity.this, ClientActivity.class);
startActivity(intent);
}
});
setContentView(R.layout.activity_connect);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
}
Launch Content xml:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.liftedstarfish.lifte.gpschat0_2.ConnectActivity"
tools:showIn="#layout/activity_connect">
<TextView
android:id="#+id/text_view_server_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="#string/server_address"
android:textColor="#android:color/black"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/text_view_port_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="#string/port_number"
android:textColor="#android:color/black"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/edit_text_server_address" />
<TextView
android:id="#+id/text_view_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="#string/username"
android:textColor="#android:color/black"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/edit_text_port_number" />
<EditText
android:id="#+id/edit_text_server_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName|numberDecimal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_view_server_address" />
<EditText
android:id="#+id/edit_text_port_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="number"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_view_port_number" />
<EditText
android:id="#+id/edit_text_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_view_username" />
<Button
android:id="#+id/button_log_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:text="#string/log_in"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
Launch Activity xml:
<?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"
tools:context="com.liftedstarfish.lifte.gpschat0_2.ConnectActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_connect" />
</android.support.design.widget.CoordinatorLayout>
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.liftedstarfish.lifte.gpschat0_2">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".ClientActivity"
android:label="#string/title_activity_client"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".ConnectActivity"
android:label="#string/title_activity_connect"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
As far as I can tell, I've done everything correctly, but the application is still crashes. I've tried cleaning the application and rebuilding it, but that did not help.
Related
So all I want to do is click the 'Sign up' button on my app and it takes me to the next page. I have made the second page and added a 'setOnclickListener' to the page I want but when I click on the button it takes me to another page that's white. I'm still new to Kotlin. There are no errors popping up that would effect it. Any ideas?
activity_main.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:gravity="top|center"
android:orientation="vertical"
android:background="#drawable/gradient_background"
android:padding="20dp"
tools:context=".MainActivity">
<!--logo-->
<ImageView
android:id="#+id/logo_image_view"
android:layout_width="117dp"
android:layout_height="116dp"
android:layout_gravity="center"
android:layout_marginTop="80dp"
android:contentDescription="#string/todo"
android:scaleType="centerInside"
android:src="#drawable/logo"
tools:ignore="ImageContrastCheck" />
<!--non interactive log in text-->
<!--EmailAddress enter text-->
<TextView
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"/>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000"
android:gravity="center"
android:hint="#string/email"
android:textColorHint="#880E4F"
tools:ignore="VisualLintTextFieldSize,TextContrastCheck" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000"
android:gravity="center"
android:hint="#string/password"
android:textColorHint="#4E342E"
tools:ignore="VisualLintTextFieldSize" />
</com.google.android.material.textfield.TextInputLayout>
<ProgressBar
android:id="#+id/progressbar"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!--Login-->
<Button
android:layout_marginTop="40dp"
android:id="#+id/btn_login"
android:text="#string/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!--register button-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:id="#+id/button"
android:text="#string/sign_up"
android:onClick="mainActivity"
tools:ignore="UsingOnClickInXml" />
</LinearLayout>
MainActivity.kt
package com.example.gymapp
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
private lateinit var signUpButton: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
signUpButton = findViewById(R.id.button)
signUpButton.setOnClickListener {
val intent = Intent(this,RegistrationActivity::class.java)
startActivity(intent)
}
}
fun mainActivity(view: View) {}
}
RegistrationActivity.java
package com.example.gymbuddies;
import android.app.Activity;
public class RegistrationActivity extends Activity {
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.Gymapp"
tools:targetApi="31">
<activity android:name=".register" />
<meta-data
android:name="android.app.lib_name"
android:value="" />
<activity
android:name=".Login"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".SignInActivity"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity android:name=".RegistrationActivity"
android:label="Registration">
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
activity_register.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:gravity="top|center"
android:orientation="vertical"
android:background="#drawable/gradient_background"
android:padding="20dp"
tools:context=".register">
<!--logo-->
<ImageView
android:id="#+id/logo_image_view"
android:layout_width="117dp"
android:layout_height="116dp"
android:src="#drawable/logo"
android:scaleType="centerInside"
android:layout_marginTop="80dp"
android:layout_gravity="center"
/>
<!--non interactive log in text-->
<!--EmailAddress enter text-->
<TextView
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"/>
<!--email-->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000"
android:gravity="center"
android:hint="#string/email"
android:textColorHint="#4527A0"
tools:ignore="VisualLintTextFieldSize" />
</com.google.android.material.textfield.TextInputLayout>
<!--name-->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:gravity="center"
android:id="#+id/name"
android:hint="#string/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000"
tools:ignore="VisualLintTextFieldSize" />
</com.google.android.material.textfield.TextInputLayout>
<!--dob-->
<!--password-->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:gravity="center"
android:id="#+id/password"
android:hint="#string/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000"
tools:ignore="VisualLintTextFieldSize" />
</com.google.android.material.textfield.TextInputLayout>
<ProgressBar
android:id="#+id/progressbar"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_marginTop="50dp"
android:id="#+id/btn_register"
android:text="#string/register"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Register.kt
package com.example.gymapp
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.ProgressBar
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.textfield.TextInputEditText
import com.google.firebase.auth.FirebaseAuth
class Register : AppCompatActivity() {
private lateinit var editTextEmail: TextInputEditText
private lateinit var editTextPassword: TextInputEditText
private lateinit var editName: TextInputEditText
private lateinit var buttonReg: Button
private lateinit var mAuth: FirebaseAuth
private lateinit var progressbar: ProgressBar
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_register)
mAuth = FirebaseAuth.getInstance()
progressbar = findViewById(R.id.progressbar)
editTextEmail = findViewById(R.id.email)
editTextPassword = findViewById(R.id.password)
editName = findViewById(R.id.name)
buttonReg = findViewById(R.id.btn_register)
buttonReg.setOnClickListener {
progressbar.visibility = View.VISIBLE
val email = editTextEmail.text.toString()
val password = editTextPassword.text.toString()
editName.text.toString()
// handle the button click event
if (email.isEmpty() || password.isEmpty()) {
Toast.makeText(this, "Wrong email or password", Toast.LENGTH_SHORT).show()
progressbar.visibility = View.GONE
return#setOnClickListener
}
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
progressbar.visibility = View.GONE
if (task.isSuccessful) {
Toast.makeText(baseContext, "Welcome!.",
Toast.LENGTH_SHORT).show()
} else {
// If sign in fails, display a message to the user.
Toast.makeText(baseContext, "Authentication failed.",
Toast.LENGTH_SHORT).show()
}
}
}
}
}
strings.xml
<resources>
<string name="app_name">GymBuddies</string>
<string name="password">Password</string>
<string name="email_address">Email Address</string>
<string name="type_your_name">Type your name</string>
<string name="login">Login</string>
<string name="email">Email</string>
<string name="register">register</string>
<string name="name">Name</string>
<string name="sign_up">Sign up</string>
<string name="todo">TODO</string>
</resources>
I've read through the code numerous times and I can't see anything conflicting.
Im new to kotlin and Im trying to make a navigation bar with a time selector based on NumberPicker, with 2 other empty fragments (for now atleast), but my problem is that if I start an intent the Navigation bar doesnt show, when I dont put it in code (intent) the navigation bar shows up working correctly, what Im doing wrong, am I missing something??
MainActivity.kt
package com.example.helloworld
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.example.helloworld.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.bottomNavigationView.setOnItemSelectedListener {
when (it.itemId) {
R.id.first -> replaceFragment(Home())
R.id.second -> replaceFragment(Voices())
R.id.third -> replaceFragment(Settings())
else -> {
}
}
true
}
replaceFragment(Home())
Intent(this, SecondActivity::class.java).also {
startActivity(it)
}
}
private fun replaceFragment(fragment: Fragment) {
val fragmentManager = supportFragmentManager
val fragmentTransaction = fragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.frameLayout, fragment)
fragmentTransaction.commit()
}
}
SecondActivity.kt
package com.example.helloworld
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_second.*
class SecondActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_second)
numPickerMin2.minValue = 0
numPickerMin2.maxValue = 23
numPickerSec2.minValue = 0
numPickerSec2.maxValue = 59
var min = 0
var sec = 0
var amOrPm = ""
val str = arrayOf<String>("AM", "PM")
numPickerAM2.minValue = 0
numPickerAM2.maxValue = (str.size - 1)
numPickerAM2.displayedValues = str
numPickerMin2.setOnValueChangedListener { numberPicker, i, i2 ->
min = numberPicker.value
}
numPickerSec2.setOnValueChangedListener { numberPicker, i, i2 ->
sec = numberPicker.value
}
numPickerAM2.setOnValueChangedListener { numberPicker, i, i2 ->
val i = numberPicker.value
amOrPm = str[i]
}
btGetValue2.setOnClickListener {
reminderTime2.text = "$min : $sec : $amOrPm"
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.helloworld"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="0.2">
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="27" />
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
tools:targetApi="31"
android:theme="#style/Theme.HelloWorld">
<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="sensorPortrait"
android:label="#string/app_name"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity">
</activity>
</application>
</manifest>
ActivityMain.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"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/frameLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/bottom_nav"/>
</androidx.constraintlayout.widget.ConstraintLayout>
activity_second.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"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
android:background="#color/BackgroundFirst"
tools:context=".Home">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout4"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_marginTop="55dp"
app:layout_constraintEnd_toStartOf="#+id/guideline2"
app:layout_constraintStart_toStartOf="#+id/guideline2"
app:layout_constraintTop_toTopOf="#+id/guideline3">
<AutoCompleteTextView
android:id="#+id/dropdown_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
android:text="Choose Alert"/>
</com.google.android.material.textfield.TextInputLayout>
<com.shawnlin.numberpicker.NumberPicker
android:id="#+id/numPickerMin2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_centerInParent="true"
android:layout_marginEnd="23dp"
android:gravity="center"
android:theme="#style/AppTheme.Picker"
app:layout_constraintBottom_toBottomOf="#+id/numPickerSec2"
app:layout_constraintEnd_toStartOf="#+id/numPickerSec2"
app:layout_constraintTop_toTopOf="#+id/numPickerSec2"
app:np_dividerColor="#color/black"
app:np_dividerDistance="55dp"
app:np_dividerLength="100dp"
app:np_dividerThickness="3dp"
app:np_formatter=""
app:np_height="180dp"
app:np_max="12"
app:np_min="0"
app:np_selectedTextColor="#color/selected"
app:np_selectedTextSize="60sp"
app:np_textAlign="textAlignCenter"
app:np_textColor="#color/black"
app:np_textSize="40sp"
app:np_typeface="#string/roboto_light"
app:np_value="1"
app:np_wheelItemCount="10"
app:np_width="74dp"
app:np_wrapSelectorWheel="true" />
<com.shawnlin.numberpicker.NumberPicker
android:id="#+id/numPickerSec2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_centerInParent="true"
android:layout_marginTop="37dp"
android:layout_marginEnd="9dp"
android:layout_marginBottom="27dp"
android:gravity="center"
android:theme="#style/AppTheme.Picker"
app:layout_constraintBottom_toTopOf="#+id/textInputLayout4"
app:layout_constraintEnd_toStartOf="#+id/numPickerAM2"
app:layout_constraintTop_toBottomOf="#+id/imageView2"
app:np_dividerColor="#color/black"
app:np_dividerDistance="55dp"
app:np_dividerLength="100dp"
app:np_dividerThickness="3dp"
app:np_formatter=""
app:np_height="180dp"
app:np_max="59"
app:np_min="0"
app:np_selectedTextColor="#color/selected"
app:np_selectedTextSize="60sp"
app:np_textAlign="textAlignCenter"
app:np_textColor="#color/black"
app:np_textSize="40sp"
app:np_typeface="#string/roboto_light"
app:np_value="1"
app:np_wheelItemCount="10"
app:np_width="74dp"
app:np_wrapSelectorWheel="true" />
<com.shawnlin.numberpicker.NumberPicker
android:id="#+id/numPickerAM2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_centerInParent="true"
android:layout_marginStart="56dp"
android:layout_marginEnd="55dp"
android:gravity="center"
android:theme="#style/AppTheme.Picker"
app:layout_constraintBottom_toBottomOf="#+id/numPickerSec2"
app:layout_constraintEnd_toEndOf="#+id/imageView2"
app:layout_constraintStart_toStartOf="#+id/guideline2"
app:layout_constraintTop_toTopOf="#+id/numPickerSec2"
app:np_dividerColor="#color/black"
app:np_dividerDistance="55dp"
app:np_dividerLength="100dp"
app:np_dividerThickness="3dp"
app:np_formatter=""
app:np_height="180dp"
app:np_max="1"
app:np_min="0"
app:np_selectedTextColor="#color/selected"
app:np_selectedTextSize="60sp"
app:np_textAlign="textAlignCenter"
app:np_textColor="#color/black"
app:np_textSize="40sp"
app:np_typeface="#string/roboto_light"
app:np_value="1"
app:np_wheelItemCount="10"
app:np_width="74dp"
app:np_wrapSelectorWheel="true" />
<Button
android:id="#+id/btGetValue2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="78dp"
android:backgroundTint="#color/selected"
android:baselineAligned="false"
android:text="Get Time"
android:textSize="15sp"
app:layout_constraintBottom_toTopOf="#+id/reminderTime2"
app:layout_constraintEnd_toStartOf="#+id/guideline2"
app:layout_constraintStart_toStartOf="#+id/guideline2" />
<TextView
android:id="#+id/reminderTime2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="63dp"
android:text="Time"
android:textSize="40sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/guideline2"
app:layout_constraintStart_toStartOf="#+id/guideline2" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="351dp"
android:layout_height="103dp"
android:layout_marginTop="16dp"
android:layout_weight="1"
android:scaleX="1.5"
android:scaleY="1.5"
app:layout_constraintEnd_toStartOf="#+id/guideline2"
app:layout_constraintStart_toStartOf="#+id/guideline2"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/helloday_logo" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5"
/>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
</androidx.constraintlayout.widget.ConstraintLayout>
Instead of creating a second activity, I suggest that you create another fragment. Use it in the same way as the other fragments which you currently have in your app.
I'm trying to start this activity_main.xlm after a user's registration flow, but when I click on the button, the app closes. I work a little time with Android but I couldn't identify this error.
I need that after clicking the register button, the app remains pressed and calls activity_main.xml
As Logcat shows, the data passes through the api {"insert":"ok"}, but the application closes and does not call activity_main.
RegisterActivity.java
public class RegisterActivity extends AppCompatActivity {
EditText et_name, et_email, et_password, et_repassword;
Button btn_register, btn_login;
#Override
protected void onCreate(Bundle savedInstanceState) {
getSupportActionBar().setTitle("REGISTER");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
et_name = findViewById(R.id.et_name);
et_email =findViewById(R.id.et_email);
et_password = findViewById(R.id.et_password);
et_repassword = findViewById(R.id.et_repassword);
btn_register= findViewById(R.id.btn_register);
btn_login = findViewById(R.id.btn_login);
btn_register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(TextUtils.isEmpty(et_email.getText().toString()) || TextUtils.isEmpty(et_name.getText().toString()) || TextUtils.isEmpty(et_password.getText().toString()) || TextUtils.isEmpty(et_repassword.getText().toString())){
String message = "All input required";
Toast.makeText(RegisterActivity.this, message,Toast.LENGTH_LONG).show();
}else {
RegisterRequest registerRequest = new RegisterRequest();
registerRequest.setName_app(et_name.getText().toString());
registerRequest.setEmail_app(et_email.getText().toString());
registerRequest.setPassword_app(et_password.getText().toString());
sendRegister(registerRequest);
}
}
});
}
private void sendRegister(RegisterRequest registerRequest) {
Call<RegisterResponse> registerResponseCall=ApiClient.getService().registerUser(registerRequest);
registerResponseCall.enqueue(new Callback<RegisterResponse>() {
#Override
public void onResponse(Call<RegisterResponse> call, Response<RegisterResponse> response) {
if (response.isSuccessful()){
String message = "Successful";
Toast.makeText(RegisterActivity.this, message,Toast.LENGTH_LONG).show();
startActivity(new Intent(RegisterActivity.this,MainActivity.class));
finish();
}else{
String message = "An error occurred please try again later...";
Toast.makeText(RegisterActivity.this, message,Toast.LENGTH_LONG).show();
}
}
#Override
public void onFailure(Call<RegisterResponse> call, Throwable t) {
String message = t.getLocalizedMessage();
Toast.makeText(RegisterActivity.this, message,Toast.LENGTH_LONG).show();
}
});
}
}
activity_register.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=".RegisterActivity">
<TextView
android:id="#+id/tv_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/register"
android:textAlignment="center"
android:textSize="50sp"
android:layout_marginStart="25dp"
android:layout_marginBottom="5dp"
android:fontFamily="#font/indigo_daisy"
android:layout_marginTop="60dp"/>
<TextView
android:id="#+id/tv_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tag"
android:textSize="17sp"
android:fontFamily="#font/roboto_regular"
android:layout_marginStart="25dp"
android:layout_marginBottom="50dp"/>
<EditText
android:id="#+id/et_name"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="#string/your_name"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:padding="15dp"
android:inputType="textPersonName"
android:fontFamily="#font/roboto_regular"
android:background="#drawable/et_custom"
android:textSize="15sp" />
<EditText
android:id="#+id/et_email"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="#string/e_mail"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:padding="15dp"
android:fontFamily="#font/roboto_regular"
android:inputType="textEmailAddress"
android:background="#drawable/et_custom"
android:textSize="15sp" />
<EditText
android:id="#+id/et_password"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="#string/password"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:padding="15dp"
android:fontFamily="#font/roboto_regular"
android:inputType="textPassword"
android:background="#drawable/et_custom"
android:textSize="15sp"
app:errorEnabled="true"/>
<EditText
android:id="#+id/et_repassword"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="#string/re_type_password"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:padding="15dp"
android:fontFamily="#font/roboto_regular"
android:inputType="textPassword"
android:background="#drawable/et_custom"
android:textSize="15sp"
app:errorEnabled="true"
app:hintEnabled="false"
app:passwordToggleEnabled="true"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<Button
android:id="#+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/btn_custom"
android:fontFamily="#font/roboto_regular"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="30dp"
android:layout_centerInParent="true"
android:textColor="#android:color/white"
android:text="#string/register"/>
<Button
android:id="#+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="200dp"
android:background="#drawable/btn_custom"
android:fontFamily="#font/roboto_regular"
android:text="#string/login"
android:textColor="#android:color/white" />
</RelativeLayout>
</LinearLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
LoginResponse loginResponse;
#Override
protected void onCreate(Bundle savedInstanceState) {
getSupportActionBar().hide();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
if (intent.getExtras() != null) {
loginResponse = (LoginResponse) intent.getSerializableExtra("data");
Log.e("TAG", "====>" + loginResponse.getEmail());
}
}
}
activity_main.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"
android:gravity="center"
tools:context=".MainActivity">
<ImageView
android:src="#drawable/ic_launcher_foreground"
android:layout_width="188dp"
android:layout_height="200dp"
android:background="#color/colorPrimaryDark"/>
<TextView
android:text="#string/app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:textColor="#color/colorPrimaryDark"/>
</LinearLayout>
manifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".RegisterActivity" />
<activity android:name=".MainActivity"/>
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Logcat
2021-12-09 22:29:45.631 22677-23634/com.guincho.chamemeuguincho E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Process: com.guincho.chamemeuguincho, PID: 22677
java.lang.NoSuchMethodError: No static method metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.art/javalib/core-oj.jar)
at retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall$1.onResponse(DefaultCallAdapterFactory.java:77)
at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:150)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
2021-12-09 22:29:45.675 22677-22677/com.guincho.chamemeuguincho I/ViewRootImpl#9ebca35[LoginActivity]: stopped(false) old=true
2021-12-09 22:29:45.678 22677-23634/com.guincho.chamemeuguincho I/Process: Sending signal. PID: 22677 SIG: 9
You should not get the support action bar before setcontentview is called.
Simply, move getSupportActionBar().hide(); after setContentView(R.layout.activity_main); and it should not crash anymore
Also please provide crash logs in the future, so we can debug quicker
I'm new at programming on Android and still learning. I'm having a problem right now which is my RecyclerView is not working properly. When I'm running my apps it's not showing any error at logcat. The problems are:
Sometime it will load all the items, but sometime it will just showing blank screen so I usually press the back button and enter the activity again and it will load the items.
Sometimes it loads the item but I can't do anything about my recyclerview. I can't click or scroll the RecyclerView.
And sometimes it just works 100% without error.
I'm using CardView in my RecyclerView and I'm using the Retrofit library.
Here are my codes :
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myappcompany.jason.financepharos">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="Finance Demo Apps"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<!-- Login Activity - Form 1 -->
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Main Activity - Form 2 -->
<activity android:name=".MainActivity"/>
<!-- Master Project Activity - Form 3 -->
<activity android:name=".MasterProjectActivity" />
<!-- Project Activity (Create) - Form 3.1 -->
<activity android:name=".ProjectActivity"
android:noHistory="true"/>
<!-- Project Activity (Read/View) - Form 3.2 -->
<activity android:name=".ProjectActivityView"
android:noHistory="true"/>
<!-- Project Activity (Update and Delete) - Form 3.3 -->
<activity android:name=".ProjectActivityUpdate"
android:noHistory="true"/>
</application>
</manifest>
XML (RecyclerView)
<?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:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:id="#+id/recyclerTemp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
XML (CardView)
<?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="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<android.support.v7.widget.CardView
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="wrap_content"
android:layout_margin="5dp"
app:cardElevation="8dp"
android:clickable="false">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="P. ID"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:text=":" />
<TextView
android:id="#+id/tvProjectID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="P. Name"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:text=":" />
<TextView
android:id="#+id/tvProjectName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="P. Application Name"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:text=":" />
<TextView
android:id="#+id/tvProjectApplicationName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="P. Aktif Y/N"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:text=":" />
<TextView
android:id="#+id/tvProjectAktifYN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="P. Update ID"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:text=":" />
<TextView
android:id="#+id/tvProjectUpdateID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="130dp"
android:layout_height="wrap_content"
android:text="P. Update Time"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:text=":" />
<TextView
android:id="#+id/tvProjectUpdateTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
My Adapter :
//Adapter Data Master Project
public class AdapterData extends RecyclerView.Adapter<AdapterData.HolderData> {
private List<DataModel> mList;
private Context ctx;
public AdapterData (Context ctx, List<DataModel> mList){
this.ctx = ctx;
this.mList = mList;
}
#NonNull
#Override
public HolderData onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View layout = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.layoutlistproject,viewGroup, false);
HolderData holder = new HolderData(layout);
return holder;
}
#Override
public void onBindViewHolder(#NonNull HolderData holder, int i) {
DataModel dm = mList.get(i);
holder.MSTPRJ_ID.setText(dm.getMSTPRJ_ID());
holder.MSTPRJ_Name.setText(dm.getMSTPRJ_Name());
holder.MSTPRJ_ApplicationName.setText(dm.getMSTPRJ_ApplicationName());
holder.MSTPRJ_AktifYN.setText(dm.getMSTPRJ_AktifYN());
holder.MSTPRJ_UpdateID.setText(dm.getMSTPRJ_UpdateID());
holder.MSTPRJ_UpdateTime.setText(dm.getMSTPRJ_UpdateTime());
holder.dm = dm;
}
#Override
public int getItemCount() {
return mList.size();
}
class HolderData extends RecyclerView.ViewHolder{
TextView MSTPRJ_ID, MSTPRJ_Name, MSTPRJ_ApplicationName, MSTPRJ_AktifYN, MSTPRJ_UpdateID, MSTPRJ_UpdateTime;
DataModel dm;
public HolderData (View v){
super(v);
MSTPRJ_ID = (TextView) v.findViewById(R.id.tvProjectID);
MSTPRJ_Name = (TextView) v.findViewById(R.id.tvProjectName);
MSTPRJ_ApplicationName = (TextView) v.findViewById(R.id.tvProjectApplicationName);
MSTPRJ_AktifYN = (TextView) v.findViewById(R.id.tvProjectAktifYN);
MSTPRJ_UpdateID = (TextView) v.findViewById(R.id.tvProjectUpdateID);
MSTPRJ_UpdateTime = (TextView) v.findViewById(R.id.tvProjectUpdateTime);
v.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent goInput = new Intent(ctx, ProjectActivityUpdate.class);
goInput.putExtra("MSTPRJ_ID", dm.getMSTPRJ_ID());
goInput.putExtra("MSTPRJ_Name", dm.getMSTPRJ_Name());
goInput.putExtra("MSTPRJ_ApplicationName", dm.getMSTPRJ_ApplicationName());
goInput.putExtra("MSTPRJ_AkitfYN", dm.getMSTPRJ_AktifYN());
goInput.putExtra("MSTPRJ_UpdateID", dm.getMSTPRJ_UpdateID());
goInput.putExtra("MSTPRJ_UpdateTime", dm.getMSTPRJ_UpdateTime());
v.setOnClickListener(this);
ctx.startActivity(goInput);
}
});
}
}
}
My Activity :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_project_view);
pd = new ProgressDialog(this);
mRecyclerProject = (RecyclerView) findViewById(R.id.recyclerTemp);
mRecyclerProject.setHasFixedSize(true);
mManager = new
LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);
mRecyclerProject.setLayoutManager(mManager);
pd.setMessage("Loading...");
pd.setCancelable(false);
pd.show();
Call<ResponsModel> call = RetroServer.retrofitRequest().readProject();
call.enqueue(new Callback<ResponsModel>() {
#Override
public void onResponse(Call<ResponsModel> call,
Response<ResponsModel> response) {
pd.hide();
Log.d("RETRO", "Response : " + response.body().getKode());
mItems = response.body().getResult();
mAdapterProject = new AdapterData(ProjectActivityView.this,
mItems);
mRecyclerProject.setAdapter(mAdapterProject);
mAdapterProject.notifyDataSetChanged();
}
#Override
public void onFailure(Call<ResponsModel> call, Throwable t) {
pd.hide();
Log.d("RETRO", "Failed : Response Gagal");
}
});
}
#Override
public void onDestroy(){
super.onDestroy();
if(pd != null){
pd.dismiss();
pd = null;
}
}
}
Thankyou :)
I'm new new to Android and am working on a simple project that needs login and sign up.
When I click on the links to link to another activity, The buttons do not work.
here is my code....
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/bg_login"
android:gravity="center"
android:padding="10dp"
tools:context=".LoginActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:weightSum="1">
<ImageView android:src="#drawable/logo_bg"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginBottom="100dp"
android:layout_gravity="center_horizontal"
android:contentDescription="#string/Zilwacom_Logo" />
<TextView android:id="#+id/login"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginBottom="24dp"
android:text="#string/welcome_to_zilwacom"
android:gravity="center"
android:textSize="24sp"
android:layout_weight="0.14" />
<!-- Email Label -->
<EditText
android:id="#+id/loginemail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="#string/Email" />
<!-- Password Label -->
<EditText
android:id="#+id/loginpassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="#string/Password"/>
<Button
android:id="#+id/btnlogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:padding="12dp"
android:text="#string/Login"/>
<TextView
android:id="#+id/linksignup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:background="#null"
android:text="#string/btn_link_to_register"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="15dp"
android:clickable="true"/>
</LinearLayout>
</LinearLayout>
and my login code
When the user clicks to sign up, the app shd open the signup activity
public class LoginActivity extends AppCompatActivity {
private EditText email;
private EditText password;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
//Get reference to buttons and texts
//buttons
Button loginbtn =(Button) findViewById(R.id.btnlogin);
TextView signuplink=(TextView) findViewById(R.id.linksignup);
//Texts
email=(EditText) findViewById(R.id.loginemail);
password=(EditText) findViewById(R.id.loginpassword);
signuplink.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(LoginActivity.this, SignupActivity.class);
startActivity(i);
}
});
}
}
I managed to do it guys,
The problem was in the manifest...
I made the change as below..
<activity
android:name=".LoginActivity"
android:label="#string/app_name"
android:launchMode="singleTop"
android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Add/change in your code:
loginbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(LoginActivity.this, SignupActivity.class);
startActivity(i);
}
});
}
Set onClickListener to your Button [loginbtn] not TextView [signuplink].
In your xml layout file add to TextView android:clickable = "true"