Android app unable to start activity componentinfo android.content.res.Resources$NotFound - java

Here's the entire logcat stack trace:
08-23 02:19:52.826 20628-20628/com.example.sham_tech.lastchance E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.sham_tech.lastchance, PID: 20628
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sham_tech.lastchance/com.example.sham_tech.lastchance.MainActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020013
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441)
at android.app.ActivityThread.access$900(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5345)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020013
at android.content.res.Resources.loadDrawable(Resources.java:2152)
at android.content.res.Resources.getDrawable(Resources.java:710)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:354)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:193)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawable Manager.java:181)
at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:689)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:186)
at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java: 77)
at android.support.v7.app.AppCompatDelegateImplBase.<init> (AppCompatDelegateImplBase.java:83)
at android.support.v7.app.AppCompatDelegateImplV7.<init>(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java:28)
at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java:41)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:193)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:173)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:511)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
at
com.example.sham_tech.lastchance.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:5343)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)        
I cannot understand what's the problem!.
Here's the activity_main.xml
<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:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView android:text="Quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
/>
<TextView
android:id="#+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:layout_marginBottom="16dp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:onClick="SubmitOrder"
/>
</LinearLayout>
Is there anything wrong in the code?
MainActivity.java
package com.example.sham_tech.lastchance;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
display(1);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
}
I have tried to solve it for more than 4 days and there is no result. Please help me!

The problem is that it's looking for a file named "abc_ic_ab_back_material.xml" in your res/drawable/ directory and it's not finding it. Make sure you have that file in that location.

The code you have pasted here did not have referenced the
abc_ic_ab_back_material
If you have used it in the other code, so find if you have the resource named abc_ic_ab_back_material under res/drawable/, if not found, just get one.
If you did not have used it anywhere, just clean you project and rebuild.

Related

Was following a tutorial on android development. Did everything same yet im getting errors

package com.example.firstapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onBtnTxt(View view){
TextView txtApp = findViewById(R.id.txtMsg);
EditText inpTxt = findViewById(R.id.input);
txtApp.setText(inpTxt.getText().toString());
}
}
this is java code
<?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:id="#+id/input"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/txtMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome!!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.339" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick= "onBtnTxt"
android:text="Click"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/editTextTextPersonName"
app:layout_constraintVertical_bias="0.286" />
<EditText
android:id="#+id/editTextTextPersonName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:ems="10"
android:hint="Your name"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/txtMsg" />
</androidx.constraintlayout.widget.ConstraintLayout>
this is xml code
2023-01-25 22:07:15.960 9062-9062/com.example.firstapp D/AndroidRuntime: Shutting down VM
2023-01-25 22:07:15.962 9062-9062/com.example.firstapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.firstapp, PID: 9062
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:446)
at android.view.View.performClick(View.java:6597)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1194)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.onKeyUp(View.java:13216)
at android.widget.TextView.onKeyUp(TextView.java:7821)
at android.view.KeyEvent.dispatch(KeyEvent.java:2716)
at android.view.View.dispatchKeyEvent(View.java:12450)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1896)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1896)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1896)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1896)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1896)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1896)
at com.android.internal.policy.DecorView.superDispatchKeyEvent(DecorView.java:428)
at com.android.internal.policy.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1820)
at android.app.Activity.dispatchKeyEvent(Activity.java:3360)
at androidx.core.app.ComponentActivity.superDispatchKeyEvent(ComponentActivity.java:122)
at androidx.core.view.KeyEventDispatcher.dispatchKeyEvent(KeyEventDispatcher.java:84)
at androidx.core.app.ComponentActivity.dispatchKeyEvent(ComponentActivity.java:140)
at androidx.appcompat.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:599)
at androidx.appcompat.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59)
at androidx.appcompat.app.AppCompatDelegateImpl$AppCompatWindowCallback.dispatchKeyEvent(AppCompatDelegateImpl.java:3089)
at com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:342)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:5037)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4905)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4479)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4445)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4585)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4453)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4642)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4479)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4445)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4453)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4479)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4445)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4618)
at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4779)
at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2571)
at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:2081)
at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:2072)
at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2548)
at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:326)
at android.os.Looper.loop(Looper.java:160)
at android.app.ActivityThread.main(ActivityThread.java:6669)
2023-01-25 22:07:15.963 9062-9062/com.example.firstapp E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:441)
... 52 more
Caused by: java.lang.ClassCastException: androidx.constraintlayout.widget.ConstraintLayout cannot be cast to android.widget.EditText
at com.example.firstapp.MainActivity.onBtnTxt(MainActivity.java:25)
... 54 more
this is the error log
I was following android development for beginner course by freecodecamp from youtube.
My android studio is properly installed. I have installed "pie" with api level of 28 as the virtual device. After doing everything exactly same i get this error. My app suddenly crashes and shows fatal error.
Please help Im completely new in this.
If you'll scroll down in your stack starce you will see this:
Caused by: java.lang.ClassCastException: androidx.constraintlayout.widget.ConstraintLayout cannot be cast to android.widget.EditText
at com.example.firstapp.MainActivity.onBtnTxt(MainActivity.java:25)
In your onBtnTxt(View view) method you wrote
EditText inpTxt = findViewById(R.id.input);
but in the layout file you gave this id (id.input) to the root view which is a constraintlayout, not an EditText
change it to
EditText inpTxt = findViewById(R.id.editTextTextPersonName);

