Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSaurabh B
Courses Plus Student 2,880 PointsQuestion on radio button beginner level app
Please help me. Whats wrong with the code. The app crashes and I get msg as "app has unfortunately stopped"
package com.example.saurabhb.gettingcolor;
import android.content.Intent; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Toast;
public class AskColorMainActivity extends ActionBarActivity {
private RadioGroup mainRadioGroup;
private RadioButton radioButtonForRed;
private Button nextButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ask_color_main);
radioButtonForRed = (RadioButton) findViewById(R.id.radioButtonForRed);
nextButton = (Button) findViewById(R.id.nextButton);
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int forGettingId = mainRadioGroup.getCheckedRadioButtonId();
radioButtonForRed = (RadioButton) findViewById(forGettingId);
String forIntent = radioButtonForRed.getText().toString();
Toast.makeText(AskColorMainActivity.this, forIntent, Toast.LENGTH_LONG).show();
Intent intent = new Intent(AskColorMainActivity.this, AboutTheColor.class);
intent.putExtra("colour", forIntent);
startActivity(intent);
}
});
}
}
/// on next activity:
package com.example.saurabhb.gettingcolor;
import android.content.Intent; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView;
public class AboutTheColor extends ActionBarActivity {
private TextView pageTwoText;
private String lastTimeIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about_the_color);
Intent intent = getIntent();
lastTimeIntent = intent.getStringExtra("colour");
pageTwoText.setText("Hello");
}
}
2 Answers
James Simshaw
28,738 PointsHello,
In your AboutTheColor class, you call pageTwoText.setText("Hello"); without initializing the pageTwoText TextView variable. You probably want to use findViewById to initialize pageTwoText.
Saurabh B
Courses Plus Student 2,880 PointsYes.... Here it is...
04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ VFY: unable to resolve virtual method 12208: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ VFY: unable to resolve virtual method 12214: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ VFY: unable to resolve virtual method 9779: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e 04-24 18:05:46.041 19299-19299/com.example.saurabhb.gettingcolor I/dalvikvm﹕ Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged 04-24 18:05:46.041 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ VFY: unable to resolve virtual method 12211: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V 04-24 18:05:46.041 19299-19299/com.example.saurabhb.gettingcolor D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0007 04-24 18:05:46.051 19299-19299/com.example.saurabhb.gettingcolor I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations 04-24 18:05:46.051 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ VFY: unable to resolve virtual method 393: Landroid/content/res/TypedArray;.getChangingConfigurations ()I 04-24 18:05:46.051 19299-19299/com.example.saurabhb.gettingcolor D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 04-24 18:05:46.051 19299-19299/com.example.saurabhb.gettingcolor I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType 04-24 18:05:46.051 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ VFY: unable to resolve virtual method 415: Landroid/content/res/TypedArray;.getType (I)I 04-24 18:05:46.051 19299-19299/com.example.saurabhb.gettingcolor D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 04-24 18:05:46.061 19299-19299/com.example.saurabhb.gettingcolor I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawable 04-24 18:05:46.061 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ VFY: unable to resolve virtual method 356: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable; 04-24 18:05:46.061 19299-19299/com.example.saurabhb.gettingcolor D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 04-24 18:05:46.061 19299-19299/com.example.saurabhb.gettingcolor I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawableForDensity 04-24 18:05:46.061 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ VFY: unable to resolve virtual method 358: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable; 04-24 18:05:46.061 19299-19299/com.example.saurabhb.gettingcolor D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 04-24 18:05:47.523 19299-19303/com.example.saurabhb.gettingcolor D/dalvikvm﹕ GC_CONCURRENT freed 203K, 11% free 9620K/10759K, paused 117ms+36ms, total 194ms 04-24 18:05:48.374 19299-19299/com.example.saurabhb.gettingcolor D/libEGL﹕ loaded /system/lib/egl/libGLES_hawaii.so 04-24 18:05:48.394 19299-19299/com.example.saurabhb.gettingcolor D/﹕ mem_init ++ 04-24 18:05:48.394 19299-19299/com.example.saurabhb.gettingcolor D/﹕ gHwMemAllocator client 3 04-24 18:05:48.394 19299-19299/com.example.saurabhb.gettingcolor D/﹕ **** Using ION allocator **** 04-24 18:05:48.394 19299-19299/com.example.saurabhb.gettingcolor D/﹕ registered SIGUSR1[10] for pid[19299] 04-24 18:05:48.394 19299-19299/com.example.saurabhb.gettingcolor D/﹕ HwMemAllocatorImpl Static Counters 0 0 04-24 18:05:48.394 19299-19299/com.example.saurabhb.gettingcolor D/﹕ HwMemAllocatorImpl[4ad7dd5c] totalDeviceAllocSize[0] totalFree[0] maxFree[0] in numSlabs[0] 04-24 18:05:48.414 19299-19299/com.example.saurabhb.gettingcolor D/﹕ mem_init 4ad7dd5c-- 04-24 18:05:48.414 19299-19299/com.example.saurabhb.gettingcolor D/ION﹕ config: version(0x10000) secure(0xf000) 256M(0x22d) fast(0x608) hwwr(0x608) 04-24 18:05:48.414 19299-19299/com.example.saurabhb.gettingcolor D/﹕ Waiting for mm thread to come up 04-24 18:05:48.424 19299-19299/com.example.saurabhb.gettingcolor D/﹕ Waiting for mm thread to come up 04-24 18:05:48.424 19299-19338/com.example.saurabhb.gettingcolor D/﹕ mm_device_thread starting 04-24 18:05:48.444 19299-19299/com.example.saurabhb.gettingcolor D/HAWAII_EGL﹕ eglCreateContext() config: 35 context: 0x4cf9f918, VC context 1, Thread 19299 04-24 18:05:48.454 19299-19299/com.example.saurabhb.gettingcolor D/HAWAII_EGL﹕ Set SWAP INTERVAL 0 04-24 18:05:48.454 19299-19299/com.example.saurabhb.gettingcolor D/HAWAII_EGL﹕ eglCreateWindowSurface() surface: 0x4cf9f938, VC surface: 1, Thread: 19299 04-24 18:05:48.454 19299-19299/com.example.saurabhb.gettingcolor D/HAWAII_EGL﹕ eglMakeCurrent(0x4cf9f918, 0x4cf9f938, 0x4cf9f938) Thread: 19299 04-24 18:05:48.474 19299-19299/com.example.saurabhb.gettingcolor D/OpenGLRenderer﹕ Enabling debug mode 0 04-24 18:05:51.757 19299-19299/com.example.saurabhb.gettingcolor D/AndroidRuntime﹕ Shutting down VM 04-24 18:05:51.757 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x416c82a0) 04-24 18:05:51.847 19299-19299/com.example.saurabhb.gettingcolor E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.NullPointerException at com.example.saurabhb.gettingcolor.AskColorMainActivity$1.onClick(AskColorMainActivity.java:32) at android.view.View.performClick(View.java:4275) at android.view.View$PerformClick.run(View.java:17434) at android.os.Handler.handleCallback(Handler.java:615) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:177) at android.app.ActivityThread.main(ActivityThread.java:4947) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) at dalvik.system.NativeStart.main(Native Method)
Saurabh B
Courses Plus Student 2,880 PointsSaurabh B
Courses Plus Student 2,880 PointsThanks but after doing it also i am facing the same problem:
public class AboutTheColor extends ActionBarActivity {
James Simshaw
28,738 PointsJames Simshaw
28,738 PointsCan you post the contents of logcat after the error occurs? That would help in troubleshooting this at this point.
Saurabh B
Courses Plus Student 2,880 PointsSaurabh B
Courses Plus Student 2,880 PointsYes, here it is... 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ VFY: unable to resolve virtual method 12208: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ VFY: unable to resolve virtual method 12214: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ VFY: unable to resolve virtual method 9779: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V 04-24 18:05:46.001 19299-19299/com.example.saurabhb.gettingcolor D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e 04-24 18:05:46.041 19299-19299/com.example.saurabhb.gettingcolor I/dalvikvm﹕ Could not find method android.view.ViewGroup.onRtlPropertiesChanged, referenced from method android.support.v7.widget.Toolbar.onRtlPropertiesChanged 04-24 18:05:46.041 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ VFY: unable to resolve virtual method 12211: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V 04-24 18:05:46.041 19299-19299/com.example.saurabhb.gettingcolor D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0007 04-24 18:05:46.051 19299-19299/com.example.saurabhb.gettingcolor I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations 04-24 18:05:46.051 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ VFY: unable to resolve virtual method 393: Landroid/content/res/TypedArray;.getChangingConfigurations ()I 04-24 18:05:46.051 19299-19299/com.example.saurabhb.gettingcolor D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 04-24 18:05:46.051 19299-19299/com.example.saurabhb.gettingcolor I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType 04-24 18:05:46.051 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ VFY: unable to resolve virtual method 415: Landroid/content/res/TypedArray;.getType (I)I 04-24 18:05:46.051 19299-19299/com.example.saurabhb.gettingcolor D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 04-24 18:05:46.061 19299-19299/com.example.saurabhb.gettingcolor I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawable 04-24 18:05:46.061 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ VFY: unable to resolve virtual method 356: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable; 04-24 18:05:46.061 19299-19299/com.example.saurabhb.gettingcolor D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 04-24 18:05:46.061 19299-19299/com.example.saurabhb.gettingcolor I/dalvikvm﹕ Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.internal.widget.ResourcesWrapper.getDrawableForDensity 04-24 18:05:46.061 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ VFY: unable to resolve virtual method 358: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable; 04-24 18:05:46.061 19299-19299/com.example.saurabhb.gettingcolor D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 04-24 18:05:47.523 19299-19303/com.example.saurabhb.gettingcolor D/dalvikvm﹕ GC_CONCURRENT freed 203K, 11% free 9620K/10759K, paused 117ms+36ms, total 194ms 04-24 18:05:48.374 19299-19299/com.example.saurabhb.gettingcolor D/libEGL﹕ loaded /system/lib/egl/libGLES_hawaii.so 04-24 18:05:48.394 19299-19299/com.example.saurabhb.gettingcolor D/﹕ mem_init ++ 04-24 18:05:48.394 19299-19299/com.example.saurabhb.gettingcolor D/﹕ gHwMemAllocator client 3 04-24 18:05:48.394 19299-19299/com.example.saurabhb.gettingcolor D/﹕ **** Using ION allocator **** 04-24 18:05:48.394 19299-19299/com.example.saurabhb.gettingcolor D/﹕ registered SIGUSR1[10] for pid[19299] 04-24 18:05:48.394 19299-19299/com.example.saurabhb.gettingcolor D/﹕ HwMemAllocatorImpl Static Counters 0 0 04-24 18:05:48.394 19299-19299/com.example.saurabhb.gettingcolor D/﹕ HwMemAllocatorImpl[4ad7dd5c] totalDeviceAllocSize[0] totalFree[0] maxFree[0] in numSlabs[0] 04-24 18:05:48.414 19299-19299/com.example.saurabhb.gettingcolor D/﹕ mem_init 4ad7dd5c-- 04-24 18:05:48.414 19299-19299/com.example.saurabhb.gettingcolor D/ION﹕ config: version(0x10000) secure(0xf000) 256M(0x22d) fast(0x608) hwwr(0x608) 04-24 18:05:48.414 19299-19299/com.example.saurabhb.gettingcolor D/﹕ Waiting for mm thread to come up 04-24 18:05:48.424 19299-19299/com.example.saurabhb.gettingcolor D/﹕ Waiting for mm thread to come up 04-24 18:05:48.424 19299-19338/com.example.saurabhb.gettingcolor D/﹕ mm_device_thread starting 04-24 18:05:48.444 19299-19299/com.example.saurabhb.gettingcolor D/HAWAII_EGL﹕ eglCreateContext() config: 35 context: 0x4cf9f918, VC context 1, Thread 19299 04-24 18:05:48.454 19299-19299/com.example.saurabhb.gettingcolor D/HAWAII_EGL﹕ Set SWAP INTERVAL 0 04-24 18:05:48.454 19299-19299/com.example.saurabhb.gettingcolor D/HAWAII_EGL﹕ eglCreateWindowSurface() surface: 0x4cf9f938, VC surface: 1, Thread: 19299 04-24 18:05:48.454 19299-19299/com.example.saurabhb.gettingcolor D/HAWAII_EGL﹕ eglMakeCurrent(0x4cf9f918, 0x4cf9f938, 0x4cf9f938) Thread: 19299 04-24 18:05:48.474 19299-19299/com.example.saurabhb.gettingcolor D/OpenGLRenderer﹕ Enabling debug mode 0 04-24 18:05:51.757 19299-19299/com.example.saurabhb.gettingcolor D/AndroidRuntime﹕ Shutting down VM 04-24 18:05:51.757 19299-19299/com.example.saurabhb.gettingcolor W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x416c82a0) 04-24 18:05:51.847 19299-19299/com.example.saurabhb.gettingcolor E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.NullPointerException at com.example.saurabhb.gettingcolor.AskColorMainActivity$1.onClick(AskColorMainActivity.java:32) at android.view.View.performClick(View.java:4275) at android.view.View$PerformClick.run(View.java:17434) at android.os.Handler.handleCallback(Handler.java:615) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:177) at android.app.ActivityThread.main(ActivityThread.java:4947) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805) at dalvik.system.NativeStart.main(Native Method)