Unable to instantiate activity ComponentInfo starting my app [duplicate] - java

This question already has answers here:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo
(46 answers)
Closed 7 years ago.
i'm getting this error when i launch my app, how can i solve this?
12112-12112/com.javacodegeeks.androidqrcodeexample E/AndroidRuntime﹕
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.javacodegeeks.androidqrcodeexample/com.javacodegeeks.androidqrcodeexample.Login}:
java.lang.NullPointerException
this is my .xml file :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.javacodegeeks.androidqrcodeexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="com.javacodegeeks.androidqrcodeexample.AndroidBarcodeQrExample"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.javacodegeeks.androidqrcodeexample.Login"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
and here my activity :
package com.javacodegeeks.androidqrcodeexample;
/**
* Created by Andre on 14/06/15.
*/
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class Login extends Activity {
EditText username = (EditText)findViewById(R.id.editText);
EditText password = (EditText)findViewById(R.id.editText2);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
public void login(View view) {
if (username.getText().toString().equals("admin") && password.getText().toString().equals("admin")) {
Toast toast = Toast.makeText(this, "CORRECT PW", Toast.LENGTH_LONG);
toast.show();
//correcct password
Intent i = new Intent(getApplicationContext(), AndroidBarcodeQrExample.class);
i.putExtra("Disco", username.getText().toString());
startActivity(i);
} else {
Toast toast = Toast.makeText(this, "UNCORRECT PW", Toast.LENGTH_LONG);
toast.show();
//wrong password
}
}
}

Move lines:
EditText username = (EditText)findViewById(R.id.editText);
EditText password = (EditText)findViewById(R.id.editText2);
inside onCreate
EditText username;
EditText password;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
username = (EditText)findViewById(R.id.editText);
password = (EditText)findViewById(R.id.editText2);
}

Related