Why does this program crash when I try run it?

I have a basic understanding of Java, but am completely new to Android Studio. I tried making a program that increases a counter when a button is held down. I based it on two bits of code I found (one for a simple click counter and one that used onClickListener). Studio doesn't highlight any errors in the code, but the program crashes when I run it on the emulator.
Can someone tell me where I've gone wrong?
Thanks
Here is the xml code
```
<?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">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="96dp"
android:onClick="onClick"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="UsingOnClickInXml" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.524"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="314dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
```
Here is the MainActivity code
```
package com.example.clickcounter;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int numberOfClicks = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick (View view){
TextView myText = findViewById(R.id.textView);
findViewById(R.id.button).setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent mEvent) {
if (mEvent.getAction() == MotionEvent.ACTION_DOWN)
numberOfClicks++;
myText.setText(numberOfClicks);
return false;
}
});
}
}
```
I tried making a counter that increases when a button is held down. I started with a click counter, which worked, but ran into problems when I modified the code to increase the counter when the button was held instead of clicked. The program simply crashed thereafter.
The error output was
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.clickcounter, PID: 22459
android.content.res.Resources$NotFoundException: String resource ID #0x1
at android.content.res.Resources.getText(Resources.java:367)
at android.widget.TextView.setText(TextView.java:6370)
at com.example.clickcounter.MainActivity$1.onTouch(MainActivity.java:29)
at android.view.View.dispatchTouchEvent(View.java:13411)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2698)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2698)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2698)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2698)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2698)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2698)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:465)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1849)
at android.app.Activity.dispatchTouchEvent(Activity.java:3993)
at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:70)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:423)
at android.view.View.dispatchPointerEvent(View.java:13674)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5482)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5285)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4788)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4841)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4807)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4947)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4815)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5004)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4788)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4841)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4807)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4815)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4788)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7505)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7474)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7435)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7630)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:188)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:336)
at android.os.Looper.loop(Looper.java:174)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/Process: Sending signal. PID: 22459 SIG: 9
It looks like you called textView.setText with an integer instead of a string.
If you call textView.setText(1) you would get that error - you need to convert the integer to a string (e.g. with String.valueOf or similar code).
When you pass an integer, it treats that as a string resource identifier and fails with a ResourceNotFound exception when it cannot find that resource.

android.view.InflateException when switching to landscape mode

