El dato lo estoy recibiendo desde mi MainActivity que es un Login, el cual envía el dato (a través de Intent) hasta la actividad Inicio (hasta aquí se envía el dato sin problemas) y desde la actividad Inicio estoy intentando enviarlo hasta mi Fragment que deriva de la misma clase Inicio (aquí es donde el dato no se envía y da error). Ayuda por favoor, muchas gracias!
Este es mi Logcat
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.matias.tikon3, PID: 10514
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.matias.tikon3/com.example.matias.tikon3.Inicio}: android.content.res.Resources$NotFoundException: String resource ID #0x1
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2309)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.access$800(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
Application terminated.
Este es mi Activity
public class Inicio extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
TextView txtRut, etiNombre;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inicio);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
// Esto es para iniciar en un fragment
//FragmentManager fragmentManager = getSupportFragmentManager();
//fragmentManager.beginTransaction().replace(R.id.contenedor, new ImportFragment()).commit();
txtRut= findViewById(R.id.tvRut);
etiNombre= findViewById(R.id.tvNombre);
Intent intent = getIntent();
int rut = intent.getIntExtra("rut", 0);
String nombre = intent.getStringExtra("nombre");
String apellido = intent.getStringExtra("apellido");
String correo = intent.getStringExtra("correo");
String pas = intent.getStringExtra("pas");
ImportFragment importFragment = new ImportFragment();
Bundle bundle = new Bundle();
bundle.putInt("rut", rut);
importFragment.setArguments(bundle);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.contenedor, importFragment, null);
fragmentTransaction.commit();
txtRut.setText(rut + "");
etiNombre.setText(nombre);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
FragmentManager fragmentManager = getSupportFragmentManager();
if (id == R.id.nav_camera) {
fragmentManager.beginTransaction().replace(R.id.contenedor, new ImportFragment()).commit();
} else if (id == R.id.nav_gallery) {
fragmentManager.beginTransaction().replace(R.id.contenedor, new GalleryFragment()).commit();
} else if (id == R.id.nav_slideshow) {
fragmentManager.beginTransaction().replace(R.id.contenedor, new SlideshowFragment()).commit();
} else if (id == R.id.nav_manage) {
fragmentManager.beginTransaction().replace(R.id.contenedor, new ToolsFragment()).commit();
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
Y este es el fragment donde quiero recibir el dato y me da error (y si tengo mi tvRut en el layout fragment_import)
public class ImportFragment extends Fragment {
TextView txtRut;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
int rut = getArguments().getInt("rut", 0);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View vista = inflater.inflate(R.layout.fragment_import, container, false);
int rut = getArguments().getInt("rut", 0);
txtRut= vista.findViewById(R.id.tvRut);
txtRut.setText(rut);
return vista;
}
}