My project on android studio is running fine on few phones and emulators but crashes on many phones. I have a Main_Activity and clicking on login takes to a second activity. I am sharing the java files and xml files of both activities along with android manifest.
Main Activity Java file
package club.pithynews.iitbhilai_pithy;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private EditText username;
private EditText password;
private Button login_button;
#Override
protected void onCreate(Bundle savedInstanceState) {
java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LoginButton();
}
public void LoginButton() {
username = (EditText) findViewById(R.id.editText);
password = (EditText) findViewById(R.id.editText2);
login_button = (Button) findViewById(R.id.button);
login_button.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
if ((username.getText().toString().equals("user"))&&(password.getText().toString().equals("pass"))) {
Intent intent = new Intent("club.pithynews.iitbhilai_pithy.User");
startActivity(intent);
}
}
}
);
}
}
Main Activity XML file
<?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"
android:background="#drawable/back_login"
tools:context="club.pithynews.iitbhilai_pithy.MainActivity">
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#11000000"
android:ems="10"
android:hint="#string/user_name"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.78"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.53" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#11000000"
android:ems="10"
android:hint="#string/password"
android:inputType="textPassword"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.78"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.64" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:maxHeight="30dp"
android:maxWidth="30dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.05"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.53"
app:srcCompat="#drawable/user1"
android:contentDescription="#string/todo" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:adjustViewBounds="true"
android:maxHeight="30dp"
android:maxWidth="30dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.06"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.64"
app:srcCompat="#drawable/lock1"
android:contentDescription="#string/todo" />
<Button
android:id="#+id/button"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/back_login"
android:text="#string/login"
android:textSize="28sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.79" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="233dp"
android:layout_height="227dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="1dp"
android:layout_marginStart="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.43"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.057"
app:srcCompat="#drawable/logoiit"
android:contentDescription="#string/todo" />
</android.support.constraint.ConstraintLayout >
Second Activity Java file
package club.pithynews.iitbhilai_pithy;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class User extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user);
}
}
Second Activity XML file
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/white"
tools:context="club.pithynews.iitbhilai_pithy.User">
<ImageButton
android:id="#+id/imageButton_emergency3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="80dp"
android:maxHeight="100dp"
android:scaleType="fitCenter"
android:layout_marginLeft="270dp"
android:layout_marginTop="350dp"
android:src="#drawable/emergency3"
android:background="#null"
android:layout_marginStart="270dp"
android:contentDescription="#string/todo13" />
<ImageButton
android:id="#+id/imageButton_feedback1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="125dp"
android:maxHeight="100dp"
android:scaleType="fitCenter"
android:layout_marginLeft="265dp"
android:layout_marginTop="445dp"
android:src="#drawable/feedback1"
android:background="#null"
android:layout_marginStart="265dp"
android:contentDescription="#string/todo12" />
<ImageButton
android:id="#+id/imageButton_aboutus1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="125dp"
android:maxHeight="500dp"
android:scaleType="fitCenter"
android:layout_marginLeft="125dp"
android:layout_marginTop="455dp"
android:src="#drawable/aboutus1"
android:background="#null"
android:layout_marginStart="125dp"
android:contentDescription="#string/todo11" />
<ImageButton
android:id="#+id/imageButton_campusmap1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="125dp"
android:maxHeight="80dp"
android:scaleType="fitCenter"
android:layout_marginLeft="20dp"
android:layout_marginTop="455dp"
android:src="#drawable/campusmap1"
android:background="#null"
android:layout_marginStart="20dp"
android:contentDescription="#string/todo10" />
<ImageButton
android:id="#+id/imageButton_adminstrators"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="100dp"
android:maxHeight="500dp"
android:scaleType="fitCenter"
android:layout_marginLeft="140dp"
android:layout_marginTop="350dp"
android:src="#drawable/adminstrators"
android:background="#null"
android:layout_marginStart="140dp"
android:contentDescription="#string/todo9" />
<ImageButton
android:id="#+id/imageButton_fnr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginTop="350dp"
android:adjustViewBounds="true"
android:background="#null"
android:contentDescription="#string/fee_and_registration"
android:maxHeight="200dp"
android:maxWidth="75dp"
android:scaleType="fitCenter"
android:src="#drawable/fnr"
android:layout_marginStart="25dp" />
<ImageButton
android:id="#+id/imageButton_clubs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="265dp"
android:layout_marginTop="220dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/clubs"
android:layout_marginStart="265dp"
android:contentDescription="#string/todo8" />
<ImageButton
android:id="#+id/imageButton_studdata"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="135dp"
android:layout_marginTop="220dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/studdata"
android:layout_marginStart="135dp"
android:contentDescription="#string/todo7" />
<ImageButton
android:id="#+id/imageButton_bus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="220dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/bus"
android:layout_marginStart="15dp"
android:contentDescription="#string/todo6" />
<ImageButton
android:id="#+id/imageButton_mess"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="265dp"
android:layout_marginTop="100dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/mess"
android:layout_marginStart="265dp"
android:contentDescription="#string/todo5" />
<ImageButton
android:id="#+id/imageButton_faculty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="135dp"
android:layout_marginTop="100dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/faculty"
android:layout_marginStart="135dp"
android:contentDescription="#string/todo4" />
<ImageButton
android:id="#+id/imageButton_academics"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="100dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/academics"
android:layout_marginStart="15dp"
android:contentDescription="#string/todo3" />
<ImageButton
android:id="#+id/imageButton_newsletter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="265dp"
android:layout_marginTop="0dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/news"
android:layout_marginStart="265dp"
android:contentDescription="#string/todo" />
<ImageButton
android:id="#+id/imageButton_events"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="135dp"
android:layout_marginTop="10dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/events"
android:layout_marginStart="135dp"
android:contentDescription="#string/todo1" />
<ImageButton
android:id="#+id/imageButton_today"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="0dp"
android:adjustViewBounds="true"
android:background="#null"
android:maxHeight="500dp"
android:maxWidth="100dp"
android:scaleType="fitCenter"
android:src="#drawable/today"
android:layout_marginStart="15dp"
android:contentDescription="#string/todo2" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:layout_alignEnd="#+id/imageButton_emergency3"
android:layout_alignRight="#+id/imageButton_emergency3"
android:text="#string/textview5"
android:textColor="#color/colorPrimaryDark"
android:visibility="visible"
tools:text=" Emergency " />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView3"
android:layout_alignBottom="#+id/textView3"
android:layout_alignEnd="#+id/imageButton_adminstrators"
android:layout_alignRight="#+id/imageButton_adminstrators"
android:text="#string/administrators"
android:textColor="#color/colorPrimaryDark" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageButton_bus"
android:layout_alignStart="#+id/imageButton_bus"
android:layout_below="#+id/imageButton_fnr"
android:text="#string/textview4"
android:textColor="#color/colorPrimaryDark"
tools:text=" Fees and\n Registration" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_alignStart="#+id/textView3"
android:layout_below="#+id/imageButton_campusmap1"
android:text="#string/textview3"
tools:text=" Campus Map"
android:textColor="#color/colorPrimaryDark"/>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageButton_adminstrators"
android:layout_alignStart="#+id/imageButton_adminstrators"
android:layout_below="#+id/imageButton_campusmap1"
android:text="#string/textview2"
tools:text=" About Us"
android:textColor="#color/colorPrimaryDark"/>
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageButton_feedback1"
android:layout_alignStart="#+id/imageButton_feedback1"
android:layout_alignTop="#+id/textView5"
android:text="#string/textview1"
tools:text=" Feedback"
android:textColor="#color/colorPrimaryDark"/>
</RelativeLayout>
Android Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="club.pithynews.iitbhilai_pithy">
<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".User">
<intent-filter>
<action android:name="club.pithynews.iitbhilai_pithy.User" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
</resources>
Debug Report when app crashes
W/System: ClassLoader referenced unknown path: /data/app/club.pithynews.iitbhilai_pithy-1/lib/arm
I/InstantRun: starting instant run server: is main process
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
D/TextView: setTypeface with style : 0
D/TextView: setTypeface with style : 0
W/ResourceType: Failure getting entry for 0x7f06005a (t=5 e=90) (error -75)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: club.pithynews.iitbhilai_pithy, PID: 16468
java.lang.RuntimeException: Unable to start activity ComponentInfo{club.pithynews.iitbhilai_pithy/club.pithynews.iitbhilai_pithy.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.constraint.ConstraintLayout
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.constraint.ConstraintLayout
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.support.constraint.ConstraintLayout
at android.app.Activity.performCreate(Activity.java:6904)
at a
at android.app.ActivityThread.main(ActivityThread.java:7331)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.content.res.Resources$NotFoundException: Resource "club.pithynews.iitbhilai_pithy:drawable/back_login" (7f06005a) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f06005a a=-1 r=0x7f06005a}
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7331)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Error is self explanatory. You're trying to load an image that is too big.
Canvas: trying to draw too large(111300000bytes) bitmap.
One of your drawable source that you set on your ImageButton or ImageView is too big. You can:
Scale image manually
Perform scaling in code and set the image afterwards
java.lang.RuntimeException: Canvas: trying to draw too large(111300000bytes) bitmap.
As you can see, you are trying to display an image that is too large. Check the size of the included bitmap resources.
you are displaying an image of size 111.3 mb which is too large to handle you need to compress and scale to some smaller version before displaying.
here you can scale your image.
Bitmap scaled = Bitmap.createScaledBitmap(originalBitmap, 120, 120, false);
more here
and compress using
ByteArrayOutputStream out = new ByteArrayOutputStream();
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 85, out);
see more here
Related
My activity does not sync with its layout xml. I really don't know why the coding seems okay. I'm a beginner dev.
This is my activity using Kotlin in Android Studio:
Code:
package com.pkndegwa.mycarmaintenance
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.work.Data
import androidx.work.ExistingWorkPolicy.REPLACE
import androidx.work.OneTimeWorkRequest
import androidx.work.WorkManager
import kotlinx.android.synthetic.service_list_item.*
import com.google.android.material.snackbar.Snackbar.LENGTH_LONG
import com.google.android.material.snackbar.Snackbar.make
import com.pkndegwa.mycarmaintenance.NotifyWork.Companion.NOTIFICATION_ID
import com.pkndegwa.mycarmaintenance.NotifyWork.Companion.NOTIFICATION_WORK
import java.lang.System.currentTimeMillis
import java.text.SimpleDateFormat
import java.util.*
import java.util.Locale.getDefault
import java.util.concurrent.TimeUnit.MILLISECONDS
class AlarmActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.service_list_item)
userInterface()
}
private fun userInterface() {
setSupportActionBar(toolbar)
val titleNotification = getString(R.string.notification_title)
done_fab.setOnClickListener {
val customCalendar = Calendar.getInstance()
customCalendar.set(
date_p.year, date_p.month, date_p.dayOfMonth, time_p.hour, time_p.minute, 0
)
val customTime = customCalendar.timeInMillis
val currentTime = currentTimeMillis()
if (customTime > currentTime) {
val data = Data.Builder().putInt(NOTIFICATION_ID, 0).build()
val delay = customTime - currentTime
scheduleNotification(delay, data)
val titleNotificationSchedule = getString(R.string.notification_schedule_title)
val patternNotificationSchedule = getString(R.string.notification_schedule_pattern)
make(
service_card,
titleNotificationSchedule + SimpleDateFormat(
patternNotificationSchedule, getDefault()
).format(customCalendar.time).toString(),
LENGTH_LONG
).show()
} else {
val errorNotificationSchedule = getString(R.string.notification_schedule_error)
make(service_card, errorNotificationSchedule, LENGTH_LONG).show()
}
}
}
private fun scheduleNotification(delay: Long, data: Data) {
val notificationWork = OneTimeWorkRequest.Builder(NotifyWork::class.java)
.setInitialDelay(delay, MILLISECONDS).setInputData(data).build()
val instanceWorkManager = WorkManager.getInstance(this)
instanceWorkManager.beginUniqueWork(NOTIFICATION_WORK, REPLACE, notificationWork).enqueue()
}
}
This is my layout.xml. This layout been use by two activity which is "ServiceListAdapter" and "AlarmActivity"
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView 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/service_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:layout_marginVertical="4dp"
android:backgroundTint="#E9E9ED"
android:clickable="true"
android:focusable="true"
android:minHeight="#dimen/button_min_height"
app:cardElevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/services_heading_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="12dp"
android:layout_weight="0"
android:importantForAccessibility="no"
android:src="#drawable/ic_baseline_build_circle_24" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/services"
android:textAllCaps="false"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
android:textSize="16sp" />
<TextView
android:id="#+id/services_done_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:textSize="14sp"
tools:text="Oil Filer, Spark Plugs, Battery" />
</LinearLayout>
<ImageView
android:id="#+id/services_expand_view"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="12dp"
android:layout_weight="0"
android:contentDescription="#string/expand_more_button"
android:src="#drawable/ic_baseline_expand_more_24" />
</LinearLayout>
<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/services_details_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="6dp"
android:paddingTop="0dp"
android:paddingBottom="8dp"
android:visibility="gone"
app:layout_constraintEnd_toStartOf="#+id/services_left_layout"
app:layout_constraintStart_toStartOf="#+id/services_left_layout">
<LinearLayout
android:id="#+id/services_left_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:orientation="vertical"
app:layout_constraintEnd_toStartOf="#id/services_right_layout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/service_date"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
android:textSize="16sp" />
<TextView
android:id="#+id/service_date_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:textSize="14sp"
tools:text="01 Nov 2022" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="#string/current_mileage"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
android:textSize="16sp" />
<TextView
android:id="#+id/current_mileage_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:textSize="14sp"
tools:text="2,000 km" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="#string/next_service_mileage"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
android:textSize="16sp" />
<TextView
android:id="#+id/next_service_mileage_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:textSize="14sp"
tools:text="4,000 km" />
</LinearLayout>
<LinearLayout
android:id="#+id/services_right_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/services_left_layout"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/next_service_date"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
android:textSize="16sp" />
<TextView
android:id="#+id/next_service_date_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:textSize="14sp"
tools:text="01 Mar 2023" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="#string/total_cost"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
android:textSize="16sp" />
<TextView
android:id="#+id/total_cost_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:textSize="14sp"
tools:text="1,500 KSH" />
</LinearLayout>
<TextView
android:id="#+id/service_notes_title_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:text="#string/notes"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/services_left_layout" />
<TextView
android:id="#+id/service_notes_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:textAllCaps="false"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/service_notes_title_text_view"
tools:text="Testing out the notes appearance" />
<!-- This section is to create our alarm from different page since Examiner-->
<!-- want the user to separate the alarm from the add service -->
<EditText
android:id="#+id/titleET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/service_notes_text_view"
android:hint="Title for your notification"
tools:context=".ui.AlarmActivity"
android:autofillHints="Which Car" />
<EditText
android:id="#+id/messageET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="You can set your own notification here"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/titleET"
tools:context=".ui.AlarmActivity"
android:autofillHints="what service" />
<DatePicker
android:id="#+id/date_p"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="-30dp"
android:layout_marginRight="-30dp"
android:layout_weight="1"
android:calendarViewShown="false"
android:datePickerMode="spinner"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/messageET"
tools:context=".ui.AlarmActivity"/>
<TimePicker
android:id="#+id/time_p"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="-30dp"
android:layout_marginRight="-30dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:timePickerMode="spinner"
app:layout_constraintTop_toBottomOf="#id/date_p"
tools:context=".ui.AlarmActivity"/>
<Button
android:id="#+id/done_fab"
android:layout_marginTop="20dp"
android:layout_gravity="center"
android:text="schedule_notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/time_p"
tools:context=".ui.AlarmActivity"/>
<LinearLayout
android:id="#+id/services_actions_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end|center_vertical"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/done_fab">
<Button
android:id="#+id/edit_service_button"
style="#style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="4dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="4dp"
android:padding="2dp"
android:text="#string/edit"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
app:drawableTopCompat="#drawable/ic_baseline_edit_24" />
<Button
android:id="#+id/delete_service_button"
style="#style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="2dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="4dp"
android:padding="2dp"
android:text="#string/delete"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="#color/black"
app:drawableTopCompat="#drawable/ic_baseline_delete_24" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
Before onCreate you need to initialize all widget
like
Button done_fab;//in JAVA
private lateinit var done_fab: Button //in Kotlin
//Add other here
and after setContentView you need to initialize the same widget with name like
done_fab=findViewById(R.id.done_fab);//in java
done_fab= findViewById(R.id.done_fab)//in Kotlin
//Add other here
it will be ready to use in overall activity class.
My DetailActivity.java file shows an error by not picking ActivityDetailBinding. Other Activity files are working fine and I put;
buildFeatures{
viewBinding true
}
in build.gradle file before start working on xml files. Only DetailActivity.java file is showing this error.
Error displaying is;
import com.example.juizeesapp.databinding.ActivityDetailBinding; ^ symbol: class ActivityDetailBinding location: package com.example.juizeesapp.databinding
Please look into this help me through this. TIA.
Here is my code.
activity_detail.xml
<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=".DetailActivity"
>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/detailImage"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
app:srcCompat="#drawable/apple" />
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:text="Juice Name"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="#+id/subtract"
android:layout_width="30dp"
android:layout_height="wrap_content"
app:srcCompat="#drawable/minus" />
<TextView
android:id="#+id/quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:layout_marginLeft="2dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:text="1"
android:textSize="18sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/add"
android:layout_width="30dp"
android:layout_height="wrap_content"
app:srcCompat="#drawable/plus" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:orientation="vertical">
<TextView
android:id="#+id/detailDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam iaculis." />
<EditText
android:id="#+id/nameBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#drawable/edit_textbackground"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName"
android:minHeight="48dp"
android:padding="10dp" />
<EditText
android:id="#+id/phoneBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#drawable/edit_textbackground"
android:ems="10"
android:hint="Phone Number"
android:inputType="phone"
android:minHeight="48dp"
android:padding="10dp" />
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:gravity="center"
android:text="Price"
android:textColor="#000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rs. "
android:textColor="#color/red"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="#+id/priceLbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="45"
android:textColor="#color/red"
android:textSize="18dp"
android:textStyle="bold" />
</LinearLayout>
<Button
android:id="#+id/insertBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/btn_background"
android:text="Place Your Order" />
</LinearLayout>
</LinearLayout>
DetailActivity.java
package com.example.juizeesapp;
import android.os.Bundle;
import android.os.PersistableBundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.example.juizeesapp.databinding.ActivityDetailBinding;
public class DetailActivity extends AppCompatActivity {
ActivityDetailBinding binding;
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityDetailBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
int image = getIntent().getIntExtra("image" , 0);
int price = Integer.parseInt(getIntent().getStringExtra("price"));
String name = getIntent().getStringExtra("name");
String description = getIntent().getStringExtra("desc");
binding.detailImage.setImageResource(image);
binding.priceLbl.setText(String.format("%d", price));
binding.nameBox.setText(name);
binding.detailDescription.setText(description);
}
}
you have not declared binding
ActivityDetailBinding binding;
It was a typo error in the manifest file. I stated .DetailActivity at the manifest file is;
<activity
android:name=".DetailActivity"
android:exported="false" />
But when I changed it into;
<activity android:name=".DetailActivity"></activity>
Problem solved.
For some reason I am experiencing massive lag when I try to use the input fields and buttons in my app. The lag is present both in the emulator that comes with Android Studio and my own One Plus Two. I really don't have much code at all so I find this very strange. The app is also using about 150Mb of RAM despite the images used are below 1Mb in total size. The app sometimes even stop responding. I am new to Android development but familiar with programming.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#drawable/bg">
<ImageView
android:contentDescription="#string/logoCS"
android:layout_width="125dp"
android:layout_height="125dp"
android:id="#+id/logo"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="0dp"
android:src="#drawable/logo" />
<Button
android:layout_width="145dp"
android:layout_height="50dp"
android:text="#string/sign_in_with"
android:id="#+id/facebookButton"
android:layout_below="#+id/logo"
android:layout_alignStart="#+id/emailField"
android:layout_marginTop="20dp"
android:textAlignment="viewStart"
android:paddingStart="10dp"
android:paddingEnd="0dp"
android:textSize="12sp"
android:background="#color/signature_gray" />
<Button
android:layout_width="145dp"
android:layout_height="50dp"
android:id="#+id/googleButton"
android:text="#string/sign_in_with"
android:src="#drawable/google"
android:layout_below="#+id/logo"
android:layout_alignTop="#+id/facebookButton"
android:adjustViewBounds ="true"
android:layout_alignEnd="#+id/emailField"
android:textAlignment="viewStart"
android:paddingStart="10dp"
android:paddingEnd="0dp"
android:textSize="12sp"
android:background="#color/signature_gray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/or"
android:textColor="#color/signature_gray"
android:id="#+id/orTextView"
android:layout_marginTop="20dp"
android:layout_below="#+id/googleButton"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="320dp"
android:layout_height="50dp"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/emailField"
android:layout_below="#id/orTextView"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="#color/white"
android:hint="#string/email"
android:textColorHint="#color/signature_gray"
android:textColor="#color/signature_gray"
android:paddingEnd="10dp"
android:paddingStart="50dp"
android:maxLines="1" />
<EditText
android:layout_width="320dp"
android:layout_height="50dp"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/passwordField"
android:layout_marginTop="10dp"
android:layout_below="#+id/emailField"
android:layout_alignStart="#+id/emailField"
android:background="#color/white"
android:hint="#string/password"
android:textColorHint="#color/signature_gray"
android:textColor="#color/signature_gray"
android:paddingEnd="10dp"
android:paddingStart="50dp"
android:maxLines="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/forgot_password"
android:textColor="#color/white"
android:id="#+id/forgotPasswordText"
android:layout_below="#+id/passwordField"
android:layout_alignEnd="#+id/passwordField"
android:layout_marginTop="5dp"
android:onClick="forgotPassword" />
<TextView
android:text="#string/sing_in_error"
android:layout_width="320dp"
android:id="#+id/errorText"
android:layout_marginTop="10dp"
android:textAlignment="center"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_below="#+id/forgotPasswordText"
android:layout_alignEnd="#+id/forgotPasswordText"
android:textColor="#android:color/holo_red_light"
android:visibility="gone" />
<ImageView
android:contentDescription="#string/userIconCS"
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/userIcon"
android:layout_marginBottom="10dp"
android:layout_marginStart="10dp"
android:layout_above="#+id/passwordField"
android:layout_alignStart="#+id/emailField"
android:background="#drawable/user" />
<ImageView
android:contentDescription="#string/pwIconCS"
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/passwordIcon"
android:layout_marginBottom="10dp"
android:layout_marginStart="10dp"
android:layout_above="#+id/signInButton"
android:layout_alignStart="#+id/passwordField"
android:background="#drawable/password" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/not_a_member"
android:id="#+id/notMemberField"
android:textColor="#color/white"
android:layout_marginTop="20dp"
android:layout_below="#+id/signInButton"
android:layout_alignEnd="#+id/orTextView"
android:layout_marginEnd="6dp" />
<TextView
android:text="#string/register_now"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/registerText"
android:textColor="#color/white"
android:onClick="register"
android:layout_alignBaseline="#+id/notMemberField"
android:layout_alignBottom="#+id/notMemberField"
android:layout_marginStart="-3dp"
android:layout_toEndOf="#+id/notMemberField" />
<Button
android:layout_width="320dp"
android:layout_height="50dp"
android:id="#+id/signInButton"
android:layout_marginTop="65dp"
android:background="#color/signature"
android:text="#string/sing_in"
android:textColor="#color/white"
android:onClick="signIn"
android:layout_below="#+id/passwordField"
android:layout_alignEnd="#+id/passwordField" />
<ImageView
android:contentDescription="#string/googleLogoCS"
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/googleImage"
android:elevation="2dp"
android:background="#drawable/google"
android:layout_alignTop="#+id/googleButton"
android:layout_alignEnd="#+id/googleButton"
android:layout_marginTop="10dp"
android:layout_marginEnd="15dp" />
<ImageView
android:contentDescription="#string/facebookLogoCS"
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/facebookImage"
android:elevation="2dp"
android:background="#drawable/facebook"
android:layout_alignTop="#+id/facebookButton"
android:layout_alignEnd="#+id/facebookButton"
android:layout_marginTop="10dp"
android:layout_marginEnd="15dp" />
</RelativeLayout>
MainActivity.java
import android.app.Activity;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
private Button facebookButton;
private Button googleButton;
private EditText emailField;
private EditText passwordField;
private Button loginButton;
private TextView registerText;
private TextView errorText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
facebookButton = (Button) findViewById(R.id.facebookButton);
googleButton = (Button) findViewById(R.id.googleButton);
emailField = (EditText) findViewById(R.id.emailField);
passwordField = (EditText) findViewById(R.id.passwordField);
loginButton = (Button) findViewById(R.id.signInButton);
registerText = (TextView) findViewById(R.id.registerText);
errorText = (TextView) findViewById(R.id.errorText);
registerText.setPaintFlags(registerText.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
}
This question already has answers here:
Null pointer Exception - findViewById()
(12 answers)
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 7 years ago.
The error is
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.RelativeLayout.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
my java is
package com.doctorfinderapp.doctorfinder;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.RelativeLayout;
public class DoctorProfileActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scrolling);
//get data from previous activity
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Invia una mail a Dottore", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
//vado sul feed
RelativeLayout feedback = (RelativeLayout) findViewById(R.id.feedback);
feedback.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(DoctorProfileActivity.this, FeedbackItemActivity.class);
startActivity(intent);
}
});
}
}
xml code where is declared the function "feedbackfunction"
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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_marginTop="#dimen/activity_horizontal_margin"
android:padding="#dimen/activity_horizontal_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.letsnurture.ln_202.coordinatorlayoutpart1.ScrollingActivity"
tools:showIn="#layout/activity_scrolling">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="74dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="#dimen/activity_horizontal_margin"
android:layout_weight="0.61">
<ImageView
android:id="#+id/ivContactItem1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:src="#drawable/ic_account_circle_black_24dp" />
<TextView
android:id="#+id/tvNumber1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_toEndOf="#id/ivContactItem1"
android:layout_toRightOf="#id/ivContactItem1"
android:text="Lorenzo Gitto"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:textColor="#212121" />
<ToggleButton
android:id="#+id/chkState1"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:background="#drawable/ic_account_circle_white_24dp"
android:checked="true"
android:padding="6dp"
android:textOff=""
android:textOn="" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="#dimen/activity_horizontal_margin">
<ImageView
android:id="#+id/ivContactItem2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:src="#drawable/ic_info_black_24dp"
android:visibility="visible" />
<TextView
android:id="#+id/tvNumber2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_toEndOf="#id/ivContactItem2"
android:layout_toRightOf="#id/ivContactItem2"
android:text="Chirurgia Toracica"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:textColor="#212121" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tvNumber2"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_marginTop="8dp"
android:layout_toEndOf="#id/ivContactItem2"
android:layout_toRightOf="#id/ivContactItem2"
android:text="Chirurgia Vascolare"
android:textAppearance="#style/TextAppearance.AppCompat.Small"
android:textColor="#727272" />
<ToggleButton
android:id="#+id/chkState2"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:background="#drawable/ic_info_white_24dp"
android:checked="false"
android:padding="6dp"
android:textOff=""
android:textOn="" />
</RelativeLayout>
<include layout="#layout/item_divider" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="#dimen/activity_horizontal_margin">
<ImageView
android:id="#+id/ivContactItem3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:src="#drawable/ic_book_black_24dp" />
<TextView
android:id="#+id/tvNumber3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_toEndOf="#id/ivContactItem3"
android:layout_toLeftOf="#+id/chkState3"
android:layout_toRightOf="#id/ivContactItem3"
android:layout_toStartOf="#+id/chkState3"
android:ellipsize="end"
android:maxLines="1"
android:text="Anni di esperienza: "
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:textColor="#212121" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tvNumber3"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_marginTop="8dp"
android:layout_toEndOf="#id/ivContactItem3"
android:layout_toRightOf="#id/ivContactItem3"
android:text="11"
android:textAppearance="#style/TextAppearance.AppCompat.Small"
android:textColor="#727272" />
<ToggleButton
android:id="#+id/chkState3"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:background="#drawable/ic_info_white_24dp"
android:checked="true"
android:padding="6dp"
android:textOff=""
android:textOn="" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="#dimen/activity_horizontal_margin">
<ImageView
android:id="#+id/ivContactItem4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:src="#drawable/ic_explore_black_24dp"
android:visibility="visible" />
<TextView
android:id="#+id/tvNumber4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_toEndOf="#id/ivContactItem4"
android:layout_toLeftOf="#+id/chkState4"
android:layout_toRightOf="#id/ivContactItem4"
android:layout_toStartOf="#+id/chkState4"
android:ellipsize="end"
android:maxLines="1"
android:text="Luogo di lavoro"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:textColor="#212121" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tvNumber4"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_marginTop="8dp"
android:layout_toEndOf="#id/ivContactItem4"
android:layout_toRightOf="#id/ivContactItem4"
android:text="Via del Porto, 21"
android:textAppearance="#style/TextAppearance.AppCompat.Small"
android:textColor="#727272" />
<ToggleButton
android:id="#+id/chkState4"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:background="#drawable/ic_info_white_24dp"
android:padding="6dp"
android:textOff=""
android:textOn="" />
</RelativeLayout>
<include layout="#layout/item_divider" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:onClick="feedbackfunction"
android:padding="#dimen/activity_horizontal_margin">
<ImageView
android:id="#+id/ivContactItem5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:src="#drawable/ic_exit_to_app_white_24dp" />
<TextView
android:id="#+id/tvNumber5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_toEndOf="#id/ivContactItem5"
android:layout_toLeftOf="#+id/chkState5"
android:layout_toRightOf="#id/ivContactItem5"
android:layout_toStartOf="#+id/chkState5"
android:ellipsize="end"
android:maxLines="1"
android:text="Punteggio Feedback"
android:clickable="true"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:textColor="#212121"
/>
<ToggleButton
android:id="#+id/chkState5"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:background="#drawable/ic_book_white_24dp"
android:checked="true"
android:padding="6dp"
android:textOff=""
android:textOn="" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:padding="#dimen/activity_horizontal_margin">
<ImageView
android:id="#+id/ivContactItem6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:src="#drawable/ic_book_black_24dp"
android:visibility="visible" />
<TextView
android:id="#+id/tvNumber6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_toEndOf="#id/ivContactItem6"
android:layout_toLeftOf="#+id/chkState6"
android:layout_toRightOf="#id/ivContactItem6"
android:layout_toStartOf="#+id/chkState6"
android:ellipsize="end"
android:maxLines="1"
android:text="Ulteriori info"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:textColor="#212121" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tvNumber6"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_marginTop="8dp"
android:layout_toEndOf="#id/ivContactItem6"
android:layout_toRightOf="#id/ivContactItem6"
android:maxLines="10"
android:text="Vai Su linkedin per vedere le mie info e competenze...http://www.linkedin.com/NomeDottore "
android:textAppearance="#style/TextAppearance.AppCompat.Small"
android:textColor="#727272" />
<ToggleButton
android:id="#+id/chkState6"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:background="#drawable/ic_exit_to_app_white_24dp"
android:padding="6dp"
android:textOff=""
android:textOn="" />
</RelativeLayout>
<include layout="#layout/item_divider" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="#dimen/activity_horizontal_margin">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prenota appuntamento"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/activity_horizontal_margin"
android:layout_marginTop="#dimen/activity_horizontal_margin"
android:text="Videochiama"
/>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Can someone help me?? Thanks to all
You don't have any RelativeLayout with id equals feedback.
RelativeLayout feedback = (RelativeLayout) findViewById(R.id.feedback);
So you feedback object is null and you can't execute onClick event on a null object
Solution
Set the RelativeLayout id = feedback
Looks like you're not setting the #id for that RelativeLayout:
android:id="#+id/feedback"
My question is different from other questions previously asked on this site on the same topic. The answer as to how we can store text from EditText field to a string was given as
EditText input = (EditText) findViewById(R.id.inputId);
String str = input.getText().toString();
my question is a bit different.
my java main activity is:
package com.example.fahadsaleem.xyz;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.w3c.dom.Text;
public class MainActivity extends AppCompatActivity {
public String str;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView calc_monday = (TextView) findViewById(R.id.monday_calc);
calc_monday.setOnClickListener(
new Button.OnClickListener(){
public void onClick(View v){
CustomDialogClass cdd = new CustomDialogClass(MainActivity.this);
cdd.show();
TextView text1 = (TextView) cdd.findViewById(R.id.Subject_ID);
text1.setText(str);
TextView text2 = (TextView) cdd.findViewById(R.id.Room_ID);
text2.setText("6 (SEECS)");
TextView text3 = (TextView) cdd.findViewById(R.id.Time_ID);
text3.setText("09:00am 09:50am");
}
}
);
calc_monday.setOnLongClickListener(
new Button.OnLongClickListener() {
public boolean onLongClick(View v) {
kj monday_calc = new kj(MainActivity.this);
monday_calc.show();
return true;
}
}
);
}
}
The kj class has the following code:
package com.example.fahadsaleem.xyz;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
/**
* Created by Fahad Saleem on 12/22/2015.
*/
public class kj extends Dialog implements android.view.View.OnClickListener {
public Activity c;
public Dialog d;
public Button back;
public kj(Activity a) {
super(a);
// TODO Auto-generated constructor stub
this.c = a;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.setting_dialog);
back = (Button) findViewById(R.id.set_btnn);
back.setOnClickListener(this);
}
#Override
public void onClick(View v){
switch (v.getId()){
case R.id.set_btnn:
MainActivity police = new MainActivity();
EditText set_monday_calc = (EditText) findViewById(R.id.set_Subject_ID);
// Store EditText in Variable
police.str = set_monday_calc.getText().toString();
dismiss();
break;
default:
break;
}
dismiss();
}
}
Basically the app's interface has a time table of subjects. When you click on a subject name, a dialog box appears showing 3 things: Subject name, room number and time period.
Now what I want is I should be able to change the 3 things by making a long click on the subject name. I am trying to use this button in class kj to achieve that:
case R.id.set_btnn:
MainActivity police = new MainActivity();
EditText set_monday_calc = (EditText) findViewById(R.id.set_Subject_ID);
// Store EditText in Variable
police.str = set_monday_calc.getText().toString();
dismiss();
this variable str is declared in MainActivity java file. When the user enters the text on the subject name and clicks on this button, the text should be stored in the str variable.
But this is not happening. When I start writing any text on the EditText field on my interface which looks like this:
The following error is seen in the log:
then when I click Go Back button which should set the text I wrote to variable str, the following error is seen in the log:
Later on when I single click on the subject, what I wrote before I clicked on the button is not being showed, rather a blank space is being shown as was declared by this line in mainactivity java file:
public String str;
Like this:
What is the problem? Here are the rest of the files:
CustomDialogClass:
package com.example.fahadsaleem.xyz;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
/**
* Created by Fahad Saleem on 12/22/2015.
*/
public class CustomDialogClass extends Dialog implements android.view.View.OnClickListener {
public Activity c;
public Dialog d;
public Button back;
public CustomDialogClass(Activity a) {
super(a);
// TODO Auto-generated constructor stub
this.c = a;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.custom_dialog);
back = (Button) findViewById(R.id.btnn);
back.setOnClickListener(this);
}
#Override
public void onClick(View v){
switch (v.getId()){
case R.id.btnn:
dismiss();
break;
default:
break;
}
dismiss();
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.fahadsaleem.xyz.MainActivity">
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/gridLayout">
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Thursday"
android:id="#+id/textView5"
android:layout_row="0"
android:layout_column="5"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="Time"
android:id="#+id/textView"
android:layout_row="0"
android:layout_column="0"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Friday"
android:id="#+id/textView6"
android:layout_row="0"
android:layout_column="6"
android:layout_gravity="center"
android:gravity="center" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="900-950"
android:id="#+id/textView7"
android:layout_row="1"
android:layout_column="0"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center"
android:background="#daf8a6" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Monday"
android:id="#+id/textView2"
android:layout_row="0"
android:layout_column="1"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Tuesday"
android:id="#+id/textView3"
android:layout_row="0"
android:layout_column="2"
android:gravity="center"
android:layout_gravity="center" />
<TextView
android:layout_width="100dp"
android:layout_height="27dp"
android:text="Wednesday"
android:id="#+id/textView4"
android:layout_row="0"
android:layout_column="3"
android:layout_gravity="center|fill"
android:gravity="center"/>
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Calculus"
android:id="#+id/monday_calc"
android:layout_row="1"
android:layout_column="1"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center"
android:clickable="true"
android:background="#dbfbb8" />
<TextView
android:layout_width="80dp"
android:layout_height="50dp"
android:text="Programming"
android:id="#+id/Tuesday_Prog"
android:layout_row="1"
android:layout_column="2"
android:layout_rowSpan="2"
android:layout_gravity="center|fill"
android:gravity="center"
android:textSize="13dp" />
<TextView
android:layout_width="100dp"
android:layout_height="27dp"
android:text="Library"
android:id="#+id/textView25"
android:layout_row="1"
android:layout_column="3"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Islamiat"
android:id="#+id/Thursday_Islamiat"
android:layout_row="1"
android:layout_column="5"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Library"
android:id="#+id/poqwe"
android:layout_row="1"
android:layout_column="6"
android:layout_gravity="center"
android:gravity="center" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="1000-1050"
android:id="#+id/textView8"
android:layout_row="2"
android:layout_column="0"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center"
android:background="#e0fcbb" />
<TextView
android:layout_width="80dp"
android:layout_height="75dp"
android:text="ICT Lab"
android:id="#+id/Monday_ICT"
android:layout_row="2"
android:layout_column="1"
android:layout_rowSpan="3"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="100dp"
android:layout_height="27dp"
android:text="Calculus"
android:id="#+id/Wed_calc"
android:layout_row="2"
android:layout_column="3"
android:gravity="center"
android:layout_gravity="bottom" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculus"
android:id="#+id/Thursday_calc"
android:layout_row="2"
android:layout_column="5"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Islamiat"
android:id="#+id/fri_islamiat"
android:layout_row="2"
android:layout_column="6"
android:layout_gravity="center"
android:gravity="center" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="1100-1150"
android:id="#+id/textView9"
android:layout_row="3"
android:layout_column="0"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center"
android:background="#daf8a6" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Library"
android:id="#+id/textView21"
android:layout_row="3"
android:layout_column="2"
android:gravity="center"
android:layout_gravity="bottom" />
<TextView
android:layout_width="100dp"
android:layout_height="27dp"
android:text="Tutorial"
android:id="#+id/textView27"
android:layout_row="3"
android:layout_column="3"
android:layout_gravity="left|bottom"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DM"
android:id="#+id/Thursday_DM"
android:layout_row="3"
android:layout_column="5"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Comm. Skills"
android:id="#+id/fri_comm"
android:layout_row="3"
android:layout_column="6"
android:layout_gravity="center"
android:gravity="center"
android:textSize="13dp" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="1200-1250"
android:id="#+id/textView10"
android:layout_row="4"
android:layout_column="0"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center"
android:background="#e0fcbb" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Comm. Skills"
android:id="#+id/Tuesday_Comm"
android:layout_row="4"
android:layout_column="2"
android:layout_gravity="center|fill"
android:gravity="center"
android:textSize="13dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DM"
android:id="#+id/Wed_DM"
android:layout_row="4"
android:layout_column="3"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorial"
android:id="#+id/textView33"
android:layout_row="4"
android:layout_column="5"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Programming"
android:id="#+id/fri_Prog"
android:layout_row="4"
android:layout_column="6"
android:layout_gravity="center"
android:gravity="center"
android:textSize="13dp" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="Lunch + Prayer Break"
android:id="#+id/textView17"
android:layout_row="5"
android:layout_column="0"
android:layout_gravity="center|fill"
android:gravity="center"
android:layout_columnSpan="7"
android:background="#d9f2f1" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="1400-1450"
android:id="#+id/textView13"
android:layout_row="6"
android:layout_column="0"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center"
android:background="#daf8a6" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="DM"
android:id="#+id/Monday_DM"
android:layout_row="6"
android:layout_column="1"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="80dp"
android:layout_height="50dp"
android:text="ICT Lecture"
android:id="#+id/Tuesday_ICT"
android:layout_row="6"
android:layout_column="2"
android:layout_gravity="center|fill"
android:gravity="center"
android:layout_rowSpan="2" />
<TextView
android:layout_width="100dp"
android:layout_height="75dp"
android:text="Programming Lab"
android:id="#+id/Wed_Prog"
android:layout_row="6"
android:layout_column="3"
android:layout_rowSpan="3"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Library"
android:id="#+id/textView34"
android:layout_row="6"
android:layout_column="5"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Library"
android:id="#+id/textView41"
android:layout_row="6"
android:layout_column="6"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="1500-1550"
android:id="#+id/textView12"
android:layout_row="7"
android:layout_column="0"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center"
android:background="#e0fcbb" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Library"
android:id="#+id/textView18"
android:layout_row="7"
android:layout_column="1"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Library"
android:id="#+id/textView35"
android:layout_row="7"
android:layout_column="5"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Library"
android:id="#+id/textView42"
android:layout_row="7"
android:layout_column="6"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="120dp"
android:layout_height="27dp"
android:text="1600-1650"
android:id="#+id/textView14"
android:layout_row="8"
android:layout_column="0"
android:textAlignment="center"
android:layout_gravity="center|fill"
android:gravity="center"
android:background="#daf8a6" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Library"
android:id="#+id/textView19"
android:layout_row="8"
android:layout_column="1"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="80dp"
android:layout_height="27dp"
android:text="Library"
android:id="#+id/textView24"
android:layout_row="8"
android:layout_column="2"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Library"
android:id="#+id/textView36"
android:layout_row="8"
android:layout_column="5"
android:layout_gravity="center|fill"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Library"
android:id="#+id/textView43"
android:layout_row="8"
android:layout_column="6"
android:layout_gravity="center|fill"
android:gravity="center" />
</GridLayout>
setting_dialog.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width= "400dp"
android:layout_height="140dp"
android:background="#3E80B4"
android:orientation="vertical" >
<TextView
android:id="#+id/set_txt_dia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Subject Name: "
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold"
android:layout_above="#+id/set_textView44"
android:layout_toRightOf="#+id/relativeLayout"
android:layout_toEndOf="#+id/relativeLayout"
android:layout_marginLeft="14dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#3E80B4"
android:orientation="horizontal"
android:id="#+id/relativeLayout">
</RelativeLayout>
<Button
android:id="#+id/set_btnn"
android:layout_width="83dp"
android:layout_height="46dp"
android:background="#android:color/white"
android:clickable="true"
android:text="Go Back"
android:textColor="#5DBCD2"
android:textStyle="bold"
android:layout_marginRight="37dp"
android:layout_marginEnd="37dp"
android:layout_alignTop="#+id/set_Subject_ID"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="25dp" />
<TextView
android:id="#+id/set_textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Time Period: "
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/set_textView44"
android:layout_alignStart="#+id/set_textView44" />
<TextView
android:id="#+id/set_textView44"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Location: "
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold"
android:layout_above="#+id/set_textView15"
android:layout_alignLeft="#+id/set_txt_dia"
android:layout_alignStart="#+id/set_txt_dia" />
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/set_Subject_ID"
android:textSize="16dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="152dp"
android:layout_marginTop="5dp" />
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/set_Time_ID"
android:textColor="#ffffff"
android:textSize="16dp"
android:layout_marginLeft="139dp"
android:layout_marginTop="44dp" />
<EditText
android:layout_width="70dp"
android:layout_height="wrap_content"
android:id="#+id/set_Room_ID"
android:textSize="16dp"
android:textColor="#ffffff"
android:layout_marginLeft="114dp"
android:layout_marginTop="24dp" />
I did not post the whole of java main activity, I only posted that which is relevant.
I haven't noticed you're using any database. I see that in your app you need to share data between classes, so MUST HAVE is to use SharedPreferences standard database:
Read please this:
How to use SharedPreferences in Android to store, fetch and edit values
You tried to get a string value which was temporary and available only for specific class. That's your problem. Solution above.
Hope it help
In onClick you are creating a new instance with which you don't really seem to be doing anything.
If you were to have in you kj class something like:
public MainActivity c;
...
public kj(MainActivity a) {
and then in onClick(View v) under "case R.id.set_btnn":
c.str = set_monday_calc.getText().toString();
you would manage to update str.