TextView is not working well - java

I did this TextView in activity_main.XML that shows a variable. but every time i enter the application its crash.
here is the xml file:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.crosser.MainActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Score:"
android:textAppearance="?android:attr/textAppearanceLarge" />
</FrameLayout>
and here is the MainActivity:
TextView myText = (TextView) findViewById(R.id.textView1);
myText.setText("Score:" + result.score);
and here is the Log from logcat
04-01 10:14:01.990: E/AndroidRuntime(925): FATAL EXCEPTION: main
04-01 10:14:01.990: E/AndroidRuntime(925): Process: com.example.crosser, PID: 925
04-01 10:14:01.990: E/AndroidRuntime(925): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.crosser/com.example.crosser.MainActivity}: java.lang.NullPointerException
04-01 10:14:01.990: E/AndroidRuntime(925): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
04-01 10:14:01.990: E/AndroidRuntime(925): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-01 10:14:01.990: E/AndroidRuntime(925): at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-01 10:14:01.990: E/AndroidRuntime(925): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-01 10:14:01.990: E/AndroidRuntime(925): at android.os.Handler.dispatchMessage(Handler.java:102)
04-01 10:14:01.990: E/AndroidRuntime(925): at android.os.Looper.loop(Looper.java:136)
04-01 10:14:01.990: E/AndroidRuntime(925): at android.app.ActivityThread.main(ActivityThread.java:5017)
04-01 10:14:01.990: E/AndroidRuntime(925): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 10:14:01.990: E/AndroidRuntime(925): at java.lang.reflect.Method.invoke(Method.java:515)
04-01 10:14:01.990: E/AndroidRuntime(925): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-01 10:14:01.990: E/AndroidRuntime(925): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-01 10:14:01.990: E/AndroidRuntime(925): at dalvik.system.NativeStart.main(Native Method)
04-01 10:14:01.990: E/AndroidRuntime(925): Caused by: java.lang.NullPointerException
04-01 10:14:01.990: E/AndroidRuntime(925): at com.example.crosser.MainActivity.onCreate(MainActivity.java:55)
04-01 10:14:01.990: E/AndroidRuntime(925): at android.app.Activity.performCreate(Activity.java:5231)
04-01 10:14:01.990: E/AndroidRuntime(925): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-01 10:14:01.990: E/AndroidRuntime(925): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
04-01 10:14:01.990: E/AndroidRuntime(925): ... 11 more
Line 55 in Main Activity is that:
myText.setText("Score:" + result.score);
Result is a class that stores the score which is a public variable.
I got this lines that make score be 0 from start and not null.
int score = 0;
Results result = new Results(score);
and this is bassicly the main code in my Main Activity:
Car car = new Car( screenWidth/2 , screenHeigh/2 , 15 , screenHeigh, screenWidth);
Person person = new Person( 0 , screenHeigh/2 , 10 , 20 , screenWidth,screenHeigh);
CarView carview = new CarView(this, car);
PersonView personview = new PersonView(this, person);
GameView gameview = new GameView(this);
gameview.setViews(carview, personview);
setContentView(gameview);
CarMover moveCar = new CarMover(car,gameview);
PersonMover movePerson = new PersonMover(person, gameview, result, car);

Your result variable is probably null, so calling result.score would cause a NullPointerException.
You also need to make sure you call setContentView before using findViewById, otherwise myText may be null.

Related

Passing Integer Values Between Activities - Android

Other stuck posts unfortunately couldn't help me.
When I clicked button while easy radiobutton is checked, the app stops working. I couldn't go and see another activity.
Sender Side:
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if(radiobutton_arm_triceps_easy.isChecked()) {
String dene = "my example test";
int myValue=2;
Intent intent = new Intent(getApplicationContext(), exercise_arm_triceps_execute.class);
intent.putExtra("attempt1", myValue );
startActivity(intent);
}
}
});
Receiver Side:
int receiveValue=getIntent().getIntExtra("attempt1",0);
textshow.setText(receiveValue);
LOGCAT
04-26 16:52:06.320 31527-31527/com.example.kerem.tutorial_project E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.kerem.tutorial_project, PID: 31527
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.kerem.tutorial_project/com.example.kerem.tutorial_project.exercise_arm_triceps_execute}: android.content.res.Resources$NotFoundException: String resource ID #0x2
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2
at android.content.res.Resources.getText(Resources.java:244)
at android.support.v7.widget.ResourcesWrapper.getText(ResourcesWrapper.java:52)
at android.widget.TextView.setText(TextView.java:3888)
at com.example.kerem.tutorial_project.exercise_arm_triceps_execute.onCreate(exercise_arm_triceps_execute.java:28)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Use
textshow.setText(String.valueOf(receiveValue));

