我刚开始学习android。所以我从android网站下载了一个名为“AdapterTransition”的示例项目。但我使用ADT eclipse来编译和运行应用程序。我收到以下错误消息
04-06 13:54:18.010: E/AndroidRuntime(894): FATAL EXCEPTION: main
04-06 13:54:18.010: E/AndroidRuntime(894): Process: com.example.android.adaptertransition, PID: 894
04-06 13:54:18.010: E/AndroidRuntime(894): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.adaptertransition/com.example.android.adaptertransition.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.android.adaptertransition.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.android.adaptertransition-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.android.adaptertransition-2, /system/lib]]
04-06 13:54:18.010: E/AndroidRuntime(894): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
04-06 13:54:18.010: E/AndroidRuntime(894): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-06 13:54:18.010: E/AndroidRuntime(894): at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-06 13:54:18.010: E/AndroidRuntime(894): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-06 13:54:18.010: E/AndroidRuntime(894): at android.os.Handler.dispatchMessage(Handler.java:102)
04-06 13:54:18.010: E/AndroidRuntime(894): at android.os.Looper.loop(Looper.java:136)
04-06 13:54:18.010: E/AndroidRuntime(894): at android.app.ActivityThread.main(ActivityThread.java:5017)
04-06 13:54:18.010: E/AndroidRuntime(894): at java.lang.reflect.Method.invokeNative(Native Method)
04-06 13:54:18.010: E/AndroidRuntime(894): at java.lang.reflect.Method.invoke(Method.java:515)
04-06 13:54:18.010: E/AndroidRuntime(894): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-06 13:54:18.010: E/AndroidRuntime(894): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-06 13:54:18.010: E/AndroidRuntime(894): at dalvik.system.NativeStart.main(Native Method)
04-06 13:54:18.010: E/AndroidRuntime(894): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.android.adaptertransition.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.android.adaptertransition-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.android.adaptertransition-2, /system/lib]]
04-06 13:54:18.010: E/AndroidRuntime(894): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
04-06 13:54:18.010: E/AndroidRuntime(894): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
04-06 13:54:18.010: E/AndroidRuntime(894): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
04-06 13:54:18.010: E/AndroidRuntime(894): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
04-06 13:54:18.010: E/AndroidRuntime(894): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
04-06 13:54:18.010: E/AndroidRuntime(894): ... 11 more
XML
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.adaptertransition"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="com.example.android.adaptertransition.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>
</application>
</manifest>
ACTIVITY
package com.example.android.adaptertransition;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ViewAnimator;
import com.example.android.common.activities.SampleActivityBase;
import com.example.android.common.logger.Log;
import com.example.android.common.logger.LogFragment;
import com.example.android.common.logger.LogWrapper;
import com.example.android.common.logger.MessageOnlyLogFilter;
public class MainActivity extends SampleActivityBase {
public static final String TAG = "MainActivity";
// Whether the Log Fragment is currently shown
private boolean mLogShown;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
AdapterTransitionFragment fragment = new AdapterTransitionFragment();
transaction.replace(R.id.sample_content_fragment, fragment);
transaction.commit();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem logToggle = menu.findItem(R.id.menu_toggle_log);
logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator);
logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log);
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_toggle_log:
mLogShown = !mLogShown;
ViewAnimator output = (ViewAnimator) findViewById(R.id.sample_output);
if (mLogShown) {
output.setDisplayedChild(1);
} else {
output.setDisplayedChild(0);
}
supportInvalidateOptionsMenu();
return true;
}
return super.onOptionsItemSelected(item);
}
/** Create a chain of targets that will receive log data */
@Override
public void initializeLogging() {
// Wraps Android's native log framework.
LogWrapper logWrapper = new LogWrapper();
// Using Log, front-end to the logging chain, emulates android.util.log method signatures.
Log.setLogNode(logWrapper);
// Filter strips out everything except the message text.
MessageOnlyLogFilter msgFilter = new MessageOnlyLogFilter();
logWrapper.setNext(msgFilter);
// On screen logging via a fragment with a TextView.
LogFragment logFragment = (LogFragment) getSupportFragmentManager()
.findFragmentById(R.id.log_fragment);
msgFilter.setNext(logFragment.getLogView());
Log.i(TAG, "Ready");
}
}
任何人都可以帮助我?
非常感谢!!
答案 0 :(得分:0)
您好我遇到了java.lang.ClassNotFoundException的问题:没找到类&#34; com.example.whatever&#34;所以我用&#34; com.example.whatever&#34;制作了一个新的包。并将java文件移动到它,这为我修复了它。希望它有所帮助