Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my consits of various activity and i used intents to connect them.in one of the activity i have edit text which takes values from user.on the same screen i have a button on clicking that it should perform operation like addition for the entered value.my app works till this activity but on clicking the button it shows unfortunately its stooped.is the problem with the intent or the java code for performing the operation.i have included all the activity in manifest file also.
java code for the operation
Java
package com.example.semester;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Sem1_1 extends Activity {
	EditText s0, s1, s2, s3;

	Button btn1;

	String n0, n1, n2, n3;
	int num0,num1,num2,num3,sum;
	float p;
	String s11,p1,s12;
	

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sem1_1);
		s0 = (EditText) findViewById(R.id.atot1_1);
		s1 = (EditText) findViewById(R.id.m1_1);
		s2 = (EditText) findViewById(R.id.m1_2);
		s3 = (EditText) findViewById(R.id.m1_3);
		btn1 = (Button) findViewById(R.id.send1_1);
		btn1.setOnClickListener(new ButtonClickHandler());

	}

	public class ButtonClickHandler implements View.OnClickListener {
		public void onClick(View view) {
			n0=s0.getText().toString();
			n1=s1.getText().toString();
			n2=s2.getText().toString();
			n3=s3.getText().toString();
			num0=Integer.valueOf(n0).intValue();
			num1=Integer.valueOf(n1).intValue();
			num2=Integer.valueOf(n2).intValue();
			num3=Integer.valueOf(n3).intValue();
			sum=num1+num2+num3;
			p=sum/num0*100;
			s11=Integer.toString(sum);
			s12=Float.toString(p);
			Intent intObj = new Intent(Sem1_1.this, Submit.class);
intObj.putExtra("sum",s11);
intObj.putExtra("percent",p);

			startActivity(intObj);

		}
	}

}


the activity that should be displayed on clicking the button
Java
Submit.java
package com.example.semester;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class Submit extends Activity {
	TextView showResult1, showResult2;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.submit);

		showResult1= (TextView) findViewById(R.id.t1_1);
		showResult1= (TextView) findViewById(R.id.t1_2);
		Intent intename = getIntent();
		String uname = (String) intename.getSerializableExtra("sum");
		String uname1 = (String) intename.getSerializableExtra("percent");

		showResult1.setText("total marks obtained " + uname);
		showResult2.setText("percentage obtained " + uname1);

	}
}
Posted
Updated 6-Oct-15 18:46pm
v2
Comments
Krunal Rohit 7-Oct-15 0:48am    
Can you share your ErrorLog ?

-KR
Member 11993529 7-Oct-15 1:04am    
10-07 01:02:00.410: W/EGL_emulation(2305): eglSurfaceAttrib not implemented
10-07 01:02:00.411: W/OpenGLRenderer(2305): Failed to set EGL_SWAP_BEHAVIOR on surface 0xa24c9520, error=EGL_SUCCESS
10-07 01:02:00.620: D/OpenGLRenderer(2305): endAllStagingAnimators on 0xa251b780 (RippleDrawable) with handle 0xb4308a80
10-07 01:02:01.541: W/EGL_emulation(2305): eglSurfaceAttrib not implemented
10-07 01:02:01.541: W/OpenGLRenderer(2305): Failed to set EGL_SWAP_BEHAVIOR on surface 0xb4302340, error=EGL_SUCCESS
10-07 01:02:11.771: D/AndroidRuntime(2305): Shutting down VM
10-07 01:02:11.773: E/AndroidRuntime(2305): FATAL EXCEPTION: main
10-07 01:02:11.773: E/AndroidRuntime(2305): Process: com.example.semester, PID: 2305
10-07 01:02:11.773: E/AndroidRuntime(2305): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.semester/com.example.semester.Submit}: java.lang.ClassCastException: java.lang.Float cannot be cast to java.lang.String
10-07 01:02:11.773: E/AndroidRuntime(2305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
10-07 01:02:11.773: E/AndroidRuntime(2305): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
10-07 01:02:11.773: E/AndroidRuntime(2305): at android.app.ActivityThread.access$800(ActivityThread.java:151)
10-07 01:02:11.773: E/AndroidRuntime(2305): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
10-07 01:02:11.773: E/AndroidRuntime(2305): at android.os.Handler.dispatchMessage(Handler.java:102)
10-07 01:02:11.773: E/AndroidRuntime(2305): at android.os.Looper.loop(Looper.java:135)
10-07 01:02:11.773: E/AndroidRuntime(2305): at android.app.ActivityThread.main(ActivityThread.java:5254)
10-07 01:02:11.773: E/AndroidRuntime(2305): at java.lang.reflect.Method.invoke(Native Method)
10-07 01:02:11.773: E/AndroidRuntime(2305): at java.lang.reflect.Method.invoke(Method.java:372)
10-07 01:02:11.773: E/AndroidRuntime(2305): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
10-07 01:02:11.773: E/AndroidRuntime(2305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
10-07 01:02:11.773: E/AndroidRuntime(2305): Caused by: java.lang.ClassCastException: java.lang.Float cannot be cast to java.lang.String
10-07 01:02:11.773: E/AndroidRuntime(2305): at com.example.semester.Submit.onCreate(Submit.java:20)
10-07 01:02:11.773: E/AndroidRuntime(2305): at android.app.Activity.performCreate(Activity.java:5990)
10-07 01:02:11.773: E/AndroidRuntime(2305): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
10-07 01:02:11.773: E/AndroidRuntime(2305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
10-07 01:02:11.773: E/AndroidRuntime(2305): ... 10 more
10-07 01:02:14.060: I/Process(2305): Sending signal. PID: 2305 SIG: 9
10-07 01:02:14.376: D/OpenGLRenderer(2378): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
10-07 01:02:14.378: D/(2378): HostConnection::get() New Host Connection established 0xb4308820, tid 2378
10-07 01:02:14.387: D/Atlas(2378): Validating map...
10-07 01:02:14.422: D/libEGL(2378): loaded /system/lib/egl/libEGL_emulation.so
10-07 01:02:14.423: D/libEGL(2378): loaded /system/lib/egl/libGLESv1_CM_emulation.so
10-07 01:02:14.433: D/libEGL(2378): loaded /system/lib/egl/libGLESv2_emulation.so
10-07 01:02:14.441: D/(2378): HostConnection::get() New Host Connection established 0xb43089e0, tid 2397
10-07 01:02:14.459: I/OpenGLRenderer(2378): Initialized EGL, version 1.4
10-07 01:02:14.507: D/OpenGLRenderer(2378): Enabling debug mode 0
10-07 01:02:14.541: W/EGL_emulation(2378): eglSurfaceAttrib not implemented
10-07 01:02:14.541: W/OpenGLRenderer(2378): Failed to set EGL_SWAP_BEHAVIOR on surface 0xb4302760, error=EGL_SUCCESS
10-07 01:02:16.703: W/EGL_emulation(2378): eglSurfaceAttrib not implemented
10-07 01:02:16.703: W/OpenGLRenderer(2378): Failed to set EGL_SWAP_BEHAVIOR on surface 0xb4302dc0, error=EGL_SUCCESS
10-07 01:02

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900