我已经查看了其他问题,但我找不到原因,为什么,当我在真实设备上启动我的应用程序时它会崩溃并且我得到一个ClassNotFoundException。 有没有人有解决方法如何摆脱这个错误?如果您需要任何其他数据,请评论。 logcat的
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.trucktracker.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.trucktracker-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.trucktracker-2, /vendor/lib, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2505)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653)
at android.app.ActivityThread.access$800(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5872)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:852)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:668)
at dalvik.system.NativeStart.main(Native Method)
的java
package com.example.trucktracker;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.os.Build;
import com.example.trucktracker.Locator;
public class MainActivity extends ActionBarActivity
{
protected TextView question;
protected Button continuebtn;
static String className;
Spinner options;
public void clickedContinue(View view)
{
Log.d(className, "ClickedContinueButton");
Intent intent = new Intent(this, Locator.class);
startActivity(intent);
}
@TargetApi(Build.VERSION_CODES.KITKAT) @Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null)
{
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
options = (Spinner) findViewById(R.id.optionselect);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.options, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
options.setAdapter(adapter);
TextView refrigeratedtruck = (TextView) findViewById (R.id.question);
Typeface typeFace=Typeface.createFromAsset(getAssets(),"Fonts/Roboto-Thin.ttf");
refrigeratedtruck.setTypeface(typeFace);
TextView temperature = (TextView) findViewById(R.id.tempquestion);
temperature.setTypeface(typeFace);
}
public void onItemSelected(AdapterView<?> options, View view,int position, long id)
{
TextView tempquestion1 = (TextView) findViewById(R.id.tempquestion);
EditText temperaturein = (EditText) findViewById(R.id.tempin);
if(position==0)
{
temperaturein.setVisibility(View.VISIBLE);
tempquestion1.setVisibility(View.VISIBLE);
}
else
{
temperaturein.setVisibility(View.GONE);
tempquestion1.setVisibility(View.GONE);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
Log.d(className, "Showing menu.");
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment
{
public PlaceholderFragment()
{
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
}
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.trucktracker"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.trucktracker.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.example.trucktracker.Locator"
android:label="@string/title_activity_locator" >
</activity>
</application>
</manifest>
答案 0 :(得分:0)
嗯,你的道路似乎是正确的。如果我没错;这可能是鬼错误,这个错误并不存在。尝试清理项目/重新启动eclipse,然后在设备上进行测试。