My app cannot launch because of my Homepage [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 9 months ago.
My Homepage has a problem, the app failed to start when i run it. but, when i comment out the code on .Homepage in the AndroidManifest the app can run.
Error at Logcat:
2022-05-31 13:28:30.991 5606-5606/com.example.limbangfoodhuntfortourism E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.limbangfoodhuntfortourism, PID: 5606
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.limbangfoodhuntfortourism/com.example.limbangfoodhuntfortourism.Homepage}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageResource(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2951)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3016)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1716)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:232)
at android.app.ActivityThread.main(ActivityThread.java:6806)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1103)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageResource(int)' on a null object reference
at com.example.limbangfoodhuntfortourism.Homepage.onCreate(Homepage.java:24)
at android.app.Activity.performCreate(Activity.java:6974)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2904)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3016) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1716) 
at android.os.Handler.dispatchMessage(Handler.java:110) 
at android.os.Looper.loop(Looper.java:232) 
at android.app.ActivityThread.main(ActivityThread.java:6806) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1103) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) 
this is the error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.limbangfoodhuntfortourism, PID: 27159
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.limbangfoodhuntfortourism/com.example.limbangfoodhuntfortourism.Homepage}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageResource(int)' on a null object reference
This is my Log in code:
package com.example.limbangfoodhuntfortourism;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class Login extends AppCompatActivity {
EditText mEmail, mPassword;
Button mLoginButton;
TextView mCreateLinkSignUp, mForgotPassword;
FirebaseAuth fAuth;
ProgressBar progressBar;
ImageView mLogo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mEmail = findViewById(R.id.email);
mPassword = findViewById(R.id.password);
progressBar = findViewById(R.id.progressBarLogin);
mLoginButton = findViewById(R.id.loginButton);
mCreateLinkSignUp = findViewById(R.id.signUpNow);
mForgotPassword = findViewById(R.id.forgotPassword);
fAuth = FirebaseAuth.getInstance();
mLoginButton.setOnClickListener((view) -> {
String email = mEmail.getText().toString().trim();
String password = mPassword.getText().toString().trim();
if(TextUtils.isEmpty(email)) {
mEmail.setError("Email is Required.");
return;
}
if(TextUtils.isEmpty(password)) {
mPassword.setError("Password is Required.");
return;
}
if(password.length() < 6) {
mPassword.setError("Password must be >= 6 characters");
return;
}
progressBar.setVisibility(View.VISIBLE);
// authenticate the user
fAuth.signInWithEmailAndPassword(email,password).addOnCompleteListener((task) -> {
if(task.isSuccessful()) {
Toast.makeText(Login.this, "Logged in Successfully!", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),Homepage.class));
} else {
Toast.makeText(Login.this, "Error!" + task.getException().getMessage(), Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
});
});
mCreateLinkSignUp.setOnClickListener((view) -> {
startActivity(new Intent(getApplicationContext(), Register.class));
});
mLogo = findViewById(R.id.imageView);
mLogo.setImageResource(R.drawable.main_logo);
mForgotPassword.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final EditText resetMail = new EditText(view.getContext());
final AlertDialog.Builder passwordResetDialog = new AlertDialog.Builder(view.getContext());
passwordResetDialog.setTitle("Reset Password?");
passwordResetDialog.setMessage("Enter Your Email To Received Reset Link.");
passwordResetDialog.setView(resetMail);
passwordResetDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
// extract the mail and send reset link
String mail = resetMail.getText().toString();
fAuth.sendPasswordResetEmail(mail).addOnSuccessListener(new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void unused) {
Toast.makeText(Login.this, "Reset Link Sent To Your Email.", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(Login.this, "Error! Reset Link is Not Sent." + e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
});
passwordResetDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
// close the dialog
}
});
passwordResetDialog.create().show();
}
});
}
}
this is my Homepage:
package com.example.limbangfoodhuntfortourism;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.firebase.auth.FirebaseAuth;
public class Homepage extends AppCompatActivity {
ImageView mLogo;
TextView mLogoutLink;
FirebaseAuth fAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_homepage);
mLogoutLink = findViewById(R.id.Logout);
mLogo = findViewById(R.id.imageView);
mLogo.setImageResource(R.drawable.main_logo);
fAuth = FirebaseAuth.getInstance();
mLogoutLink.setOnClickListener((view) -> {
startActivity(new Intent(getApplicationContext(), Logout.class));
});
}
}
This is my AndroidManifest code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.limbangfoodhuntfortourism">
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.LimbangFoodHuntForTourism"
tools:targetApi="31">
<activity
android:name=".Logout"
android:exported="true" />
<activity
android:name=".RestaurantDetails"
android:exported="true" />
<activity
android:name=".Homepage"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Login"
android:exported="true" />
<activity
android:name=".Register"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="true" />
</application>
</manifest>
try this in your login activity
mLogo = findViewById(R.id.imageView);
mLogo.setImageDrawable(ContextCompat.getDrawable(getActivity(),
R.drawable.main_logo));
lemme know if it works out for you

Moving a file from one computer into other computer

