Android - 无法实例化活动ComponentInfo(com.build.ashkelon.MyActivity 2)

时间:2014-09-27 10:21:01

标签: java android android-fragmentactivity classnotfoundexception runtimeexception

我看到了人们为这个问题提供的答案。 但没有什么能解决我的问题。

问题: 当我尝试在手机上启动应用程序时,我遇到了以下异常: java.lang.runtimeexception unable to instantiate activity componentinfo (com.build.askelon/com.build.askelon.MyActivity2) : java.lang.ClassNotFoundException : com.build.askelon.MyActivity2

整个堆栈跟踪:

    09-28 22:09:24.800: E/Trace(4656): error opening trace file: No such file or directory (2)
    09-28 22:09:24.870: I/dalvikvm(4656): Failed resolving Lcom/build/ashkelon/MyActivity2; interface 904 'Ledu/washington/cs/touchfreelibrary/sensors/CameraGestureSensor$Listener;'
    09-28 22:09:24.870: W/dalvikvm(4656): Link of class 'Lcom/build/ashkelon/MyActivity2;' failed
    09-28 22:09:24.875: D/AndroidRuntime(4656): Shutting down VM
    09-28 22:09:24.875: W/dalvikvm(4656): threadid=1: thread exiting with uncaught exception (group=0x410442a0)
    09-28 22:09:24.875: E/AndroidRuntime(4656): FATAL EXCEPTION: main
    09-28 22:09:24.875: E/AndroidRuntime(4656): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.build.ashkelon/com.build.ashkelon.MyActivity2}: java.lang.ClassNotFoundException: com.build.ashkelon.MyActivity2
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2024)
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at android.os.Handler.dispatchMessage(Handler.java:99)
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at android.os.Looper.loop(Looper.java:137)
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at android.app.ActivityThread.main(ActivityThread.java:4898)
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at java.lang.reflect.Method.invokeNative(Native Method)
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at java.lang.reflect.Method.invoke(Method.java:511)
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at dalvik.system.NativeStart.main(Native Method)
    09-28 22:09:24.875: E/AndroidRuntime(4656): Caused by: java.lang.ClassNotFoundException: com.build.ashkelon.MyActivity2
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at android.app.Instrumentation.newActivity(Instrumentation.java:1057)
    09-28 22:09:24.875: E/AndroidRuntime(4656):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2015)
    09-28 22:09:24.875: E/AndroidRuntime(4656):     ... 11 more

我已经检查了包名称和AndroidPrivteLibraries就可以了。 但仍然没有运行应用程序。

这是我的Manifest.xml:

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

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera.flash" />

 <uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="16"/>
 <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <service
        android:name="com.build.ashkelon.CallDetectService"
        android:enabled="true"
        android:exported="false" >
    </service>
    <activity
        android:name="com.build.ashkelon.MyActivity2"
        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.build.ashkelon.MyActivity"
        android:label="@string/app_name" >
    </activity>
  </application>
</manifest>

这是我的午餐活动:

package com.build.ashkelon;

import android.app.Activity; 
import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.Toast;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;

import com.build.ashkelon.R;

import java.util.List;
import java.util.Vector;

import edu.washington.cs.touchfreelibrary.sensors.CameraGestureSensor;


public class MyActivity2 extends Activity implements CameraGestureSensor.Listener {

SectionsPagerAdapter mSectionsPagerAdapter;
/**
 * The {@link ViewPager} that will host the section contents.
 */
ViewPager mViewPager;
CameraGestureSensor gestureSensor;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pager_layout);
    gestureSensor = new CameraGestureSensor(this);

    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback);
    List<Fragment> fragmentsList = new Vector<Fragment>();
    fragmentsList.add(Fragment.instantiate(this,Fragment1.class.getName()));
    fragmentsList.add(Fragment.instantiate(this,Fragment2.class.getName()));
    fragmentsList.add(Fragment.instantiate(this,Fragment3.class.getName()));

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(),fragmentsList);

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
}

@Override
public void onGestureUp(CameraGestureSensor cameraGestureSensor, long l) {
    if(mViewPager.getCurrentItem() > 3)
        Toast.makeText(getApplicationContext(), "Hi",Toast.LENGTH_SHORT).show();
    else {
        int currentFrag = mViewPager.getCurrentItem();
        mViewPager.setCurrentItem(currentFrag++);
    }

}

@Override
public void onGestureDown(CameraGestureSensor cameraGestureSensor, long l) {
    if(mViewPager.getCurrentItem() < 0)
        Toast.makeText(getApplicationContext(), "Hi", Toast.LENGTH_SHORT).show();
    else {
        int currentFrag = mViewPager.getCurrentItem();
        mViewPager.setCurrentItem(currentFrag--);
    }
}

@Override
public void onGestureLeft(CameraGestureSensor cameraGestureSensor, long l) {
    Toast.makeText(getApplicationContext(), "Hi", Toast.LENGTH_SHORT).show();
}

@Override
public void onGestureRight(CameraGestureSensor cameraGestureSensor, long l) {
    Toast.makeText(getApplicationContext(), "Hi", Toast.LENGTH_SHORT).show();
}

/**
 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
 * one of the sections/tabs/pages.
 */
public class SectionsPagerAdapter extends FragmentPagerAdapter {

    List<Fragment> fragmentsList;
    public SectionsPagerAdapter(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        this.fragmentsList = fragments;
    }

    @Override
    public Fragment getItem(int position) {
        return this.fragmentsList.get(position);
    }

    @Override
    public int getCount() {
    return this.fragmentsList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
                return "Title";
    }
}

@Override
protected void onPause() {
    gestureSensor.stop();
    super.onPause();
}

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS: {
                CameraGestureSensor.loadLibrary();
                gestureSensor.start();     // your main gesture sensor object

            } break;
            default:
            {
                super.onManagerConnected(status);
            } break;
        }
    }
};
}

感谢所有人!

1 个答案:

答案 0 :(得分:0)

  

安静简单:( Eclipse)Project&gt;属性&gt; Java构建路径&gt;图书馆&gt;添加外部JAR

对于Android开发来说,这不是正确的方法。撤消您在那里所做的事情,然后将JAR放在项目的libs/目录中。