在我的项目中,当我更改我的包名称时,出现了以下错误。 我上网但没有有用的数据。 在某些情况下,我发现我的方法不应该是静态的,当我删除静态时 它设置此方法必须是静态的。 任何解决此问题的建议 提前致谢 这是我的错误:
找不到原生方法:
com.nooshindroid.yastashir.controller.JNIServer.get_number_of_processors:()I
at com.nooshindroid.yastashir.controller.JNIServer.get_number_of_processors(Native Method)
at com.nooshindroid.yastashir.controller.JNIServer.runServer(JNIServer.java:27)
at com.nooshindroid.yastashir.game.FreebloksActivity.startNewGame(FreebloksActivity.java:520)
at com.nooshindroid.yastashir.game.FreebloksActivity$16.onClick(FreebloksActivity.java:774)
at com.nooshindroid.yastashir.game.ColorListDialog.onItemClick(ColorListDialog.java:79)
at android.widget.AdapterView.performItemClick(AdapterView.java:301)
at android.widget.AbsListView.performItemClick(AbsListView.java:1510)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3339)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
这是我的代码:
public class JNIServer {
final static String tag = JNIServer.class.getSimpleName();
/* unfortunately Runtime.availableProcessors() returns only the number of online cores */
public static native int get_number_of_processors();
private static native int native_run_server(int game_mode, int field_size_x, int field_size_y, int ki_mode, int ki_threads);
private static native int native_resume_server(
int field_size_x,
int field_size_y,
int current_player,
int spieler[],
int field_data[],
int player_stone_data[],
int game_mode,
int ki_mode,
int ki_threads);
public static void runServer(Spielleiter spiel, int game_mode, int field_size, int ki_mode) {
int ki_threads = get_number_of_processors();
if (spiel == null)
native_run_server(game_mode, field_size, field_size, ki_mode, ki_threads);
else {
int player_stones_available[] = new int[Stone.STONE_COUNT_ALL_SHAPES * 4];
int i, j;
for (i = 0; i < 4; i++)
for (j = 0; j < Stone.STONE_COUNT_ALL_SHAPES; j++)
player_stones_available[i * Stone.STONE_COUNT_ALL_SHAPES + j] = spiel.get_player(i).get_stone(j).get_available();
native_resume_server(
spiel.m_field_size_x,
spiel.m_field_size_y,
spiel.current_player(),
spiel.spieler,
spiel.get_game_field(),
player_stones_available,
game_mode,
ki_mode,
ki_threads);
}
}
static {
Log.d(tag, "loading server.so");
System.loadLibrary("server");
}
}
答案 0 :(得分:0)
为什么您到处使用native
关键字?它应该意味着用另一种语言实现某些东西,这似乎不是这里的情况因此导致了这个错误。