How to check if checkbox was checked?

I am creating a quiz app for androids. I have 3 fragments and 3 checkboxes on first two of them. On the last fragment there is a button which when pressed opens an activity called "End". I need that on the "End" activity a result would appear of how many correct answers one have chosen.
Firstly, I've tried to check if it's working with only the first fragment, but I got stuck. The app closes when I press the button.
End.java:
package bandymas.viewpagerexample;
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.CheckBox;
import android.widget.TextView;
public class End extends ActionBarActivity {
private CheckBox checkBox1, checkBox2, checkBox3;
private Button button;
TextView newresult = (TextView)findViewById(R.id.textView1);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_end);
getSupportActionBar().hide();
addListenerOnButton();
}
private void addListenerOnButton() {
checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
checkBox3 = (CheckBox) findViewById(R.id.checkBox3);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
//Run when button is clicked
#Override
public void onClick(View v) {
StringBuffer result = new StringBuffer();
result.append("CheckBox1 : ").append(checkBox1.isChecked());
result.append("\nCheckbox2 : ").append(checkBox2.isChecked());
result.append("\nCheckBox3 :").append(checkBox3.isChecked());
newresult.setText("My Awesome Text");
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_naujas_baigimas, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here's my logcat:
04-01 20:04:37.564 6020-6020/bandymas.viewpagerexample W/ApplicationPackageManager﹕ getCSCPackageItemText()
04-01 20:04:37.564 6020-6020/bandymas.viewpagerexample I/PersonaManager﹕ getPersonaService() name persona_policy
04-01 20:04:37.684 6020-6020/bandymas.viewpagerexample I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: (CL3869936)
OpenGL ES Shader Compiler Version: 17.01.11.SPL
Build Date: 01/17/14 Fri
Local Branch:
Remote Branch:
Local Patches:
Reconstruct Branch:
04-01 20:04:37.734 6020-6020/bandymas.viewpagerexample D/OpenGLRenderer﹕ Enabling debug mode 0
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample I/SELinux﹕ Function: selinux_android_load_priority [0], There is no sepolicy file.
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample I/SELinux﹕ Function: selinux_android_load_priority , priority version is VE=SEPF_GT-I9505_4.4.2_0033
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample I/SELinux﹕ selinux_android_seapp_context_reload: seapp_contexts file is loaded from /seapp_contexts
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample E/dalvikvm﹕ >>>>> Normal User
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample E/dalvikvm﹕ >>>>> bandymas.viewpagerexample [ userId:0 | appId:10229 ]
04-01 20:07:31.404 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ Late-enabling CheckJNI
04-01 20:07:31.584 7094-7094/bandymas.viewpagerexample W/ApplicationPackageManager﹕ getCSCPackageItemText()
04-01 20:07:31.594 7094-7094/bandymas.viewpagerexample I/PersonaManager﹕ getPersonaService() name persona_policy
04-01 20:07:31.794 7094-7094/bandymas.viewpagerexample I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:381>: EGL 1.4 QUALCOMM build: (CL3869936)
OpenGL ES Shader Compiler Version: 17.01.11.SPL
Build Date: 01/17/14 Fri
Local Branch:
Remote Branch:
Local Patches:
Reconstruct Branch:
04-01 20:07:31.844 7094-7094/bandymas.viewpagerexample D/OpenGLRenderer﹕ Enabling debug mode 0
04-01 20:07:42.454 7094-7094/bandymas.viewpagerexample W/ApplicationPackageManager﹕ getCSCPackageItemText()
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 11347: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 11353: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6f at 0x0000
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 9041: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
04-01 20:07:42.485 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 365: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ VFY: unable to resolve virtual method 387: Landroid/content/res/TypedArray;.getType (I)I
04-01 20:07:42.495 7094-7094/bandymas.viewpagerexample D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
04-01 20:07:42.525 7094-7094/bandymas.viewpagerexample D/AndroidRuntime﹕ Shutting down VM
04-01 20:07:42.525 7094-7094/bandymas.viewpagerexample W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4187fda0)
04-01 20:07:42.525 7094-7094/bandymas.viewpagerexample E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: bandymas.viewpagerexample, PID: 7094
java.lang.RuntimeException: Unable to start activity ComponentInfo{bandymas.viewpagerexample/bandymas.viewpagerexample.End}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
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:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at bandymas.viewpagerexample.End.addListenerOnButton(End.java:33)
at bandymas.viewpagerexample.End.onCreate(End.java:23)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
            at android.app.ActivityThread.access$900(ActivityThread.java:161)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:157)
            at android.app.ActivityThread.main(ActivityThread.java:5356)
            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:1265)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
            at dalvik.system.NativeStart.main(Native Method)
