0

嗯,我看到了人们给这个问题的答案。 但没有任何解决我的问题。Android - 无法安装活动ComponentInfo(com.build.ashkelon.MyActivity2)

问题: 当我尝试启动我的手机在我的应用我得到这个异常: 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; 
     } 
    } 
}; 
} 

谢谢!

+0

尝试清理工作区并重新编译应用程序 – Blackbelt 2014-09-27 10:25:06

+0

发布*整个*堆栈跟踪。 – CommonsWare 2014-09-27 10:52:31

+0

那么,我试图清理和重建,不工作。我添加到主帖子堆栈跟踪。谢谢。 @CommonsWare – 2014-10-02 14:11:12

回答

0

它安静简单:(Eclipse中)项目>属性> Java构建路径>库>添加外部JAR

这不是做Android的发展的正确途径。撤消你在那里做了什么,然后把JAR放到你的项目的libs/目录中。

+0

好吧,我现在看到,谢谢。 – 2014-10-02 17:36:49

相关问题