更新sdk后无法运行简单的android应用程序

更新sdk后无法运行简单的android应用程序,android,Android,嗨,我已经将我的sdk更新到api级别21,从那以后我收到了很多错误。我的简单应用程序在开始给我运行时异常之前没有给出任何类型的错误。 以下是我的mainactivity.java类: package com.example.myfirstapp; import android.support.v4.view.MenuItemCompat; import android.support.v7.app.ActionBarActivity; import android.support.v7.wi

嗨,我已经将我的sdk更新到api级别21,从那以后我收到了很多错误。我的简单应用程序在开始给我运行时异常之前没有给出任何类型的错误。 以下是我的mainactivity.java类:

package com.example.myfirstapp;

import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.ShareActionProvider;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}


@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);
    MenuItem shareItem=menu.findItem(R.id.action_share);
    ShareActionProvider m=(ShareActionProvider)MenuItemCompat.getActionProvider(shareItem);
    m.setShareIntent(getDefaultIntent());
    return true;
}

private Intent getDefaultIntent() {
    // TODO Auto-generated method stub
    Intent intent=new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    return intent;
}


@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();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
 }
}
My Manifest.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myfirstapp"
    android:versionCode="1"
    android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="21" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        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>
我可以看到您的类是com.example.myfirstapp.MainActivity,但程序找不到com.example.myfirstapp.com.example.myfirstapp.MainActivity,因为它已将您的包名翻倍

在AndroidManifest.xml中,尝试使用包名而不是.MainActivity放置主类。这样行吗

<application>
<activity
    android:name="com.example.myfirstapp.MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

有人能给我提些建议吗?
10-29 03:08:48.153: E/AndroidRuntime(1481): FATAL EXCEPTION: main
10-29 03:08:48.153: E/AndroidRuntime(1481): java.lang.RuntimeException: Unable to instantiate            activity ComponentInfo 
com.example.myfirstapp.com.example.myfirstapp.MainActivity
10-29 03:08:48.153: E/AndroidRuntime(1481):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
10-29 03:08:48.153: E/AndroidRuntime(1481):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
10-29 03:08:48.153: E/AndroidRuntime(1481):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
10-29 03:08:48.153: E/AndroidRuntime(1481):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
10-29 03:08:48.153: E/AndroidRuntime(1481):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-29 03:08:48.153: E/AndroidRuntime(1481):     at android.os.Looper.loop(Looper.java:137)
10-29 03:08:48.153: E/AndroidRuntime(1481):     at android.app.ActivityThread.main(ActivityThread.java:4745)
10-29 03:08:48.153: E/AndroidRuntime(1481):     at java.lang.reflect.Method.invokeNative(Native Method)
10-29 03:08:48.153: E/AndroidRuntime(1481):     at java.lang.reflect.Method.invoke(Method.java:511)
10-29 03:08:48.153: E/AndroidRuntime(1481):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-29 03:08:48.153: E/AndroidRuntime(1481):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-29 03:08:48.153: E/AndroidRuntime(1481):     at dalvik.system.NativeStart.main(Native Method)
10-29 03:08:48.153: E/AndroidRuntime(1481): Caused by: java.lang.ClassNotFoundException: com.example.myfirstapp.com.example.myfirstapp.MainActivity
10-29 03:08:48.153: E/AndroidRuntime(1481):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
10-29 03:08:48.153: E/AndroidRuntime(1481):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-29 03:08:48.153: E/AndroidRuntime(1481):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-29 03:08:48.153: E/AndroidRuntime(1481):     at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
10-29 03:08:48.153: E/AndroidRuntime(1481):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
10-29 03:08:48.153: E/AndroidRuntime(1481):     ... 11 more
<application>
<activity
    android:name="com.example.myfirstapp.MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>