I am a really really new developer. I am currently work a BLE stuff with my friend, but we always have an issue to move my project into his computer, and his project move to my computer.
He does not like to use GitHub at all, me too actually, so we want to just use flash drive to transfer the project folder.(this is the way I found from stackoverflow.com)
I always have errors, and this transfer folder way never work as we respect.
Most of question from "Cannot resolve symbol 'R' such as:
setContentView(R.layout.activity_main);
I already look up online, and most of people just say "clean project", but it does not work at all.
Some of people said, activity_main.xml has problem, but I cant find the problem.
MainActivity.java
package test.research.sjsu.beaconbroadcast;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.bluetooth.le.AdvertiseCallback;
import android.bluetooth.le.AdvertiseData;
import android.bluetooth.le.AdvertiseSettings;
import android.bluetooth.le.BluetoothLeAdvertiser;
import android.content.Context;
import android.os.Bundle;
import android.os.ParcelUuid;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import java.util.UUID;
public class MainActivity extends AppCompatActivity {
BluetoothManager mBluetoothManager;
BluetoothAdapter mBluetoothAdapter;
BluetoothLeAdvertiser mBluetoothLeAdvertiser;
AdvertiseData mAdvertiseData;
AdvertiseData.Builder mAdvertiseDataBuilder = new AdvertiseData.Builder();
byte[] Data = new byte[4];
ParcelUuid mServiceDataUUID;
AdvertiseSettings mAdvertiseSettings;
AdvertiseSettings.Builder mAdvertiseSettingBuilder = new AdvertiseSettings.Builder();
Button BroadcastButton;
Button StopBroadcastButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = mBluetoothManager.getAdapter();
mBluetoothLeAdvertiser = mBluetoothAdapter.getBluetoothLeAdvertiser();
Data = hexStringToByteArray("abcdefgh");
mServiceDataUUID = ParcelUuid.fromString(UUID.randomUUID().toString());
mAdvertiseDataBuilder.setIncludeDeviceName(true);
mAdvertiseDataBuilder.setIncludeTxPowerLevel(true);
mAdvertiseData = mAdvertiseDataBuilder.build();
mAdvertiseDataBuilder.addServiceData(mServiceDataUUID,Data);
mAdvertiseSettingBuilder.setAdvertiseMode(1);
mAdvertiseSettingBuilder.setTimeout(0);
mAdvertiseSettingBuilder.setTxPowerLevel(2);
mAdvertiseSettingBuilder.setConnectable(true);
mAdvertiseSettings = mAdvertiseSettingBuilder.build();
BroadcastButton = (Button) findViewById(R.id.BroadcastButton);
BroadcastButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startAdvertise();
}
});
StopBroadcastButton = (Button) findViewById(R.id.StopBraodcastButton);
StopBroadcastButton.setVisibility(View.INVISIBLE);
StopBroadcastButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
stopAdvertise();
}
});
}
Here is my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.research.sjsu.beaconbroadcast">
android:versionCode="1"
android:versionName="1.0"
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Sometime there are other red lines, but now the R problem just make me crazy.

Unfortunately, app has stopped

Unfortunately, app has stopped. The purpose of the app is to display a web page when it is launched. I have researched this problem, and tried changing code in the manifest file. I have been unsuccessful at eliminating this message.
MainActivity.java
package com.example.testb1;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
import android.net.Uri;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState)
{
Intent getmobilepages = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("http://www.mcohio.org/government/auditor/mobile_app/home.cfm");
getmobilepages.setData(uri);
startActivity(getmobilepages);
}
}
testb1 Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testb1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.testb1.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.getmobilepages" />
</intent-filter>
</activity>
</application>
</manifest>
Edit: I tried running your code and was completely wrong. You are just missing the line:
super.onCreate(savedInstanceState);
At the start of your oncreate method. Add that in and it should compile just fine.
Make sure to post your logcat in the future, the error is identified clearly there.
You have not called super you will get SuperNotCalled Exception. You need to set you layout. Better to start another activity on button click.
Add internet permission in manifest
<uses-permission android:name="android.permission.INTERNET"/>
MainActivty
public class MainActivity extends Activity {
Button b;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// call super
setContentView(R.layout.activity_main);
// set your layout
b = (Button) findViewById(R.id.button1);
//get button id
b.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// do something
Intent getmobilepages = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("http://www.mcohio.org/government/auditor/mobile_app/home.cfm");
getmobilepages.setData(uri);
startActivity(getmobilepages);
}
});
}
}

"No Activity found" error

