新版Android sdk的问题

时间:2014-04-25 09:08:04

标签: android eclipse

就在今天,我下载了eclipse并将其设置为android开发。在创建新的android项目时,它会创建appcompat_v7库项目,该项目由主项目引用。问题是两者都显示错误。我甚至试图从问题列表中删除错误,但这没有帮助。抛出了运行时错误 -

04-25 15:07:51.521: E/AndroidRuntime(1348): FATAL EXCEPTION: main
04-25 15:07:51.521: E/AndroidRuntime(1348): Process: com.example.demo, PID: 1348
04-25 15:07:51.521: E/AndroidRuntime(1348): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.demo/com.example.demo.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.demo.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.demo-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.demo-1, /system/lib]]
04-25 15:07:51.521: E/AndroidRuntime(1348):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
04-25 15:07:51.521: E/AndroidRuntime(1348):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-25 15:07:51.521: E/AndroidRuntime(1348):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-25 15:07:51.521: E/AndroidRuntime(1348):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-25 15:07:51.521: E/AndroidRuntime(1348):     at android.os.Handler.dispatchMessage(Handler.java:102)
04-25 15:07:51.521: E/AndroidRuntime(1348):     at android.os.Looper.loop(Looper.java:136)
04-25 15:07:51.521: E/AndroidRuntime(1348):     at android.app.ActivityThread.main(ActivityThread.java:5017)
04-25 15:07:51.521: E/AndroidRuntime(1348):     at java.lang.reflect.Method.invokeNative(Native Method)
04-25 15:07:51.521: E/AndroidRuntime(1348):     at java.lang.reflect.Method.invoke(Method.java:515)
04-25 15:07:51.521: E/AndroidRuntime(1348):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-25 15:07:51.521: E/AndroidRuntime(1348):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-25 15:07:51.521: E/AndroidRuntime(1348):     at dalvik.system.NativeStart.main(Native Method)
04-25 15:07:51.521: E/AndroidRuntime(1348): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.demo.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.demo-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.demo-1, /system/lib]]
04-25 15:07:51.521: E/AndroidRuntime(1348):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
04-25 15:07:51.521: E/AndroidRuntime(1348):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
04-25 15:07:51.521: E/AndroidRuntime(1348):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
04-25 15:07:51.521: E/AndroidRuntime(1348):     at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
04-25 15:07:51.521: E/AndroidRuntime(1348):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
04-25 15:07:51.521: E/AndroidRuntime(1348):     ... 11 more

如何立即使用开发环境。显然我无法创建一个新项目。但是年纪较大的人工作正常。提前谢谢。

编辑:我附加了IDE创建的第一个活动源 -

package com.example.demo;

import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;

public class MainActivity extends ActionBarActivity {

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

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
    }


    @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);
        return true;
    }

    @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);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }

}

1 个答案:

答案 0 :(得分:0)

我将android-support-v4.jar从libs文件夹复制到appcompat_v7 / bin文件夹,错误已解决。该应用运行得很好。