问题描述:

I'm beginner to android programming and this my first app.

I have a list of errors in Java Eclipse when I run my code which I can't understand them .

some of them :

01-28 14:52:10.798: W/dalvikvm(347): threadid=7: thread exiting with uncaught exception (group=0x4001d800)

01-28 14:52:10.798: E/AndroidRuntime(347): FATAL EXCEPTION: Thread-9

01-28 14:52:10.798: E/AndroidRuntime(347): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.zewailiansapp.ust.FORMS }

01-28 14:52:10.798: E/AndroidRuntime(347): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)

01-28 14:52:10.798: E/AndroidRuntime(347): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)

01-28 14:52:10.798: E/AndroidRuntime(347): at android.app.Activity.startActivityForResult(Activity.java:2817)

01-28 14:52:10.798: E/AndroidRuntime(347): at android.app.Activity.startActivity(Activity.java:2923)

01-28 14:52:10.798: E/AndroidRuntime(347): at com.zewailiansapp.ust.Mainactivity$4$1.run(Mainactivity.java:124)

These errors are repeated for every template in my app.

This my manifest XML code

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.zewailiansapp.ust"

android:versionCode="1"

android:versionName="1.0" >

<uses-sdk

android:minSdkVersion="8"

android:targetSdkVersion="8" />

<application

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

<activity

android:name="com.zewailiansapp.ust.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>

<activity

android:name="com.zewailiansapp.ust.Mainactivity"

android:label="@string/app_name" >

<intent-filter>

<action android:name="com.zewailiansapp.ust.MAINACTIVITY" />

<category android:name="android.intent.category.DEFAULT" />

</intent-filter>

</activity>

<activity

android:name="com.zewailiansapp.ust.Announcements"

android:label="Announcements" >

<intent-filter>

<action android:name="com.zewailiansapp.ust.ANNOUNCEMENTS" />

<category android:name="android.intent.category.ALTERNATIVE" />

</intent-filter>

</activity>

<activity

android:name="com.zewailiansapp.ust.Calendar"

android:label="Online Calendar" >

<intent-filter>

<action android:name="com.zewailiansapp.ust.CALENDAR" />

<category android:name="android.intent.category.ALTERNATIVE" />

</intent-filter>

</activity>

<activity

android:name="com.zewailiansapp.ust.Schedules"

android:label="Schedules" >

<intent-filter>

<action android:name="com.zewailiansapp.ust.SCHEDULES" />

<category android:name="android.intent.category.ALTERNATIVE" />

</intent-filter>

</activity>

<activity

android:name="com.zewailiansapp.ust.Forms"

android:label="Forms" >

<intent-filter>

<action android:name="com.zewailiansapp.ust.FORMS" />

<category android:name="android.intent.category.ALTERNATIVE" />

</intent-filter>

</activity>

<activity

android:name="com.zewailiansapp.ust.Social"

android:label="Social Links" >

<intent-filter>

<action android:name="com.zewailiansapp.ust.SOCIAL" />

<category android:name="android.intent.category.ALTERNATIVE" />

</intent-filter>

</activity>

<activity

android:name="com.zewailiansapp.ust.Aboutus"

android:label="Credits" >

<intent-filter>

<action android:name="com.zewailiansapp.ust.ABOUTUS" />

<category android:name="android.intent.category.ALTERNATIVE" />

</intent-filter>

</activity>

</application>

</manifest>

This main activity Java code

package com.zewailiansapp.ust;

import android.os.Bundle;

import android.app.Activity;

import android.content.Intent;

import android.view.Menu;

import android.view.View;

import android.widget.ImageButton;

public class Mainactivity extends Activity {

ImageButton b1;

ImageButton b2;

ImageButton b3;

ImageButton b4;

ImageButton b5;

ImageButton b6;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_mainactivity);

b1= (ImageButton) findViewById(R.id.ib1);

b2= (ImageButton) findViewById(R.id.ib2);

b3= (ImageButton) findViewById(R.id.ib3);

b4= (ImageButton) findViewById(R.id.ib4);

b5= (ImageButton) findViewById(R.id.ib5);

b6= (ImageButton) findViewById(R.id.ib6);

b1.setOnClickListener(new View.OnClickListener()

{

public void onClick(View v) {

Thread timer = new Thread()

{

public void run()

{

try

{

sleep(10);

}

catch(InterruptedException e)

{

e.printStackTrace();

}

finally

{

Intent changeWindow = new Intent("com.zewailiansapp.ust.ANNOUNCEMENTS");

startActivity(changeWindow);

}

}

};

timer.start();

}

});