This is my main page code:
package com.example.splasher;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
public static String text;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
// hide statusbar of Android
// could also be done later
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
EditText field= (EditText) findViewById (R.id.editText1);
field.setOnFocusChangeListener(new OnFocusChangeListener(){
public void onFocusChange(View v, boolean hasFocus){
if (hasFocus) ((EditText)v).selectAll();
}
});
text=field.getText().toString();
try{
startActivity(new Intent("com.example.splasher.View"));
}
catch(ActivityNotFoundException e){
}
}
});
}
}
This is the code of my called activity:
package com.example.splasher;
import android.os.Bundle;
import android.app.Activity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
public class View extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
// hide statusbar of Android
// could also be done later
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
// WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.view);
// TextView textview=(TextView) findViewById (R.id.textView1);
// textview.setText(MainActivity.text);
}}
And this is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.splasher"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".View"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.splasher.View" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I can't work out why I get this error. Any ideas? Names are all the same and with same upper, lower case letters. They are all described in manifest as well.
In your manifest, type the activity action in caps.
< action android:name="COM.EXAMPLE.SPLASHER.VIEW" / >
this is done for all activities except for the main activity
There is MainActivity.this.startActivity(new Intent(MainActivity.this, Views.class)); Views class with 's' !
there is no need of the intent filter which you have applied in the View activity..Just keep one intent filter in your MainActivity
Replace the start activity line code with following:
startActivity(new Intent(MainActivity.this,View.class));
Try to replace your startActivity call by MainActivity.this.startActivity in your MainActivity.
I think there is a scope trouble.

error in xml parsing

i built a code that switch from one activity to another.
when run this code it prints following errors.
Error in an XML file: aborting build.
and
Installation error: INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID
here is my xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="wishme.code"
android:versionCode="1"
android:versionName="1.0" android:sharedUserId="#string/app_name">
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".WishMeActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity2"></activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
here is activity 1
package wishme.code;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Contacts.Intents;
import android.widget.TextView;
import android.view.View;
import android.widget.EditText;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Toast;
public class WishMeActivity extends Activity {
private EditText text;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text=(EditText) findViewById(R.id.editText1);
}
public void myClickhandler(View view)
{
switch(view.getId())
{
case R.id.button1:
RadioButton celsiusbutton=(RadioButton) findViewById(R.id.radio0);
RadioButton fahrenheit=(RadioButton) findViewById(R.id.radio2);
if(text.getText().length()==0)
{
Toast.makeText(this,"Enter a Valid Value",Toast.LENGTH_LONG).show();
return;
}
float input=Float.parseFloat(text.getText().toString());
if(celsiusbutton.isChecked())
{text.setText(String.valueOf(convertFahrenheitToCelsius(input)));
celsiusbutton.setChecked(false);
fahrenheit.setChecked(true);}
else
{
text.setText(String.valueOf(convertCelsiusToFahrenheit(input)));
fahrenheit.setChecked(false);
celsiusbutton.setChecked(true);
}
break;
case R.id.button_nxt:
Intent myintent=new Intent(view.getContext(),Activity2.class);
startActivityForResult(myintent, 0);
break;
}
}
private float convertFahrenheitToCelsius(float fahrenheit) {
return ((fahrenheit - 32) * 5 / 9);
}
// Converts to fahrenheit
private float convertCelsiusToFahrenheit(float celsius) {
return ((celsius * 9) / 5) + 32;
}
}
and finally this is activity 2
package wishme.code;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Activity2 extends Activity{
public void onCreate(Bundle savedInstancestate) {
super.onCreate(savedInstancestate);
setContentView(R.layout.main2);
Button previous=(Button) findViewById(R.id.button_prev);
}
public void prevclickhandler(View view)
{
Intent intent=new Intent();
setResult(RESULT_OK,intent);
finish();
}
}
please suggest me the solution.
I you just want to go from one activity to another, then you dont need to give the sharedUserID. Its used in cases where you have two different applications that are signed with same certificate and you want to share data between them or you want them to run in the same process.
If you remove it, it should solve your problem.
For information about sharedUserID: http://developer.android.com/guide/topics/manifest/manifest-element.html#uid
This may be due to your sharedUserId value being of a non-permitted value. It has to have the same format as the package structure (e.g. com.android).

Categories