activity_end.xml:
<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="bandymas.viewpagerexample.End">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Result"
android:id="#+id/textView1"
android:layout_marginTop="100dp"
android:textSize="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Please Check that there is the button(R.id.button) in activity_end.xml.
I guess that the button's id doesn't exist in activity_end.xml.

Android NumberPicker NullPointer why?

i am try to implement a numberPicker to select minute values.
But i am getting a NullPointer Exception at this line:
minutePicker = (NumberPicker) findViewById(R.id.minuten_picker);
Following Code:
public class MainActivity extends Activity {
NumberPicker minutePicker;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Auswahl Minuten zum starten / Stoppen aller
minutePicker = new NumberPicker(MainActivity.this);
minutePicker = (NumberPicker) findViewById(R.id.minuten_picker);
minutePicker.setMaxValue(30);
minutePicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
#Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
abschaltzeit = minutePicker.getValue();
}
});
minutePicker.setValue(0);
minutePicker.setWrapSelectorWheel(false);
}
}
XML:
<NumberPicker
android:id="#+id/minuten_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="6"
android:layout_column="0"
android:paddingLeft="20dp" />
Log:
09-25 11:00:09.749 10687-10687/de.carsten.awesome.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: de.carsten.awesome.app, PID: 10687
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.carsten.awesome.app/de.carsten.awesome.app.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at de.carsten.awesome.app.MainActivity.onCreate(MainActivity.java:83)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
minutePicker = new NumberPicker(MainActivity.this);
minutePicker = (NumberPicker) findViewById(R.id.minuten_picker);
You're creating a NumberPicker programmatically and then overwriting the reference with whatever findViewById() returns. It returns null if your activity_main layout does not contain a minuten_picker.
Choose only the other: either create it prorgrammatically or find it from a view hierarchy you inflated.
If you choose the programmatic way new NumberPicker(), remember to add it to some layout in your activity view hierarchy, e.g. with setContentView()
If you choose the inflation way, make sure you have the view in your XML layout file.
I'm guessing the NPE you're seeing is actually on the following line where you're trying to invoke a method on the minutePicker and it's null.
I apologize.
I moved the Code from the MainActivity in the creating Fragment and it works with rootView.findView.
Sorry but i am new with the Fragement Konzept.
Thanks a lot for your help !

Android Calculator Bug

