无法实例化应用 - 上MainActivity的ClassNotFoundException [英] Unable to instantiate application - ClassNotFoundException on MainActivity

查看:197
本文介绍了无法实例化应用 - 上MainActivity的ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图清理我的项目好几次,重新启动Eclipse中,要构建路径 - >导出,并确保Android的私人图书馆被选中,我也试图通过XML和Java文件解析查找错误我自己。我也曾尝试在这里研究的StackOverflow但无济于事。

I've tried cleaning my project several times, restarting Eclipse, going to Build path -> Export, making sure Android private libraries is ticked, and I've tried parsing through XML and Java files to find the error myself. I have also tried researching here on StackOverflow but to no avail.

我也查了,如果我是调用的onCreate 方法之前的事情。

I've also checked if I was calling things before the onCreate method.

我担心我的清单XML文件可能会导致一个问题,但我看不出有什么不妥的地方。

I fear my manifest XML file might be causing an issue but I don't see anything wrong with it.

另外关于该项目可能帮助您找到的bug一些信息:

Also a little information about the project which may help you find the bug:


  1. Java文件都位于Java包 com.example.myfirstapp <​​/ code>。

  2. 的时间表和MainActivityXML文件位于布局目录

  1. Java files are located in the Java package com.example.myfirstapp.
  2. The "Schedule" and "MainActivity" XML files are located in layout directory.

由于错误与在MainActivity XML文件,我将张贴和清单。

Since the error is related to the MainActivity XML file, I'll post that and the manifest.

因此​​,这里是我的 MainActivity XML文件(文件名是activity_main.xml中):

So here's my MainActivity XML file (file name is activity_main.xml):

<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:background="#800000"
    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">        
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/email"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="20dp"
        android:contentDescription="@+string/logo"
        android:src="@drawable/brock_logo"/>    
    <EditText
        android:id="@+id/password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:ems="10"
        android:inputType="textWebPassword"/>    
    <EditText
        android:id="@+id/email"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/password"
        android:layout_centerHorizontal="true"
        android:ems="10"
        android:inputType="textWebEmailAddress">
        <requestFocus />
    </EditText>
    <Button
        android:id="@+id/login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/password"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="21dp"
        android:onClick="login"
        android:text="@string/login" />    
</RelativeLayout>

下面是我的 AndroidManifest XML文件:

Here is my AndroidManifest XML file:

<?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="19"/>    
    <uses-permission android:name="android.permission.INTERNET"/>    
    <application
        android:name=".MainActivity"
        android:allowBackup="true"
        android:hasCode="false"
        android:icon="@drawable/brock_logo"
        android:label="@string/app_name"
        android:logo="@drawable/brock_logo"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.myfirstapp.Schedule"
            android:label="@string/app_name"
            android:parentActivityName=".MainActivity">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity"/>
        </activity>
    </application>
</manifest>

这是我的的logcat 输出:

09-21 13:19:41.598: D/dalvikvm(1190): Late-enabling CheckJNI
09-21 13:19:41.690: D/AndroidRuntime(1190): Shutting down VM
09-21 13:19:41.690: W/dalvikvm(1190): threadid=1: thread exiting with uncaught exception    (group=0xa4d85b20)
09-21 13:19:41.698: E/AndroidRuntime(1190): FATAL EXCEPTION: main
09-21 13:19:41.698: E/AndroidRuntime(1190): Process: com.example.myfirstapp, PID: 1190
09-21 13:19:41.698: E/AndroidRuntime(1190): java.lang.RuntimeException: Unable to instantiate application com.example.myfirstapp.MainActivity: java.lang.ClassNotFoundException: Didn't find class "com.example.myfirstapp.MainActivity" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib]]
09-21 13:19:41.698: E/AndroidRuntime(1190):     at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
09-21 13:19:41.698: E/AndroidRuntime(1190):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4317)
09-21 13:19:41.698: E/AndroidRuntime(1190):     at android.app.ActivityThread.access$1500(ActivityThread.java:135)
09-21 13:19:41.698: E/AndroidRuntime(1190):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-21 13:19:41.698: E/AndroidRuntime(1190):     at android.os.Handler.dispatchMessage(Handler.java:102)
09-21 13:19:41.698: E/AndroidRuntime(1190):     at android.os.Looper.loop(Looper.java:136)
09-21 13:19:41.698: E/AndroidRuntime(1190):     at android.app.ActivityThread.main(ActivityThread.java:5017)
09-21 13:19:41.698: E/AndroidRuntime(1190):     at java.lang.reflect.Method.invokeNative(Native Method)
09-21 13:19:41.698: E/AndroidRuntime(1190):     at java.lang.reflect.Method.invoke(Method.java:515)
09-21 13:19:41.698: E/AndroidRuntime(1190):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-21 13:19:41.698: E/AndroidRuntime(1190):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-21 13:19:41.698: E/AndroidRuntime(1190):     at dalvik.system.NativeStart.main(Native Method)
09-21 13:19:41.698: E/AndroidRuntime(1190): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.myfirstapp.MainActivity" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib]]
09-21 13:19:41.698: E/AndroidRuntime(1190):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
09-21 13:19:41.698: E/AndroidRuntime(1190):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
09-21 13:19:41.698: E/AndroidRuntime(1190):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
09-21 13:19:41.698: E/AndroidRuntime(1190):     at android.app.Instrumentation.newApplication(Instrumentation.java:975)
09-21 13:19:41.698: E/AndroidRuntime(1190):     at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
09-21 13:19:41.698: E/AndroidRuntime(1190):     ... 11 more

抱歉倾销code和调试输出。只是想提供尽可能多的信息成为可能。

Sorry for dumping code and debug output. Just trying to provide as much information as possible.

感谢您的阅读。

推荐答案

试试这个:

 <application
    android:allowBackup="true"
    android:icon="@drawable/brock_logo"
    android:label="@string/app_name"
    android:logo="@drawable/brock_logo"
    android:theme="@style/AppTheme" >

那么干净,重建项目。

then clean and rebuild your project.

这篇关于无法实例化应用 - 上MainActivity的ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