I am trying to make an app that involves two content mains, one being for portrait the other being for landscape, However, when I switch the orientation to landscape, the app crashes. Portrait and Landscape have different layouts, the only notable difference between the two is that landscape has one more fragment within its layout.
I want to iterate that this is my first time working with landscape mode in android studio so if I made any rookie mistakes, i'm sure you'll be forgiving.
Any input is appreciated, thanks in advance!
Settings Fragment.java
package com.example.celebquizapp;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.content.SharedPreferences;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
public class SettingsFragment extends Fragment implements View.OnClickListener {
private SharedPreferences preferences;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View fragment_view = inflater.inflate(R.layout.fragment_settings, container, false);
preferences = this.getActivity().getSharedPreferences("values", Context.MODE_PRIVATE);
return fragment_view;
}
public void onViewCreated(#NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
RadioGroup selectionOption = getActivity().findViewById(R.id.selection_option_setting);
setRadioButtonListener(selectionOption);
}
public void onClick(View v) {
RadioButton button = (RadioButton) v;
boolean checked = button.isChecked();
if (checked) {
int chosenVal = Integer.parseInt(String.valueOf(button.getText()));
Log.d("RADIOS", "Current value chosen: " + chosenVal);
preferences.edit().putInt("numofopt", chosenVal).apply();
}
}
public void setRadioButtonListener(RadioGroup radioGroup) {
for (int i = 0; i < radioGroup.getChildCount(); i++) {
radioGroup.getChildAt(i).setOnClickListener(this);
}
}
#Override
public void onStart() {
super.onStart();
// Not required to save data in preferences
// So delete on start up
preferences.edit().clear().apply();
}
}
Settings Fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SettingsFragment">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/selectionOptionLabel"
android:textColor="#color/colorBlack"
android:textSize="20sp"
android:layout_marginTop="0dp"
android:padding="10dp"/>
<RadioGroup
android:id="#+id/selection_option_setting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:textSize="20sp"
android:text="#string/_2"
android:layout_marginLeft="10dp" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:text="#string/_3"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:text="#string/_4"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:text="#string/_5"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:text="#string/_6"/>
</RadioGroup>
</LinearLayout>
Error message
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.celebquizapp, PID: 11657
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.celebquizapp/com.example.celebquizapp.MainActivity}: android.view.InflateException: Binary XML file line #22 in com.example.celebquizapp:layout/activity_main: Binary XML file line #26 in com.example.celebquizapp:layout/content_main: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5279)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5187)
at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: android.view.InflateException: Binary XML file line #22 in com.example.celebquizapp:layout/activity_main: Binary XML file line #26 in com.example.celebquizapp:layout/content_main: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #26 in com.example.celebquizapp:layout/content_main: Error inflating class fragment
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.RadioGroup.getChildCount()' on a null object reference
at com.example.celebquizapp.SettingsFragment.setRadioButtonListener(SettingsFragment.java:50)
at com.example.celebquizapp.SettingsFragment.onViewCreated(SettingsFragment.java:32)
at androidx.fragment.app.FragmentManagerImpl.ensureInflatedFragmentView(FragmentManagerImpl.java:1144)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:851)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1133)
at androidx.fragment.app.FragmentManagerImpl.addFragment(FragmentManagerImpl.java:1393)
at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManagerImpl.java:3205)
at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:134)
at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:357)
at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:336)
at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1069)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1263)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1119)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
at com.example.celebquizapp.MainActivity.onCreate(MainActivity.java:18)
at android.app.Activity.performCreate(Activity.java:7802)
E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5279)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5187)
at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
RadioGroup selectionOption = getActivity().findViewById(R.id.selection_option_setting);
It should be
RadioGroup selectionOption = view.findViewById(R.id.selection_option_setting);

Runtime Error with Android Studio (Button)