I coded a calculator for Android, but when I press the "equals" button while the app is running in the emulator, an error comes in the LogCat and the app closes.
Please help me fix the error.
Here's the LogCat Output:
07-25 01:34:13.213: I/Choreographer(1387): Skipped 39 frames! The application may be doing too much work on its main thread.
07-25 01:34:13.473: D/gralloc_goldfish(1387): Emulator without GPU emulation detected.
07-25 01:34:50.653: I/Choreographer(1387): Skipped 36 frames! The application may be doing too much work on its main thread.
07-25 01:34:52.973: D/AndroidRuntime(1387): Shutting down VM
07-25 01:34:52.973: W/dalvikvm(1387): threadid=1: thread exiting with uncaught exception (group=0xb3ab0ba8)
07-25 01:34:53.103: E/AndroidRuntime(1387): FATAL EXCEPTION: main
07-25 01:34:53.103: E/AndroidRuntime(1387): Process: com.example.owncode, PID: 1387
07-25 01:34:53.103: E/AndroidRuntime(1387): java.lang.IllegalStateException: Could not find a method Sum(View) in the activity class com.example.owncode.MainActivity for onClick handler on view class android.widget.Button with id 'button_calculate'
07-25 01:34:53.103: E/AndroidRuntime(1387): at android.view.View$1.onClick(View.java:3810)
07-25 01:34:53.103: E/AndroidRuntime(1387): at android.view.View.performClick(View.java:4438)
07-25 01:34:53.103: E/AndroidRuntime(1387): at android.view.View$PerformClick.run(View.java:18422)
07-25 01:34:53.103: E/AndroidRuntime(1387): at android.os.Handler.handleCallback(Handler.java:733)
07-25 01:34:53.103: E/AndroidRuntime(1387): at android.os.Handler.dispatchMessage(Handler.java:95)
07-25 01:34:53.103: E/AndroidRuntime(1387): at android.os.Looper.loop(Looper.java:136)
07-25 01:34:53.103: E/AndroidRuntime(1387): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-25 01:34:53.103: E/AndroidRuntime(1387): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 01:34:53.103: E/AndroidRuntime(1387): at java.lang.reflect.Method.invoke(Method.java:515)
07-25 01:34:53.103: E/AndroidRuntime(1387): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-25 01:34:53.103: E/AndroidRuntime(1387): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-25 01:34:53.103: E/AndroidRuntime(1387): at dalvik.system.NativeStart.main(Native Method)
07-25 01:34:53.103: E/AndroidRuntime(1387): Caused by: java.lang.NoSuchMethodException: Sum [class android.view.View]
07-25 01:34:53.103: E/AndroidRuntime(1387): at java.lang.Class.getConstructorOrMethod(Class.java:472)
07-25 01:34:53.103: E/AndroidRuntime(1387): at java.lang.Class.getMethod(Class.java:857)
07-25 01:34:53.103: E/AndroidRuntime(1387): at android.view.View$1.onClick(View.java:3803)
07-25 01:34:53.103: E/AndroidRuntime(1387): ... 11 more
07-25 01:36:28.423: I/Choreographer(1452): Skipped 52 frames! The application may be doing too much work on its main thread.
07-25 01:36:28.753: D/gralloc_goldfish(1452): Emulator without GPU emulation detected.
07-25 01:36:32.873: I/Choreographer(1452): Skipped 39 frames! The application may be doing too much work on its main thread.
07-25 01:36:35.713: W/ResourceType(1452): No package identifier when getting value for resource number 0x00000009
07-25 01:36:35.723: D/AndroidRuntime(1452): Shutting down VM
07-25 01:36:35.723: W/dalvikvm(1452): threadid=1: thread exiting with uncaught exception (group=0xb3ab0ba8)
07-25 01:36:36.103: E/AndroidRuntime(1452): FATAL EXCEPTION: main
07-25 01:36:36.103: E/AndroidRuntime(1452): Process: com.example.owncode, PID: 1452
07-25 01:36:36.103: E/AndroidRuntime(1452): java.lang.IllegalStateException: Could not execute method of the activity
07-25 01:36:36.103: E/AndroidRuntime(1452): at android.view.View$1.onClick(View.java:3823)
07-25 01:36:36.103: E/AndroidRuntime(1452): at android.view.View.performClick(View.java:4438)
07-25 01:36:36.103: E/AndroidRuntime(1452): at android.view.View$PerformClick.run(View.java:18422)
07-25 01:36:36.103: E/AndroidRuntime(1452): at android.os.Handler.handleCallback(Handler.java:733)
07-25 01:36:36.103: E/AndroidRuntime(1452): at android.os.Handler.dispatchMessage(Handler.java:95)
07-25 01:36:36.103: E/AndroidRuntime(1452): at android.os.Looper.loop(Looper.java:136)
07-25 01:36:36.103: E/AndroidRuntime(1452): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-25 01:36:36.103: E/AndroidRuntime(1452): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 01:36:36.103: E/AndroidRuntime(1452): at java.lang.reflect.Method.invoke(Method.java:515)
07-25 01:36:36.103: E/AndroidRuntime(1452): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-25 01:36:36.103: E/AndroidRuntime(1452): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-25 01:36:36.103: E/AndroidRuntime(1452): at dalvik.system.NativeStart.main(Native Method)
07-25 01:36:36.103: E/AndroidRuntime(1452): Caused by: java.lang.reflect.InvocationTargetException
07-25 01:36:36.103: E/AndroidRuntime(1452): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 01:36:36.103: E/AndroidRuntime(1452): at java.lang.reflect.Method.invoke(Method.java:515)
07-25 01:36:36.103: E/AndroidRuntime(1452): at android.view.View$1.onClick(View.java:3818)
07-25 01:36:36.103: E/AndroidRuntime(1452): ... 11 more
07-25 01:36:36.103: E/AndroidRuntime(1452): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x9
07-25 01:36:36.103: E/AndroidRuntime(1452): at android.content.res.Resources.getText(Resources.java:244)
07-25 01:36:36.103: E/AndroidRuntime(1452): at android.widget.TextView.setText(TextView.java:3888)
07-25 01:36:36.103: E/AndroidRuntime(1452): at com.example.owncode.MainActivity.Sum(MainActivity.java:113)
07-25 01:36:36.103: E/AndroidRuntime(1452): ... 14 more
07-25 01:39:31.103: I/Choreographer(1502): Skipped 47 frames! The application may be doing too much work on its main thread.
07-25 01:39:31.383: D/gralloc_goldfish(1502): Emulator without GPU emulation detected.
07-25 01:39:35.203: I/Choreographer(1502): Skipped 42 frames! The application may be doing too much work on its main thread.
07-25 01:39:38.363: W/ResourceType(1502): No package identifier when getting value for resource number 0x00000009
07-25 01:39:38.423: D/AndroidRuntime(1502): Shutting down VM
07-25 01:39:38.423: W/dalvikvm(1502): threadid=1: thread exiting with uncaught exception (group=0xb3ab0ba8)
07-25 01:39:38.603: E/AndroidRuntime(1502): FATAL EXCEPTION: main
07-25 01:39:38.603: E/AndroidRuntime(1502): Process: com.example.owncode, PID: 1502
07-25 01:39:38.603: E/AndroidRuntime(1502): java.lang.IllegalStateException: Could not execute method of the activity
07-25 01:39:38.603: E/AndroidRuntime(1502): at android.view.View$1.onClick(View.java:3823)
07-25 01:39:38.603: E/AndroidRuntime(1502): at android.view.View.performClick(View.java:4438)
07-25 01:39:38.603: E/AndroidRuntime(1502): at android.view.View$PerformClick.run(View.java:18422)
07-25 01:39:38.603: E/AndroidRuntime(1502): at android.os.Handler.handleCallback(Handler.java:733)
07-25 01:39:38.603: E/AndroidRuntime(1502): at android.os.Handler.dispatchMessage(Handler.java:95)
07-25 01:39:38.603: E/AndroidRuntime(1502): at android.os.Looper.loop(Looper.java:136)
07-25 01:39:38.603: E/AndroidRuntime(1502): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-25 01:39:38.603: E/AndroidRuntime(1502): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 01:39:38.603: E/AndroidRuntime(1502): at java.lang.reflect.Method.invoke(Method.java:515)
07-25 01:39:38.603: E/AndroidRuntime(1502): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-25 01:39:38.603: E/AndroidRuntime(1502): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-25 01:39:38.603: E/AndroidRuntime(1502): at dalvik.system.NativeStart.main(Native Method)
07-25 01:39:38.603: E/AndroidRuntime(1502): Caused by: java.lang.reflect.InvocationTargetException
07-25 01:39:38.603: E/AndroidRuntime(1502): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 01:39:38.603: E/AndroidRuntime(1502): at java.lang.reflect.Method.invoke(Method.java:515)
07-25 01:39:38.603: E/AndroidRuntime(1502): at android.view.View$1.onClick(View.java:3818)
07-25 01:39:38.603: E/AndroidRuntime(1502): ... 11 more
07-25 01:39:38.603: E/AndroidRuntime(1502): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x9
07-25 01:39:38.603: E/AndroidRuntime(1502): at android.content.res.Resources.getText(Resources.java:244)
07-25 01:39:38.603: E/AndroidRuntime(1502): at android.widget.TextView.setText(TextView.java:3888)
07-25 01:39:38.603: E/AndroidRuntime(1502): at com.example.owncode.MainActivity.Sum(MainActivity.java:113)
07-25 01:39:38.603: E/AndroidRuntime(1502): ... 14 more
Here's my MainActivity.JAVA:
package com.example.owncode;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends Activity {
EditText calculatorText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
calculatorText = (EditText) findViewById(R.id.calculatorText);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
/*getMenuInflater().inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);*/
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.button_quitProgram) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void button_one_click(View view){
calculatorText.append("1");
}
public void button_two_click(View view){
calculatorText.append("2");
}
public void button_three_click(View view){
calculatorText.append("3");
}
public void button_four_click(View view){
calculatorText.append("4");
}
public void button_five_click(View view){
calculatorText.append("5");
}
public void button_six_click(View view){
calculatorText.append("6");
}
public void button_seven_click(View view){
calculatorText.append("7");
}
public void button_eight_click(View view){
calculatorText.append("8");
}
public void button_nine_click(View view){
calculatorText.append("9");
}
public void button_zero_click(View view){
calculatorText.append("0");
}
public void button_plus_click(View view){
calculatorText.append("+");
}
public void button_minus_click(View view){
calculatorText.append("-");
}
public void button_backspace_click(View view){
if (calculatorText.length()>0){
String calculatorText_text = calculatorText.getText().toString();
calculatorText_text = calculatorText_text.substring(0, calculatorText_text.length()-1);
calculatorText.setText(calculatorText_text);
}
}
public void Sum(View view){
String str = calculatorText.getText().toString();
int len = str.length();
int i=0;
String str1 = "", str2 = "";
char op;
int num1 = 0, num2 = 0, res=0;
for(i=0; i<len; i++){
if(str.charAt(i)=='+' || str.charAt(i)=='-')
break;
str1 = str1 + str.charAt(i);
}
op = str.charAt(i);
i++;
while(i<len){
str2 = str2 + str.charAt(i);
i++;
}
num1 = Integer.parseInt(str1);
num2 = Integer.parseInt(str2);
if(op=='+')
res = num1+num2;
else if(op=='-')
res = num1-num2;
calculatorText.setText(res);
}
}
And, here's my main_activity.xml:
<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:orientation="horizontal" >
<Button
android:id="#+id/button_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button_minus"
android:layout_alignBottom="#+id/button_minus"
android:layout_alignParentLeft="true"
android:hint="#string/button_plus"
android:onClick="button_plus_click" />
<Button
android:id="#+id/button_zero"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button_plus"
android:layout_alignBottom="#+id/button_plus"
android:layout_toRightOf="#+id/button_plus"
android:hint="#string/button_zero"
android:onClick="button_zero_click" />
<Button
android:id="#+id/button_minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="135dp"
android:hint="#string/button_minus"
android:onClick="button_minus_click" />
<Button
android:id="#+id/button_nine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button_minus"
android:layout_alignLeft="#+id/button_minus"
android:hint="#string/button_nine"
android:onClick="button_nine_click" />
<Button
android:id="#+id/button_eight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button_zero"
android:layout_toLeftOf="#+id/button_minus"
android:hint="#string/button_eight"
android:onClick="button_eight_click" />
<Button
android:id="#+id/button_seven"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button_eight"
android:layout_alignBottom="#+id/button_eight"
android:layout_toLeftOf="#+id/button_eight"
android:hint="#string/button_seven"
android:onClick="button_seven_click" />
<Button
android:id="#+id/button_six"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button_nine"
android:layout_toRightOf="#+id/button_eight"
android:hint="#string/button_six"
android:onClick="button_six_click" />
<Button
android:id="#+id/button_five"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button_six"
android:layout_alignBottom="#+id/button_six"
android:layout_toRightOf="#+id/button_seven"
android:hint="#string/button_five"
android:onClick="button_five_click" />
<Button
android:id="#+id/button_four"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button_five"
android:layout_alignBottom="#+id/button_five"
android:layout_toLeftOf="#+id/button_five"
android:hint="#string/button_four"
android:onClick="button_four_click" />
<Button
android:id="#+id/button_three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button_six"
android:layout_toRightOf="#+id/button_five"
android:hint="#string/button_three"
android:onClick="button_three_click" />
<Button
android:id="#+id/button_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button_three"
android:layout_alignBottom="#+id/button_three"
android:layout_toRightOf="#+id/button_four"
android:hint="#string/button_two"
android:onClick="button_two_click" />
<Button
android:id="#+id/button_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button_two"
android:layout_alignBottom="#+id/button_two"
android:layout_toLeftOf="#+id/button_two"
android:hint="#string/button_one"
android:onClick="button_one_click" />
<Button
android:id="#+id/button_backspace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button_three"
android:layout_marginBottom="29dp"
android:layout_marginLeft="17dp"
android:layout_toRightOf="#+id/calculatorText"
android:hint="#string/button_backspace"
android:onClick="button_backspace_click" />
<Button
android:id="#+id/button_calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button_backspace"
android:layout_alignLeft="#+id/button_backspace"
android:hint="#string/button_calculate"
android:onClick="Sum" />
<EditText
android:id="#+id/calculatorText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button_backspace"
android:layout_alignParentLeft="true"
android:editable="false"
android:ems="10"
android:hint="#string/calculatorText_text" >
<requestFocus />
</EditText>
</RelativeLayout>
I know it's all simple code but this is my first app and please help me so that I can get it running on a few of my relatives' devices.
Because of this line you are getting error
calculatorText.setText(res);
change it into
calculatorText.setText(""+res);
You are setting Integer value..so View taken it as a Resouce ID.
Change calculatorText.setText(res); to calculatorText.setText(Integer.toString(res));
You cannot set an integer value to an EditText.

