我需要在我的Android Studio应用程序中使用Mapsforge(离线地图)。我导入了以下库:
我已经把受抚养人包括在Build中了Gradle:
compile fileTree(dir: 'libs', include: ['*.jar'])
这是代码:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.mapsforge.map.android.view.MapView;
public class MapaForgeFragment extends Fragment {
private MapView mapView;
private View view;
public static MapaForgeFragment newInstance() {
MapaForgeFragment fragment = new MapaForgeFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
public MapaForgeFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_mapa_forge, container, false);
mapView = (MapView) view.findViewById(R.id.mapView);
return view;
}
}
在XML中:
<FrameLayout 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"
tools:context="cat.bcn.horta.MapaForgeFragment">
<org.mapsforge.map.android.view.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.view.InflateException: Binary XML file line #7: Error inflating class org.mapsforge.map.android.view.MapView
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at cat.bcn.horta.MapaForgeFragment.onCreateView(MapaForgeFragment.java:36)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5227)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at cat.bcn.horta.MapaForgeFragment.onCreateView(MapaForgeFragment.java:36)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5227)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at org.mapsforge.map.view.FpsCounter.createPaint(FpsCounter.java:33)
at org.mapsforge.map.view.FpsCounter.<init>(FpsCounter.java:47)
at org.mapsforge.map.android.view.MapView.<init>(MapView.java:70)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at cat.bcn.horta.MapaForgeFragment.onCreateView(MapaForgeFragment.java:36)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5227)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)
我认为在Eclipse中导入jar文件是必要的,但在Android Studio中可能需要一些其他的东西。
您似乎忘记了用初始化mapsforge库
AndroidGraphicFactory.createInstance(appContext);
其中AppContext
是应用程序上下文。
我想做一个应用程序,使用谷歌翻译API。自从我添加了 我的构建中的依赖项。gradle我有个错误: 现在必须显式声明注释处理器。发现编译类路径上的以下依赖项包含注释处理器。请将它们添加到annotationProcessor配置中。-自动值-1.2。jar(com.google.auto.value:auto-value:1.2)或者,设置android。defaultConfig。javaCom
我试图导入的应用程序中的gradle版本与JDK11不兼容,而JDK11正是android studio用作其嵌入式JDK的。我的机器上有JDK8。我已经尝试进入项目结构来更改JDK8位置的路径,但是如果我尝试更改它,就会出现错误。它说我必须选择一个有效的JDK11目录。如何让android studio使用JDK 8?错误截图
您能帮助在android studio中运行默认java而不是gradle执行吗?谢谢
我正在尝试建立一个简单的“飞鸟”游戏,我需要鸟的图像倾斜,上升时指向上方,反之亦然。然而,当旋转我的图像时,它会在稍微下降或轻触屏幕后部分或完全从屏幕上消失。谁能告诉我怎么解决这个问题吗?
问题内容: 这是我的应用程序级别gradle文件: 编译项目时出现的完整错误是: 错误:任务’:app:transformDexArchiveWithExternalLibsDexMergerForDebug’的执行失败。 java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex
我安装了Java1.7.0_21,卸载了以前的版本后,今天安装了1.7.0_45。现在Android Studio已经停止编译项目,并表示无法找到1.7.0_21文件夹。如何为Java SDK设置新路径?我也改变了环境变量,但不起作用。
我正在尝试从AndroidStudio中的JSON文件中读取数据,格式如下: 我想有对象包含int,String,String(每行的新对象)。有人知道怎么写吗?