Unable to find explicit activity class java - java

i am a new app developer i was working on a app for the past few days i have implemented onclicklistner in my program then the error shows like this.i have been working on a cardview project please help me from this and i am using new version of andriod.
thank you
this is my Main activity:
package com.example.login;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.os.Handler;
import android.os.Handler;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private static int SPLASH_SCREEN = 4000;
private CardView d1,d2,d3,d4;
//varaibles
Animation topAnim, bottomAnim;
ImageView image;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
d1 = (CardView) findViewById(R.id.d1);
d2 = (CardView) findViewById(R.id.d2);
d3 = (CardView) findViewById(R.id.d3);
d4 = (CardView) findViewById(R.id.d4);
d1=null;
d2=null;
d3=null;
d4=null;
try {
d1.setOnClickListener((OnClickListener) this);
d2.setOnClickListener((OnClickListener) this);
d3.setOnClickListener((OnClickListener) this);
d4.setOnClickListener((OnClickListener) this);
}catch (NullPointerException ignored){
}
//Animation
topAnim = AnimationUtils.loadAnimation(this, R.anim.top_animation);
bottomAnim = AnimationUtils.loadAnimation(this, R.anim.bottom_animation);
//Hooks
image = findViewById(R.id.imageView);
image.setAnimation(topAnim);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(MainActivity.this,dashboard2.class);
startActivity(intent);
finish();
}
}, SPLASH_SCREEN);
}
#Override
public void onClick(View v){
Intent i;
switch (v.getId()){
case R.id.d1: i = new Intent(this,d1.class); startActivity(i); break;
case R.id.d2: i = new Intent(this,d2.class); startActivity(i); break;
case R.id.d3: i = new Intent(this,d3.class); startActivity(i); break;
case R.id.d4: i = new Intent(this,d4.class); startActivity(i); break;
}
}
}
this is my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.login">
<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/Theme.Login">
<activity
android:name=".d4"
android:exported="false" />
<activity
android:name=".d3"
android:exported="false" />
<activity
android:name=".d1"
android:exported="false" />
<activity
android:name=".d2"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
this is my logcat:
```Process: com.example.login, PID: 16401
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.login/com.example.login.dashboard2}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1933)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1616)
at android.app.Activity.startActivityForResult(Activity.java:4487)
at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:597)
at android.app.Activity.startActivityForResult(Activity.java:4445)
at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:583)
at android.app.Activity.startActivity(Activity.java:4806)
at android.app.Activity.startActivity(Activity.java:4774)
at com.example.login.MainActivity$1.run(MainActivity.java:61)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
enter code here

Activity dashboard2 is not declared in your Manifest
Solution: Add below tag in your Manifest
<activity
android:name=".dashboard2"
android:exported="false" />

Related

Android Studio Splash screen disappearing before activity start

I have problem with splash screen. It shows only for half a second and disappears a few seconds before activity HomeZastepowy appears. I made this splash screen based on this site https://android.jlelse.eu/right-way-to-create-splash-screen-on-android-e7f1709ba154. Where i made a mistake?
MainActivity code:
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
import java.util.Objects;
public class MainActivity extends AppCompatActivity {
FirebaseAuth mAuth;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
if (mAuth.getCurrentUser() != null) {
String uid = mAuth.getUid();
final DocumentReference mDocRef = FirebaseFirestore.getInstance().collection("Data").document("userInfo").collection(Objects.requireNonNull(uid)).document(uid);
mDocRef.get()
.addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
#Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists()) {
String user = documentSnapshot.getString("user");
assert user != null;
if (user.equals("user")) {
Log.d("tag", String.valueOf(mAuth.getUid()));
Intent intent = new Intent(getApplicationContext(),
HomeUsrActivity.class);
startActivity(intent);
finish();
} else {
Log.d("tag", "Zastepowy");
Log.d("tag", String.valueOf(mAuth.getUid()));
startActivity(new Intent(MainActivity.this, HomeZastepowy.class));
finish();
}
}
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(MainActivity.this, "Error", Toast.LENGTH_SHORT).show();
}
});
finish();
}else {
Intent intent = new Intent(getApplicationContext(),
HomeActivity.class);
startActivity(intent);
finish();
}
}
}
AndroidManifest code:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.zapp4">
<application
android:allowBackup="true"
android:fullBackupContent="#xml/backup_descriptor"
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=".HomeUsrActivity"></activity>
<activity android:name=".LoginActivity" />
<activity android:name=".punktyog" />
<activity android:name=".punktywz" />
<activity android:name=".HomeZastepowy" />
<activity android:name=".tradycje" />
<activity android:name=".wiedza" />
<activity android:name=".kontakt" />
<activity android:name=".zastepy" />
<activity android:name=".historia" />
<activity android:name=".onas" />
<activity android:name=".HomeActivity" />
<activity android:name=".MainActivity" android:theme="#style/SplashScreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I think the problem is that you forgot to remove this line from your code:
setContentView(R.layout.activity_main)
Because you setContentView, it overrides your theme background. So try to comment this line and give it a try.

My Application Is crashing when I'm using Daily repeating Alarm

I am trying to fire alarm everyday on fix time but my application is crashing when click the button to fire alarm.
Please help to find solution. Thanks in Advance .
Here is my Main Activity code :-
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import java.util.Calendar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,15);
calendar.set(Calendar.MINUTE,9);
calendar.set(Calendar.SECOND,20);
Intent intent = new Intent(getApplicationContext(), Notification_receiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),100,intent,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),AlarmManager.INTERVAL_DAY,pendingIntent);
}
});
}
}
Here is my Notification_receiver.java file:-
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
class Notification_receiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent repeating_intent = new Intent(context,Repeating_activity.class);
repeating_intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent .getActivity(context,100,repeating_intent,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentIntent(pendingIntent)
.setSmallIcon(android.R.drawable.sym_def_app_icon)
.setContentTitle("Notification Tittle")
.setContentText("Notification Text")
.setAutoCancel(true);
notificationManager.notify(100,builder.build());
}
}
Here is Manifest if needed :-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hacker.timernotification">
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/> //I tried with and without this but still crashing my app
<uses-permission android:name="android.permission.WAKE_LOCK"/> // this is at the time of fire alarm
<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>
<activity android:name=".Repeating_activity"/>
<receiver android:name=".Notification_receiver"></receiver>
<!--android:enabled="true"
android:exported="true-->"/>
</application>
</manifest>
Here is Repeating_activity.java file :-
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
class Repeating_activity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.repeating_activity_layout);
}
}
activity_main.xml and repeating_activity_layout.xml I have in my projecte not pasting here because I don't think it's need.
Here is error getting after crashing my application :-
16297-16297/com.example.hacker.timernotification E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate receiver com.example.hacker.timernotification.Notification_receiver: java.lang.IllegalAccessException: access to class not allowed
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2436)
at android.app.ActivityThread.access$1600(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1365)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5317)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalAccessException: access to class not allowed
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2431)
at android.app.ActivityThread.access$1600(ActivityThread.java:157) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1365) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:176) 
at android.app.ActivityThread.main(ActivityThread.java:5317) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:511) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 
at dalvik.system.NativeStart.main(Native Method) 
Please help to find solution . Any help will be Appreciated
Make your "Notification_receiver" class public like this
public class Notification_receiver extends BroadcastReceiver
{
// your code
}
it should work.
Update your manifest as below
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hacker.timernotification">
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<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>
<activity android:name=".Repeating_activity"/>
<receiver android:name=".Notification_receiver"
android:directBootAware="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
bootAware is required because your alarm will get disabled after restarting your device, in order to enable it again will have to use. Hope this helps
Dint notice it, agreed with gautam's answer

Can not go to the next page

I want go to next page(mainActivity). I was able to sign up and send that information to the database. But only the success message and the ok button come out. Errors not come out. plz check my code.
LogingActivity.java
package com.life.registeration;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.Volley;
import org.json.JSONObject;
public class LoginActivity extends AppCompatActivity {
private AlertDialog dialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
TextView registerButton = (TextView) findViewById(R.id.registerButton);
registerButton.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
Intent registerIntent = new Intent(LoginActivity.this, RegisterActivity.class);
LoginActivity.this.startActivity(registerIntent);
}
});
final EditText idText = (EditText) findViewById(R.id.idText);
final EditText passwordText = (EditText) findViewById(R.id.passwordText);
final Button loginButton = (Button) findViewById(R.id.loginButton);
loginButton.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
String userID = idText.getText().toString();
String userPassword = passwordText.getText().toString();
Response.Listener<String> responseListener = new Response.Listener<String>(){
#Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if(success){
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
dialog = builder.setMessage("Login success.")
.setPositiveButton("ok", null)
.create();
dialog.show();
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
LoginActivity.this.startActivity(intent);
finish();
}
else{
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
dialog = builder.setMessage("please, check your id.")
.setNegativeButton("re try", null)
.create();
dialog.show();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
};
LoginRequest loginRequest = new LoginRequest(userID, userPassword, responseListener);
RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
queue.add(loginRequest);
}
});
}
#Override
protected void onStop(){
super.onStop();
if(dialog != null){
dialog.dismiss();
dialog = null;
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.life.registeration">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme.NoActionBar">
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".RegisterActivity" /><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
With answer of Prerak Sola add your Activity on Manifest.xml:
<activity android:name=".MainActivity" />
Use your .setPositiveButton properly , your OK click event is null - .setPositiveButton("ok", null):
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
}
}).create();
dialog.show();
You have not registered your MainActivity in AndroidManifest.xml file. Add the line <activity android:name=".MainActivity" /> in the manifest file. So it should look like:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.life.registeration">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme.NoActionBar">
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".RegisterActivity" />
<activity android:name=".MainActivity" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>

How to go back from new activity to main navigation drawer activity

First I create app of Navigation Drawer Activity and travel from fragment to new activity, Now I want to set Home Button on New activity which navigates to main activity of navigation drawer.
but when i run it from app it gives me this when Home button is click
but i want to go direct on MainActivity
Here
NewActivity.java
package com.shubham.navi_demo;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
public class NewActivity extends FragmentActivity {
private static Button Button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new);
onclickbutton();
}
public void onclickbutton(){
Button = (Button)findViewById(R.id.button);
Button.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("android.intent.action.MAIN");
startActivity(intent);
}
}
);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".NewActivity">
<intent-filter>
<action android:name="com.shubham.navi_demo.NewActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
You don't have to start activity with Intent. Just call finish() in NewActivity, it will show you the Main Navigation drawer activity.
hope this helps.
Intent intent = new Intent(this,MainActivity.class);
Change
Intent intent = new Intent("android.intent.action.MAIN");
to
Intent intent = new Intent(this,MainActivity.class);
or call finish(); to finish() current Activity
Simple solution that you can provide users to navigate back to home screen is explained here.
developer.android.com/training/implementing-navigation/ancestral.html
Add this line to your 'AndroidManifest' under relevant activity declaration.
android:parentActivityName="com.example.your_main_activity"

ActivityNotFoundException: Unable to find explicit activity class {co.edu.unimagdalena.projecto/co.edu.unimagdalena.projecto.informacion2}

i have one package with two class
MainActivity:
package co.edu.unimagdalena.projecto;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity implements OnClickListener {
String[] info;
private EditText nombre;
private EditText apellido;
private EditText email;
private EditText telefono;
private Button enviar;
final static String INFO = "co.edu.unimagdalena.projecto.informacion2";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nombre=(EditText)findViewById(R.id.EditTextNombre);
apellido=(EditText)findViewById(R.id.EditTextApellidos);
email=(EditText)findViewById(R.id.EditTextCorreo);
telefono=(EditText)findViewById(R.id.EditTextTelefono);
enviar = (Button)findViewById(R.id.BtnEnviar);
enviar.setOnClickListener(this);
info=new String[4];
}
public void onClick (View v){
Intent intent = new Intent (this, informacion2.class);
intent.setClassName("co.edu.unimagdalena.projecto","co.edu.unimagdalena.projecto.informacion2");
startActivity(intent);
}
public void pasarActidadInfo (View v){
info [0] = nombre.getText().toString();
info [1] = apellido.getText().toString();
info [2] = email.getText().toString();
info [3] = telefono.getText().toString();
Intent act = new Intent (this, informacion2.class);
act.putExtra(INFO, info);
startActivity(act);
}
and other class call it informacion2:
package co.edu.unimagdalena.projecto;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.widget.TextView;
import co.edu.unimagdalena.projecto.MainActivity;
public class informacion2 extends Activity {
String [] info;
TextView nombre,apellido,email,telefono;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.informacion2);
nombre = (TextView) findViewById(R.id.mostrarNombre);
apellido= (TextView) findViewById(R.id.mostrarApellido);
email = (TextView) findViewById(R.id.mostrarEmail);
telefono = (TextView) findViewById(R.id.mostrarTelefono);
Intent men = getIntent();
info = men.getStringArrayExtra(MainActivity.INFO);
nombre.setText(info[0]);
apellido.setText(info[1]);
email.setText(info[2]);
telefono.setText(info[3]);
}
}
and this is the AndroidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.edu.unimagdalena.projecto">
<application
android:allowBackup="true"
android:icon="#mipmap/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>
</application>
<activity
android:name=".informacion2"
android:label="#string/app_name">
</activity>
</manifest>
**I already trying everything and the error is not corrected, i am new in android studio
I can fix the error but now android studio give me this error
java.lang.RuntimeException: Unable to start activity ComponentInfo{co.edu.unimagdalena.projecto/co.edu.unimagdalena.projecto.informacion2}: java.lang.NullPointerException: Attempt to read from null array**
Try including other activity inside application in manifest file like this
<application
android:allowBackup="true"
android:icon="#mipmap/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=".informacion2"
android:label="#string/app_name">
</activity>
</application>
setClassName takes a Package Context as first param setClassName(Context packageContext, String className):
In Android manifest
<activity android:name="co.edu.unimagdalena.projecto.informacion2">
And while starting the activity from your main activity
intent.setClassName("co.edu.unimagdalena.projecto","co.edu.unimagdalena.projecto.informacion2");
You are getting NullPointerException inside second activity, when you try to get values of Array. And you are filling array inside pasarActidadInfo method of first activity. The problem is that you are not calling pasarActidadInfo from anywhere after filling array in your first activity. So,your array would be null.
Try calling pasarActidadInfo method when you want to start new activity.
May be in onClick of button.
Always declare all android components (activities, service, receivers) inside the application tag / block and other configurations will be defined outside of application tag/block and inside manifest tag / block in Androidmanifest.xml.
Copy and paste this code in your manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.edu.unimagdalena.projecto">
<application
android:allowBackup="true"
android:icon="#mipmap/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=".informacion2"
android:label="#string/app_name">
</activity>
</application>
</manifest>

Categories

Resources