I have two activity
classes. I have a button on the first one and I want to show the second when it is clicked, but I get force close when ever i run the application. Here are the classes:
public class APP extends Activity {
private TextToSpeech tts;
private Button b1,b1a,b2,b2a,b3,b3a;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/** Called when the activity is first created. */
setContentView(R.layout.main);
tts = new TextToSpeech (this, null);
b1 = (Button)findViewById(R.id.btn_time);
b1.setOnLongClickListener(new Button.OnLongClickListener(){
@Override
public boolean onLongClick(View arg0) {
String hi = "Time";
tts.speak(hi, 0, null);
return false;
}});
b1a = (Button)findViewById(R.id.btn_time);
b1a.setOnClickListener(new Button.OnClickListener(){
public void onClick(View arg0){
{
Intent i = new Intent(APP.this, Time.class);
startActivity(i);
}
}
});
and to link it to :
public class Time extends Activity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.time);
Button btn = (Button) findViewById(R.id.imageButton1);
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view) {
Intent data = new Intent();
TextView txt_username =
(TextView) findViewById(R.id.imageButton1);
data.setData(Uri.parse(
txt_username.getText().toString()));
setResult(RESULT_OK, data);
finish();
}
});
}
}
}
There are no errors with the codes, it only force closes when the button is pressed.
I even added the time class to manifest
, but the problem still persist. Is there anyway to solve this problem? thanks in advance. :D
this is my current manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.learn2develop.APP"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".APP"
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:na开发者_运维问答me=".Time"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.TIME" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
But, the problem still persist. it force closed after i press the button to link to time activity. and when i check up the logcat
, it says:
07-13 14:25:56.384: ERROR/AndroidRuntime(3799): android.content.ActivityNotFoundException: Unable to find explicit activity class {net.learn2develop.APP/android.text.format.Time};
Have you declared this activity in your AndroidManifest.xml?
Problem is in your Time Activity You don't have any onCreateMethod on it.You declared onCreate on in inner class Activity2 But you wrote to start Time Activity from your App Activity.
If you write Intent i = new Intent(APP.this, Time.class);
.It will look for Time Activity.But you didn't define Time Activity Correctly.Create onCreate method with appropriate syntax on the Timer Class Activity
Also check your manifest file whether you signed Time Activity or not
I think you have not mentioned the classes in menifest you wanted to call ;Use these permission lines to call another activity
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:enabled="true" android:name="Time" />
</application>
</manifest>
精彩评论