I would be so, so grateful if you can help me with this problem.
I am learning android development with Android Basics on Udacity.
I am at User Input: Lesson 8.
The apps have been downloading to my phone fine so far but now the app (JustJava) crashes when I press the only button in it. There are no serious (red) errors showing on Android Studio.
I have reviewed logcat but cannot understand it except that the button (onClick) is the problem. I have no idea how to fix it.
This keeps appearing in red in logcat every few seconds: E/TZ_CCM_SERVER: Only 'CCM' are supported
Here is the full error log relating my runtime crash:
07-09 10:51:17.638 18253-18253/com.example.android.justjava E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.justjava, PID: 18253
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:389)
at android.view.View.performClick(View.java:5697)
at android.widget.TextView.performClick(TextView.java:10826)
at android.view.View$PerformClick.run(View.java:22526)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
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: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384)
at android.view.View.performClick(View.java:5697) 
at android.widget.TextView.performClick(TextView.java:10826) 
at android.view.View$PerformClick.run(View.java:22526) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:158) 
at android.app.ActivityThread.main(ActivityThread.java:7224) 
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: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.example.android.justjava.MainActivity.displayPrice(MainActivity.java:45)
at com.example.android.justjava.MainActivity.submitOrder(MainActivity.java:28)
at java.lang.reflect.Method.invoke(Native Method) 
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384) 
at android.view.View.performClick(View.java:5697) 
at android.widget.TextView.performClick(TextView.java:10826) 
at android.view.View$PerformClick.run(View.java:22526) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:158) 
at android.app.ActivityThread.main(ActivityThread.java:7224) 
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) 
EDIT:
MainActivity / java code:
package com.example.android.justjava;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import java.text.NumberFormat;
/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
int coffeeNumber = 3;
display(coffeeNumber);
displayPrice(coffeeNumber * 5);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
/**
* This method displays the given price on the screen.
*/
private void displayPrice(int number) {
TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
}
}
XML 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:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quantity"
android:fontFamily="sans-serif-light"
android:textColor="#android:color/black"
android:padding="10dp"
android:textAllCaps="true"
android:layout_marginBottom="16dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="16sp"
android:fontFamily="sans-serif-light"
android:textColor="#android:color/black"
android:padding="10dp"
android:id="#+id/quantity_text_view"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:fontFamily="sans-serif-light"
android:textColor="#android:color/black"
android:padding="10dp"
android:textAllCaps="true"
android:layout_marginBottom="16dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="€0"
android:textSize="16sp"
android:fontFamily="sans-serif-light"
android:textColor="#android:color/black"
android:padding="10dp"
android:layout="#+id/price_text_view"
/>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Order"
android:onClick="submitOrder"
/>
</LinearLayout>
Check your activity_main.xml in this layout you does not have a TextView with that id price_text_view. Just define a TextView with that id and your App will not crash anymore and you can go Forward to the next chapter ;)
<TextView
android:id="#+id/price_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
I think you just made a silly misstake. I saw you're using layout insteed of id ^^
Change your xml like below
<?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:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Quantity"
android:fontFamily="sans-serif-light"
android:textColor="#android:color/black"
android:padding="10dp"
android:textAllCaps="true"
android:layout_marginBottom="16dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="16sp"
android:fontFamily="sans-serif-light"
android:textColor="#android:color/black"
android:padding="10dp"
android:id="#+id/quantity_text_view"/>
<TextView
android:id="#+id/price_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:fontFamily="sans-serif-light"
android:textColor="#android:color/black"
android:padding="10dp"
android:textAllCaps="true"
android:layout_marginBottom="16dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="€0"
android:textSize="16sp"
android:fontFamily="sans-serif-light"
android:textColor="#android:color/black"
android:padding="10dp"
android:layout="#+id/price_text_view"
/>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Order"
android:onClick="submitOrder"
/>
I have just Called TextView in global, then initialized in onCreateand then using wherever we need.
Just replace this edited java class,
public class MainActivity extends AppCompatActivity {
TextView priceTextView, quantityTextView ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
priceTextView = (TextView) findViewById(R.id.price_text_view);
}
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
int coffeeNumber = 3;
display(coffeeNumber);
displayPrice(coffeeNumber * 5);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
quantityTextView.setText("" + number);
}
/**
* This method displays the given price on the screen.
*/
private void displayPrice(int number) {
priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
}
}

