我使用eclipse作为IDE来编写一个简单的测试程序,将一些TextView和Button放在屏幕上并且工作正常。
然后,我做......
(1)将编译器合规性级别设置为15
(2)将ANDROID_SDK_PLATFORM设置为C:/ ADT / sdk / platforms / android-15
(3)将这些添加为外部JAR
osmdroid-android-4.2.jar
slf4j-android-1.7.7.jar
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.test.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>
fragment_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.test.MainActivity$PlaceholderFragment" >
<Button
android:id="@+id/bt_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/bt_test"
android:text="@string/hello_world"
android:textSize="24sp" />
<org.osmdroid.views.MapView
android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
MainActivity.java
package com.example.test;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import org.osmdroid.views.MapView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu 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;
getActivity().setContentView(R.layout.fragment_main);
return null;
}
}
}
编译确定,apk安装确定,但应用程序崩溃... (我使用带有android 4.2.2的真实手机作为调试设备。) 这是日志:
06-06 23:03:06.007: D/jdwp(18476): sendBufferedRequest : len=0x3B
06-06 23:03:06.013: D/dalvikvm(18476): open_cached_dex_file :
/data/app/com.example.test-1.apk /data/dalvik-
cache/data@app@com.example.test-1.apk@classes.dex
06-06 23:03:06.027: D/skia(18476): Flag is not 10
06-06 23:03:06.029: D/skia(18476): Flag is not 10
06-06 23:03:06.032: W/IconCustomizer(18476): can't load
transform_config.xml
06-06 23:03:06.035: D/skia(18476): Flag is not 10
06-06 23:03:06.040: D/skia(18476): Flag is not 10
06-06 23:03:06.043: D/skia(18476): Flag is not 10
06-06 23:03:06.058: D/skia(18476): Flag is not 10
06-06 23:03:06.060: D/skia(18476): Flag is not 10
06-06 23:03:06.066: D/skia(18476): Flag is not 10
06-06 23:03:06.067: D/skia(18476): Flag is not 10
06-06 23:03:06.069: D/skia(18476): Flag is not 10
06-06 23:03:06.071: D/skia(18476): Flag is not 10
06-06 23:03:06.072: D/skia(18476): Flag is not 10
06-06 23:03:06.077: V/Provider/Settings(18476): invalidate
[secure]: current 7 != cached 0
06-06 23:03:06.080: V/Provider/Settings(18476): from db cache, name
= access_control_lock_enabled , value = null
06-06 23:03:06.111: D/libEGL(18476): loaded
/vendor/lib/egl/libEGL_mtk.so
06-06 23:03:06.114: D/libEGL(18476): loaded
/vendor/lib/egl/libGLESv1_CM_mtk.so
06-06 23:03:06.117: D/libEGL(18476): loaded
/vendor/lib/egl/libGLESv2_mtk.so
06-06 23:03:06.252: D/OpenGLRenderer(18476): Enabling debug mode 0
06-06 23:03:06.253: V/InputMethodManager(18476): onWindowFocus:
null softInputMode=288 first=true flags=#9810100
06-06 23:03:06.254: V/InputMethodManager(18476): START INPUT:
com.android.internal.policy.impl.PhoneWindow$DecorView{4221c418
V.E..... R.....ID 0,0-720,1280} ic=null
tba=android.view.inputmethod.EditorInfo@42289610 controlFlags=#104
06-06 23:03:06.256: V/InputMethodManager(18476): Starting input:
Bind result=InputBindResult{null
com.cootek.smartinputv5/.TouchPalIME #4739}
06-06 23:03:06.265: D/skia(18476): Flag is not 10
06-06 23:03:08.041: I/SurfaceTextureClient(18476):
[STC::queueBuffer] (this:0x5c2c73f8) fps:0.57, dur:1745.04,
max:1745.04, min:1745.04
06-06 23:03:08.627: D/OpenGLRenderer(18476): Flushing caches (mode
0)
06-06 23:03:08.845: D/OpenGLRenderer(18476): Flushing caches (mode
1)
06-06 23:03:08.849: D/OpenGLRenderer(18476): Flushing caches (mode
0)
06-06 23:03:45.893: D/jdwp(18569): sendBufferedRequest : len=0x3B
06-06 23:03:45.899: D/dalvikvm(18569): open_cached_dex_file :
/data/app/com.example.test-2.apk /data/dalvik-
cache/data@app@com.example.test-2.apk@classes.dex
06-06 23:03:45.911: D/skia(18569): Flag is not 10
06-06 23:03:45.914: D/skia(18569): Flag is not 10
06-06 23:03:45.918: W/IconCustomizer(18569): can't load
transform_config.xml
06-06 23:03:45.921: D/skia(18569): Flag is not 10
06-06 23:03:45.925: D/skia(18569): Flag is not 10
06-06 23:03:45.929: D/skia(18569): Flag is not 10
06-06 23:03:45.942: D/skia(18569): Flag is not 10
06-06 23:03:45.944: D/skia(18569): Flag is not 10
06-06 23:03:45.950: D/skia(18569): Flag is not 10
06-06 23:03:45.952: D/skia(18569): Flag is not 10
06-06 23:03:45.953: D/skia(18569): Flag is not 10
06-06 23:03:45.955: D/skia(18569): Flag is not 10
06-06 23:03:45.956: D/skia(18569): Flag is not 10
06-06 23:03:45.961: D/AndroidRuntime(18569): Shutting down VM
06-06 23:03:45.961: W/dalvikvm(18569): threadid=1: thread exiting
with uncaught exception (group=0x419d59a8)
06-06 23:03:45.964: E/AndroidRuntime(18569): FATAL EXCEPTION: main
06-06 23:03:45.964: E/AndroidRuntime(18569):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.test/com.example.test.MainActivity}:
android.view.InflateException: Binary XML file line #24: Error
inflating class org.osmdroid.views.MapView
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.app.ActivityThread.performLaunchActivity(
ActivityThread.java:2333)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.app.ActivityThread.handleLaunchActivity(
ActivityThread.java:2385)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.app.ActivityThread.access$600(ActivityThread.java:157)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.app.ActivityThread$H.handleMessage(
ActivityThread.java:1341)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.os.Handler.dispatchMessage(Handler.java:99)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.os.Looper.loop(Looper.java:153)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.app.ActivityThread.main(ActivityThread.java:5322)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
java.lang.reflect.Method.invokeNative(Native Method)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
java.lang.reflect.Method.invoke(Method.java:511)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:848)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:615)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
dalvik.system.NativeStart.main(Native Method)
06-06 23:03:45.964: E/AndroidRuntime(18569): Caused by:
android.view.InflateException: Binary XML file line #24: Error
inflating class org.osmdroid.views.MapView
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.view.LayoutInflater.createViewFromTag
(LayoutInflater.java:768)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.view.LayoutInflater.rInflate(LayoutInflater.java:816)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.view.LayoutInflater.inflate(LayoutInflater.java:559)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.view.LayoutInflater.inflate(LayoutInflater.java:466)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.view.LayoutInflater.inflate(LayoutInflater.java:419)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
com.android.internal.policy.impl.PhoneWindow.setContentView
(PhoneWindow.java:354)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.app.Activity.setContentView(Activity.java:1981)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
com.example.test.MainActivity$PlaceholderFragment.onCreateView
(MainActivity.java:63)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.app.Fragment.performCreateView(Fragment.java:1695)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.app.FragmentManagerImpl.moveToState
(FragmentManager.java:885)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.app.FragmentManagerImpl.moveToState
(FragmentManager.java:1057)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.app.BackStackRecord.run(BackStackRecord.java:694)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.app.FragmentManagerImpl.execPendingActions
(FragmentManager.java:1435)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.app.Activity.performStart(Activity.java:5233)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.app.ActivityThread.performLaunchActivity
(ActivityThread.java:2306)
06-06 23:03:45.964: E/AndroidRuntime(18569): ... 11 more
06-06 23:03:45.964: E/AndroidRuntime(18569): Caused by:
java.lang.ClassNotFoundException: Didn't find class
"org.osmdroid.views.MapView" on path: DexPathList[[zip file
"/data/app/com.example.test-2.apk"],nativeLibraryDirectories=
[/data/app-lib/com.example.test-2, /vendor/lib, /system/lib]]
06-06 23:03:45.964: E/AndroidRuntime(18569): at
dalvik.system.BaseDexClassLoader.findClass
(BaseDexClassLoader.java:53)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.view.LayoutInflater.createView(LayoutInflater.java:622)
06-06 23:03:45.964: E/AndroidRuntime(18569): at
android.view.LayoutInflater.createViewFromTag
(LayoutInflater.java:757)
06-06 23:03:45.964: E/AndroidRuntime(18569): ... 25 more
06-06 23:03:48.547: I/Process(18569): Sending signal.
PID: 18569 SIG: 9
答案 0 :(得分:0)
我解决了。添加osmdroid-android-4.2.jar,osmdroid-third-party-4.2.jar,slf4j-android-1.7.7.jar和slf4j-api-1.7.7作为外部JAR。并将所有四个文件放入“test”项目的libs目录中。