Android application keep crashing

in the last few days I tried to develop android applications with no success, for some reason my application keep crashing.
the application keeps throwing few exceptions that I didn't succeeded to handle with.
MainActivity.java :
package com.mobIce.digicoin.digitalcoin;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends ActionBarActivity {
private List<Coin> coins;
public MainActivity(){
coins = new ArrayList<Coin>();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
populateCoins();
populateListView();
}
}
private void populateCoins() {
coins.add(new Coin("Bitcoin", "650", "4", "http://coinmarketcap.com/img/Bitcoin.png"));
coins.add(new Coin("Dogecoin", "100", "400", "http://coinmarketcap.com/img/Bitcoin.png"));
coins.add(new Coin("fafaf", "8065", "400", "http://coinmarketcap.com/img/Bitcoin.png"));
}
private void populateListView() {
ArrayAdapter<Coin> adapter = new MyListAdapter();
ListView list = (ListView) findViewById(R.id.coinsListView);
list.setAdapter(adapter);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
private class MyListAdapter extends ArrayAdapter<Coin> {
public MyListAdapter()
{
super(MainActivity.this, R.layout.coin_layout, coins);
}
#Override
public View getView(int position, View convertView, ViewGroup parent){
View itemView = convertView;
if(itemView == null)
itemView = getLayoutInflater().inflate(R.layout.coin_layout, parent, false);
//find the coin to work with.
Coin currentCoin = coins.get(position);
//fill the view
try{
TextView coinName = (TextView) itemView.findViewById(R.id.coinName);
coinName.setText(currentCoin.getName());
TextView coinPrice = (TextView) itemView.findViewById(R.id.coinPrice);
coinPrice.setText(currentCoin.getPrice());
TextView coinPercentage = (TextView) itemView.findViewById(R.id.coinPercentage);
coinPercentage.setText(currentCoin.getPercentage());
}
catch (NullPointerException e){ }
return itemView;
}
}
}
activity_main.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mobIce.digicoin.digitalcoin.MainActivity"
tools:ignore="MergeRootFrame" />
fragment_main.xml:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/coinsListView"
android:paddingLeft="30dp" />
</LinearLayout>
coin_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="coinName"
android:id="#+id/coinName"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/coinIcon"
android:layout_marginTop="35dp"
android:layout_marginLeft="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/coinIcon"
android:maxHeight="80dp"
android:maxWidth="80dp"
android:minHeight="80dp"
android:minWidth="80dp"
android:src="#drawable/dogecoin"
android:longClickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:baselineAlignBottom="false"
android:clickable="false"
android:adjustViewBounds="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/coinPrice"
android:layout_marginLeft="35dp"
android:layout_alignTop="#+id/coinIcon"
android:layout_toRightOf="#+id/coinName"
android:layout_marginTop="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/coinPercentage"
android:layout_below="#+id/coinPrice"
android:layout_alignLeft="#+id/coinPrice"
android:layout_alignStart="#+id/coinPrice" />
</RelativeLayout>
logcat trace:
03-17 08:59:33.977 1107-1107/com.mobIce.digicoin.digitalcoin D/AndroidRuntime﹕ Shutting down VM
03-17 08:59:33.977 1107-1107/com.mobIce.digicoin.digitalcoin W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb1a38ba8)
03-17 08:59:33.987 1107-1107/com.mobIce.digicoin.digitalcoin E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.mobIce.digicoin.digitalcoin, PID: 1107
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobIce.digicoin.digitalcoin/com.mobIce.digicoin.digitalcoin.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.mobIce.digicoin.digitalcoin.MainActivity.populateListView(MainActivity.java:47)
at com.mobIce.digicoin.digitalcoin.MainActivity.onCreate(MainActivity.java:36)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            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:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
03-17 09:04:09.857 1149-1149/com.mobIce.digicoin.digitalcoin D/AndroidRuntime﹕ Shutting down VM
03-17 09:04:09.857 1149-1149/com.mobIce.digicoin.digitalcoin W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb1a38ba8)
03-17 09:04:09.867 1149-1149/com.mobIce.digicoin.digitalcoin E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.mobIce.digicoin.digitalcoin, PID: 1149
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobIce.digicoin.digitalcoin/com.mobIce.digicoin.digitalcoin.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.mobIce.digicoin.digitalcoin.MainActivity.populateListView(MainActivity.java:50)
at com.mobIce.digicoin.digitalcoin.MainActivity.onCreate(MainActivity.java:39)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            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:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
03-17 09:06:36.697 1192-1192/com.mobIce.digicoin.digitalcoin D/AndroidRuntime﹕ Shutting down VM
03-17 09:06:36.697 1192-1192/com.mobIce.digicoin.digitalcoin W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb1a38ba8)
03-17 09:06:36.717 1192-1192/com.mobIce.digicoin.digitalcoin E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.mobIce.digicoin.digitalcoin, PID: 1192
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobIce.digicoin.digitalcoin/com.mobIce.digicoin.digitalcoin.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.mobIce.digicoin.digitalcoin.MainActivity.populateListView(MainActivity.java:50)
at com.mobIce.digicoin.digitalcoin.MainActivity.onCreate(MainActivity.java:39)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            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:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
03-17 09:13:38.647 1239-1239/com.mobIce.digicoin.digitalcoin D/AndroidRuntime﹕ Shutting down VM
03-17 09:13:38.647 1239-1239/com.mobIce.digicoin.digitalcoin W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb1a38ba8)
03-17 09:13:38.747 1239-1239/com.mobIce.digicoin.digitalcoin E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.mobIce.digicoin.digitalcoin, PID: 1239
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobIce.digicoin.digitalcoin/com.mobIce.digicoin.digitalcoin.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.mobIce.digicoin.digitalcoin.MainActivity.populateListView(MainActivity.java:50)
at com.mobIce.digicoin.digitalcoin.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            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:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
03-17 09:13:45.127 1239-1239/com.mobIce.digicoin.digitalcoin I/Process﹕ Sending signal. PID: 1239 SIG: 9
03-17 09:19:34.847 1285-1285/com.mobIce.digicoin.digitalcoin D/AndroidRuntime﹕ Shutting down VM
03-17 09:19:34.847 1285-1285/com.mobIce.digicoin.digitalcoin W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb1a38ba8)
03-17 09:19:34.857 1285-1285/com.mobIce.digicoin.digitalcoin E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.mobIce.digicoin.digitalcoin, PID: 1285
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobIce.digicoin.digitalcoin/com.mobIce.digicoin.digitalcoin.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.mobIce.digicoin.digitalcoin.MainActivity.populateListView(MainActivity.java:50)
at com.mobIce.digicoin.digitalcoin.MainActivity.onCreate(MainActivity.java:37)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            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:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
03-17 09:20:11.987 1285-1285/com.mobIce.digicoin.digitalcoin I/Process﹕ Sending signal. PID: 1285 SIG: 9
Your coinsListView is in the fragment layout and not in activity layout. You cannot access it with findViewById() in populateListView() called from activity onCreate(). Instead, move the list view population to the fragment's onCreateView() after the inflation, calling findViewById() on the rootView layout you just inflated.

Categories