美好的一天!
我有一个带有MainActivity的JAR文件。我已经创建了一个新的Android应用程序来测试Intent代码。下面是我的按钮代码。
public void doSomething(View v) {
Intent i = new Intent(this, com.testing1234.apptest.MainActivity.class);
startActivity(i);
}
com.testing1234.apptest是我的JAR文件。当我尝试运行它时,带有按钮的第一个表单出现。单击按钮以运行JAR文件后,应用程序将终止。
在logcat上显示错误“找不到类'com.testing1234.apptest.MainActivity'”
或者它不是不可能的?我确实确保将JAR文件包含在我的项目中。请帮我。请随时向我提供一些有用的提示。感谢。
编辑:
我尝试了另一个JAR文件,下面是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wodota.test123"
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>
<activity android:name="com.viva.demo.MainActivity" />
</application>
</manifest>
编辑2:Logcat
08-19 19:17:30.940: D/dalvikvm(26519): VFY: replacing opcode 0x1c at 0x0002
08-19 19:17:30.950: D/dalvikvm(2614): GC_EXPLICIT freed <1K, 27% free 6422K/8771K, paused 0ms+0ms
08-19 19:17:30.950: D/dalvikvm(2614): GC_EXPLICIT freed <1K, 27% free 6422K/8771K, paused 0ms+0ms
08-19 19:17:30.960: W/InputManagerService(2624): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@b32849d0 (uid=1000 pid=26271)
08-19 19:17:30.970: I/PGA(26519): New SOCKET connection: .wodota.test123 (pid 26519, tid 26519)
08-19 19:17:30.980: I/ActivityManager(2624): Displayed com.wodota.test123/.MainActivity: +80ms
08-19 19:17:33.660: E/InputDispatcher(2624): Motion event has invalid pointer count 0; value must be between 1 and 16.
08-19 19:17:33.730: E/InputDispatcher(2624): Motion event has invalid pointer count 0; value must be between 1 and 16.
08-19 19:17:33.730: D/AndroidRuntime(26519): Shutting down VM
08-19 19:17:33.730: W/dalvikvm(26519): threadid=1: thread exiting with uncaught exception (group=0xb2c63180)
08-19 19:17:33.730: D/BstCommandProcessor-Application(2806): Application crash has been observed.
08-19 19:17:33.730: I/Process(26519): Sending signal. PID: 26519 SIG: 9
08-19 19:17:33.730: D/AndroidRuntime(26519): procName from cmdline: com.wodota.test123
08-19 19:17:33.730: E/AndroidRuntime(26519): in writeCrashedAppName, pkgName :com.wodota.test123
08-19 19:17:33.730: D/AndroidRuntime(26519): file written successfully with content: com.wodota.test123 StringBuffer : ;com.wodota.test123
08-19 19:17:33.730: E/AndroidRuntime(26519): FATAL EXCEPTION: main
08-19 19:17:33.730: E/AndroidRuntime(26519): java.lang.IllegalStateException: Could not execute method of the activity
08-19 19:17:33.730: E/AndroidRuntime(26519): at android.view.View$1.onClick(View.java:3044)
08-19 19:17:33.730: E/AndroidRuntime(26519): at android.view.View.performClick(View.java:3511)
08-19 19:17:33.730: E/AndroidRuntime(26519): at android.view.View$PerformClick.run(View.java:14105)
08-19 19:17:33.730: E/AndroidRuntime(26519): at android.os.Handler.handleCallback(Handler.java:605)
08-19 19:17:33.730: E/AndroidRuntime(26519): at android.os.Handler.dispatchMessage(Handler.java:92)
08-19 19:17:33.730: E/AndroidRuntime(26519): at android.os.Looper.loop(Looper.java:137)
08-19 19:17:33.730: E/AndroidRuntime(26519): at android.app.ActivityThread.main(ActivityThread.java:4424)
08-19 19:17:33.730: E/AndroidRuntime(26519): at java.lang.reflect.Method.invokeNative(Native Method)
08-19 19:17:33.730: E/AndroidRuntime(26519): at java.lang.reflect.Method.invoke(Method.java:511)
08-19 19:17:33.730: E/AndroidRuntime(26519): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
08-19 19:17:33.730: E/AndroidRuntime(26519): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:592)
08-19 19:17:33.730: E/AndroidRuntime(26519): at dalvik.system.NativeStart.main(Native Method)
08-19 19:17:33.730: E/AndroidRuntime(26519): Caused by: java.lang.reflect.InvocationTargetException
08-19 19:17:33.730: E/AndroidRuntime(26519): at java.lang.reflect.Method.invokeNative(Native Method)
08-19 19:17:33.730: E/AndroidRuntime(26519): at java.lang.reflect.Method.invoke(Method.java:511)
08-19 19:17:33.730: E/AndroidRuntime(26519): at android.view.View$1.onClick(View.java:3039)
08-19 19:17:33.730: E/AndroidRuntime(26519): ... 11 more
08-19 19:17:33.730: E/AndroidRuntime(26519): Caused by: java.lang.NoClassDefFoundError: com.viva.demo.MainActivity
08-19 19:17:33.730: E/AndroidRuntime(26519): at com.wodota.test123.MainActivity.doSomething(MainActivity.java:26)
08-19 19:17:33.730: E/AndroidRuntime(26519): ... 14 more
08-19 19:17:33.740: I/WindowManager(2624): WIN DEATH: Window{b341f500 com.wodota.test123/com.wodota.test123.MainActivity paused=false}
08-19 19:17:33.740: I/ActivityManager(2624): Process com.wodota.test123 (pid 26519) has died.
08-19 19:17:33.740: W/ActivityManager(2624): Force removing ActivityRecord{b30ace88 com.wodota.test123/.MainActivity}: app died, no saved state
08-19 19:17:33.740: D/ActivityManager(2624): TopActivityInfo, pkgName: com.android.settings activityName: com.android.settings/.Settings bstSpecialAppKeyboardHandlingEnabled = false
08-19 19:17:33.740: D/ActivityManager(2624): Showing guidance for pkgName: com.android.settings
08-19 19:17:33.750: V/AudioHardware(515): open playback normal
08-19 19:17:33.750: V/AudioHardware(515): write() wakeup setting route SPK
08-19 19:17:33.750: D/GuidanceScreen(2777): hiding guidance
08-19 19:17:33.750: D/GuidanceScreen(2777): event === app_launch
08-19 19:17:33.750: D/GuidanceScreen(2777): hardKeyboard = 1
08-19 19:17:33.750: D/GuidanceScreen(2777): controllerType === DualAction
08-19 19:17:33.750: D/GuidanceScreen(2777): appName: Settings, currentPkg: com.android.settings, event: app_launch, controller: DualAction
08-19 19:17:33.750: D/GuidanceScreen(2777): appName: Settings
08-19 19:17:33.750: D/GuidanceScreen(2777): no guidance for com.android.settings.
08-19 19:17:33.770: I/ManageApplications(26271): onCreateOptionsMenu in ManageApplications{b3502558 #1 id=0x10202d4}: com.android.internal.view.menu.MenuBuilder@b3549888
08-19 19:17:33.780: D/VoldCmdListener(507): asec fspath air.com.playtika.slotomania-2
08-19 19:17:33.780: W/InputManagerService(2624): Got RemoteException sending setActive(false) notification to pid 26519 uid 10055
08-19 19:17:33.790: D/VoldCmdListener(507): asec fspath com.igg.bzbee.slotsdeluxe-2
08-19 19:17:33.790: D/VoldCmdListener(507): asec fspath com.kingsky.moto3dAndroid-1
08-19 19:17:36.770: D/AudioHardware(515): AudioHardware pcm playback is going to standby.
08-19 19:17:42.290: W/ActivityManager(2624): Activity destroy timeout for ActivityRecord{b319b598 com.android.packageinstaller/.UninstallAppProgress}
08-19 19:17:43.860: I/ActivityManager(2624): No longer want com.google.android.partnersetup (pid 26421): hidden #9
08-19 19:17:45.640: D/Finsky(26435): [1] 5.onFinished: Installation state replication succeeded.
08-19 19:18:20.210: D/dalvikvm(3343): GC_CONCURRENT freed 1914K, 40% free 6446K/10691K, paused 0ms+0ms
答案 0 :(得分:2)
您需要将活动添加到清单。您要运行的每个Activity都必须添加到Manifest。
添加:
<activity android:name="com.testing1234.apptest.MainActivity" />