My Android app crashes while trying to start a new activity using Intents [duplicate]

This question already has answers here:
How to fix Error inflating class null
(2 answers)
Closed 4 years ago.
Am new to Android programming and I decided to build a quiz app. I built the layout and wanted to set up a button to start a new activity which begins the quiz. I also set up the method in the MainActivity correctly but when I run the app and click on the button, the app crashes and leaves a ton of error messages on logcat.
Any help will be appreciated. Below are the codes.
XML Code:
<Button
android:id="#+id/button_view"
android:layout_width="200dp"
android:layout_height="60dp"
android:layout_below="#id/name_view"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:background="#drawable/button_round"
android:fontFamily="sans-serif-light"
android:inputType="textCapWords"
android:text="Go!"
android:onClick="startQuestionOne"
android:textSize="24dp" />
MainActivity
public class LoginActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
public void startQuestionOne(View view) {
Intent myIntent = new Intent(LoginActivity.this, QuestionOneActivity.class);
startActivity(myIntent);
}
}
Logcat Message
06-25 18:32:34.259 13705-13705/com.example.android.udacityquizapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.udacityquizapp, PID: 13705
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.udacityquizapp/com.example.android.udacityquizapp.QuestionOneActivity}: android.view.InflateException: Binary XML file line #23: Error inflating class null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2344)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access$800(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5328)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class null
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.android.udacityquizapp.QuestionOneActivity.onCreate(QuestionOneActivity.java:11)
at android.app.Activity.performCreate(Activity.java:5279)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396) 
at android.app.ActivityThread.access$800(ActivityThread.java:154) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:5328) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: java.lang.NullPointerException
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:99)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1035)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1092)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139) 
at com.example.android.udacityquizapp.QuestionOneActivity.onCreate(QuestionOneActivity.java:11) 
at android.app.Activity.performCreate(Activity.java:5279) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396) 
at android.app.ActivityThread.access$800(ActivityThread.java:154) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1324) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:5328) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644) 
at dalvik.system.NativeStart.main(Native Method) 
This is the full XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient"
tools:context=".LoginActivity">
<ImageView
android:id="#+id/udacity_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:src="#drawable/udacity" />
<TextView
android:id="#+id/textview_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/udacity_logo"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:fontFamily="sans-serif-ligh"
android:text="Udacity Quiz App"
android:textColor="#faebd7"
android:textSize="36dp"
android:textStyle="bold" />
<EditText
android:id="#+id/name_view"
android:layout_width="300dp"
android:layout_height="40dp"
android:layout_below="#id/textview_text"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:background="#drawable/edit_round"
android:drawableLeft="#drawable/ic_action_user"
android:ems="10"
android:fontFamily="sans-serif-light"
android:hint="Name"
android:inputType="textCapWords"
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="16dp" />
<Button
android:id="#+id/button_view"
android:layout_width="200dp"
android:layout_height="60dp"
android:layout_below="#id/name_view"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:background="#drawable/button_round"
android:fontFamily="sans-serif-light"
android:inputType="textCapWords"
android:text="Go!"
android:onClick="startQuestionOne"
android:textSize="24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:fontFamily="sans-serif-light"
android:text="powered by: #William"
android:textColor="#faebd7" />
</RelativeLayout>
Above is the XML for LoginActivity which contains a button. When the button is clicked, its supposed to start a new activity called QuestionOneActivity, but instead, the app crashes.
LoginActivity
package com.example.android.udacityquizapp;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class LoginActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
public void startQuestionOne(View view) {
Intent myIntent = new Intent(LoginActivity.this,
QuestionOneActivity.class);
startActivity(myIntent);
}
}
firstly bind Button in onCreate() as
Button b = (Button) findViewById(R.id.button_view);
then check if your activity QuestionOneActivity is declared in manifest file
after that check QuestionOneActivity activity xml file for error if have any...
Thanks clay_to_n, based on your suggestions, i found out that i used a lower case 'v' for my View tag. When i adjusted it, the app runs as expected.

Categories

Resources