tengo poco tiempo dedicándome a la programación en android y he estado tratando de desarrollar una aplicación de un formulario con Sliding Tabs, encontré un código que he tratado de probar para darme una idea pero me devuelve los siguientes errores:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.jonathanraymundo.pager, PID: 2506
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jonathanraymundo.pager/com.example.jonathanraymundo.pager.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.jonathanraymundo.pager/com.example.jonathanraymundo.pager.PhotosActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.jonathanraymundo.pager/com.example.jonathanraymundo.pager.PhotosActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1794)
at android.app.ActivityThread.resolveActivityInfo(ActivityThread.java:2210)
at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:286)
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:724)
at android.widget.TabHost.setCurrentTab(TabHost.java:388)
at android.widget.TabHost.addTab(TabHost.java:222)
at com.example.jonathanraymundo.pager.MainActivity.onCreate(MainActivity.java:59)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Lo que pude identificar fue que no puede encontrar el activity "PhotosActivity" pero si lo tengo declarado en el manifest y otra en esta parte del codigo Java:
// Adding all TabSpec to TabHost
tabHost.addTab(gralspec); // Adding photos tab
tabHost.addTab(cablespec); // Adding songs tab
tabHost.addTab(fibrespec); // Adding videos tab
Realmente no comprendo a que se deban estos errores y agradecería mucho la ayuda que me pudieran brindar para identificar el por que. De antemano muchas gracias por su atención.
Aqui esta mi archivo Manifest:
<?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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity><!-- 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>
<!-- Songs Activity -->
<activity android:name=".SongsActivity" />
<!-- Videos Activity -->
<activity android:name=".VideosActivity" />
<!-- Photos Activity -->
<activity android:name=".PhotosActivity" />
Y mi archivo Java:
package com.example.jonathanraymundo.pager;
import android.app.ActionBar;
import android.app.TabActivity;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TabHost;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;
public class MainActivity extends TabActivity {
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = getTabHost();
// Tab for Photos
TabHost.TabSpec gralspec = tabHost.newTabSpec("General");
// setting Title and Icon for the Tab
gralspec.setIndicator("General", getResources().getDrawable(R.drawable.icon_general_tab));
Intent photosIntent = new Intent(this, PhotosActivity.class);
gralspec.setContent(photosIntent);
// Tab for Songs
TabHost.TabSpec cablespec = tabHost.newTabSpec("Cableado");
cablespec.setIndicator("Cableado", getResources().getDrawable(R.drawable.icon_structure_tab));
Intent songsIntent = new Intent(this, SongsActivity.class);
cablespec.setContent(songsIntent);
// Tab for Videos
TabHost.TabSpec fibrespec = tabHost.newTabSpec("Fibra");
fibrespec.setIndicator("Fibra", getResources().getDrawable(R.drawable.icon_fiber_tab));
Intent videosIntent = new Intent(this, VideosActivity.class);
fibrespec.setContent(videosIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(gralspec); // Adding photos tab
tabHost.addTab(cablespec); // Adding songs tab
tabHost.addTab(fibrespec); // Adding videos tab
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
public Action getIndexApiAction() {
Thing object = new Thing.Builder()
.setName("Main Page") // TODO: Define a title for the content shown.
// TODO: Make sure this auto-generated URL is correct.
.setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
.build();
return new Action.Builder(Action.TYPE_VIEW)
.setObject(object)
.setActionStatus(Action.STATUS_TYPE_COMPLETED)
.build();
}
@Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
AppIndex.AppIndexApi.start(client, getIndexApiAction());
}
@Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
AppIndex.AppIndexApi.end(client, getIndexApiAction());
client.disconnect();
}
}