b2.setOnClickListener(new View.OnClickListener()

{

public void onClick(View v) {

Thread timer = new Thread()

{

public void run()

{

try

{

sleep(10);

}

catch(InterruptedException e)

{

e.printStackTrace();

}

finally

{

Intent changeWindow = new Intent("com.zewailiansapp.ust.CALENDAR");

startActivity(changeWindow);

}

}

};

timer.start();

}

});

b3.setOnClickListener(new View.OnClickListener()

{

public void onClick(View v) {

Thread timer = new Thread()

{

public void run()

{

try

{

sleep(10);

}

catch(InterruptedException e)

{

e.printStackTrace();

}

finally

{

Intent changeWindow = new Intent("com.zewailiansapp.ust.SCHEDULES");

startActivity(changeWindow);

}

}

};

timer.start();

}

});

b4.setOnClickListener(new View.OnClickListener()

{

public void onClick(View v) {

Thread timer = new Thread()

{

public void run()

{

try

{

sleep(10);

}

catch(InterruptedException e)

{

e.printStackTrace();

}

finally

{

Intent changeWindow = new Intent("com.zewailiansapp.ust.FORMS");

startActivity(changeWindow);

}

}

};

timer.start();

}

});

b5.setOnClickListener(new View.OnClickListener()

{

public void onClick(View v) {

Thread timer = new Thread()

{

public void run()

{

try

{

sleep(10);

}

catch(InterruptedException e)

{

e.printStackTrace();

}

finally

{

Intent changeWindow = new Intent("com.zewailiansapp.ust.SOCIAL");

startActivity(changeWindow);

}

}

};

timer.start();

}

});

b6.setOnClickListener(new View.OnClickListener()

{

public void onClick(View v) {

Thread timer = new Thread()

{

public void run()

{

try

{

sleep(10);

}

catch(InterruptedException e)

{

e.printStackTrace();

}

finally

{

Intent changeWindow = new Intent("com.zewailiansapp.ust.ABOUTUS");

startActivity(changeWindow);

}

}

};

timer.start();

}

});

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.mainactivity, menu);

return true;

}

}

This main XML layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".Mainactivity"

android:background="@drawable/program_background"

>

<TextView

android:id="@+id/social"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="40dp"

android:layout_marginTop="400dp"

android:text="Social Links" />

<TextView

android:id="@+id/forms"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="200dp"

android:layout_marginTop="300dp"

android:text="Forms" />

<TextView

android:id="@+id/aboutus"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="200dp"

android:layout_marginTop="400dp"

android:text="Credits" />

<TextView

android:id="@+id/announcements"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="40dp"

android:layout_marginTop="200dp"

android:text="Announcements" />

<TextView

android:id="@+id/calendar"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="200dp"

android:layout_marginTop="200dp"

android:text="Calendar" />

<TextView

android:id="@+id/schedules"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="40dp"

android:layout_marginTop="300dp"

android:text="Schedules" />

<ImageButton

android:id="@+id/ib6"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="200dp"

android:layout_marginTop="350dp"

android:src="@drawable/about" />

<ImageButton

android:id="@+id/ib1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="40dp"

android:layout_marginTop="150dp"

android:src="@drawable/announcement" />

<ImageButton

android:id="@+id/ib2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="200dp"

android:layout_marginTop="150dp"

android:src="@drawable/calendar" />

<ImageButton

android:id="@+id/ib5"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="40dp"

android:layout_marginTop="350dp"

android:src="@drawable/social" />

<ImageButton

android:id="@+id/ib4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="200dp"

android:layout_marginTop="250dp"

android:src="@drawable/form" />

<ImageButton

android:id="@+id/ib3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="40dp"

android:layout_marginTop="250dp"

android:src="@drawable/schedule" />

</RelativeLayout>

网友答案:

The ClassCast exception means you are trying to cast an ImageButton to something that isn't one. Find the part of your code that looks something like: ((ImageButton) findViewById(R.id.imageButton)) and make sure that the id that it is referencing is actually an ImageButton, and not something else, like a standard Button, or an ImageView. Please post your xml if the error continues so I can help further.

Also, when starting an activity, use the method new Intent(getApplicationContext(), <Activity class>... (i.e. new Intent(getApplicationContext(), MyActivity.class)... It will work better than the method that you're trying to use. Good luck!

网友答案:

According to the newly updated LogCat, you are now experiencing a problem different then the original. Here is the solution to your new problem:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.zewailiansapp.ust.FORMS

According to this, your activity has now started, and you clicked one of your buttons, but the app can not find the class that you are telling it to launch.

Use the following snippet to start new activities:

Intent i = new Intent(MyFirstActivity.this, MySecondActivity.class);
startActivity(i);
相关阅读:
Top