Reputation: 3
I've just got into trying to learn Java over the past few days. I've been jumping between tutorials, etc to try and pick up some of the basics.
Currently it starts on a splash screen for 5 seconds and then goes to another Action(is that right term?) which is the main page(called StartingPoint). However it crashes whilst jumping between those 2 pages. So basically, my question is why is it doing this and how can I fix it?
I created the main page first and that works fine on its own. It is just when trying to jump between those 2 pages.
Manifest - AMENDED:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jonysapp.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Splash"
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>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.jonysapp.test.StartingPoint"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.jonysapp.test.StartingPoint" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Splash.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/mirley"
>
</LinearLayout>
Splash.Java: I have a feeling the code is wrong in here somewhere. Maybe with the Try Catch Finally?
package com.jonysapp.test;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity{
@Override
protected void onCreate(Bundle MirleysVariable) {
// TODO Auto-generated method stub
super.onCreate(MirleysVariable);
setContentView(R.layout.splash);
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent openStartingPoint = new Intent(Splash.this, StartingPoint.class);
Splash.this.startActivity(openStartingPoint);
}
}
};
timer.start();
}
}
StartingPoint.Java
package com.jonysapp.test;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class StartingPoint extends Activity {
int counter;
Button add, sub;
TextView display;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_starting_point);
counter = 0;
add = (Button) findViewById(R.id.bAdd);
sub = (Button) findViewById(R.id.bSub);
display = (TextView) findViewById(R.id.tvDisplay);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter++;
display.setText("Your total is " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter--;
display.setText("Your total is " + counter);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.starting_point, menu);
return true;
}
}
LogCat:
04-21 12:48:08.004: D/dalvikvm(31290): GC_FOR_ALLOC freed 66K, 3% free 8887K/9091K, paused 16ms
04-21 12:48:08.014: I/dalvikvm-heap(31290): Grow heap (frag case) to 10.280MB for 1639696-byte allocation
04-21 12:48:08.044: D/dalvikvm(31290): GC_CONCURRENT freed 1K, 3% free 10487K/10759K, paused 2ms+2ms
04-21 12:48:08.084: D/TextLayoutCache(31290): Using debug level: 0 - Debug Enabled: 0
04-21 12:48:08.134: D/libEGL(31290): loaded /system/lib/egl/libGLES_android.so
04-21 12:48:08.134: D/libEGL(31290): loaded /system/lib/egl/libEGL_adreno200.so
04-21 12:48:08.144: D/libEGL(31290): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
04-21 12:48:08.144: D/libEGL(31290): loaded /system/lib/egl/libGLESv2_adreno200.so
04-21 12:48:08.174: D/OpenGLRenderer(31290): Enabling debug mode 0
04-21 12:48:13.094: W/dalvikvm(31290): threadid=11: thread exiting with uncaught exception (group=0x2b542210)
04-21 12:48:13.094: E/AndroidRuntime(31290): FATAL EXCEPTION: Thread-2196
04-21 12:48:13.094: E/AndroidRuntime(31290): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.jonysapp.test/com.jonysapp.test.StartingPoint}; have you declared this activity in your AndroidManifest.xml?
04-21 12:48:13.094: E/AndroidRuntime(31290): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
04-21 12:48:13.094: E/AndroidRuntime(31290): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
04-21 12:48:13.094: E/AndroidRuntime(31290): at android.app.Activity.startActivityForResult(Activity.java:3190)
04-21 12:48:13.094: E/AndroidRuntime(31290): at android.app.Activity.startActivity(Activity.java:3297)
04-21 12:48:13.094: E/AndroidRuntime(31290): at com.jonysapp.test.Splash$1.run(Splash.java:23)
04-21 12:48:13.364: D/OpenGLRenderer(31290): Flushing caches (mode 0)
04-21 12:48:13.404: D/OpenGLRenderer(31290): Flushing caches (mode 1)
It's very likely I have posted too much code for this question so I apologise if I have bombarded this page with too much. Although if I have missed off anything important to help, please let me know!
As a side note, if you have any tips to stop me getting into any bad habits with the coding so far, that would be appreciated (but not necessary)
Thanks again for any help!
Upvotes: 0
Views: 140
Reputation: 13957
This is your issue:
04-21 12:48:13.094: E/AndroidRuntime(31290): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.jonysapp.test/com.jonysapp.test.StartingPoint}; have you declared this activity in your AndroidManifest.xml?
You have to declare the activity in your manifest, i.e.
<activity
android:name="com.example.project.StartingPoint"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
p.s.: added intent-filter
for app launcher activity.
Hope this helps ... Cheers!
Upvotes: 1
Reputation: 26007
See this messge:
04-21 12:48:13.094: E/AndroidRuntime(31290): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.jonysapp.test/com.jonysapp.test.StartingPoint}; have you declared this activity in your AndroidManifest.xml
This means that you have some activity that you haven't declared in manifest file. you have used all capitals in here:
com.jonysapp.test.STARTINGPOINT
Try making it:
com.jonysapp.test.StartingPoint.
The class name is case sensitive I guess. @Trinimon is right.
Upvotes: 0