我正在开发一款使用 Cocos2d-x 游戏引擎的 Android 游戏。该应用程序通过 cocos2d-x 为我生成的 Activity 启动。我想要做的是启动另一个 Activity ,该 Activity 使用 JNI 调用 cocos Activity 方法启动文件资源管理器,然后使用 Intent 切换到文件资源管理器 Activity 。但是,在文件浏览器打开之前应用程序崩溃了。
JNI调用代码如下:
void MusicSelect::HandleYourMusicPressed(CCObject* sender)
{
SimpleAudioEngine::sharedEngine()->playEffect("SFX/select.wav");
JavaVM* jvm = cocos2d::JniHelper::getJavaVM();
if (NULL == jvm)
CCLog("Failed to get the JavaVM");
JNIEnv* env;
jint ret = jvm->GetEnv((void**)&env, JNI_VERSION_1_4);
if (ret != JNI_OK)
CCLog("Failed to get then JNIEnv");
jclass classRet = env->FindClass("org/cocos2dx/extbeatanni/ExtremeBeatAnnihilation");
if (!classRet)
CCLog("Failed to find class ExtremeBeatAnnihilation");
jmethodID methodRet = env->GetMethodID(classRet, "startupFileExplore", "()V");
if (!methodRet)
CCLog("Failed to find method startupFileExplore");
env->CallVoidMethod(classRet, methodRet);
}
这是 Cocos2d-x 生成的 Activity ,startupFileExplore() 是我添加的函数:
public class ExtremeBeatAnnihilation extends Cocos2dxActivity{
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
}
private void startupFileExplore()
{
Intent myIntent = new Intent(ExtremeBeatAnnihilation.this, FileExplore.class);
System.out.println("Starting up the activity");
startActivity(myIntent);
}
static {
System.loadLibrary("game");
}
}
这是显示 onCreate() 方法的精简文件浏览器 Activity :
public class FileExplore extends Activity {
// some class members defined here
@Override
protected void onCreate(Bundle savedInstanceState) {
System.out.println("Inside the onCreate()");
super.onCreate(savedInstanceState);
loadFileList();
showDialog(DIALOG_LOAD_FILE);
Log.d(TAG, path.getAbsolutePath());
}
// some more methods that aren't necessarily relevant
}
这是我的 AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.cocos2dx.extbeatanni"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="15" />
<uses-feature android:glEsVersion="0x00020000" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="org.cocos2dx.extbeatanni.ExtremeBeatAnnihilation"
android:configChanges="orientation"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="org.cocos2dx.extbeatanni.FileExplore"
android:label="@string/app_name" >
</activity>
</application>
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
</manifest>
当我运行它并调用带有 JNI 代码的函数时,我只看到 Starting up the activity 在 logcat 中得到输出,但我从未看到 Inside onCreate( ) 在崩溃前获取输出。
我查阅并尝试了很多东西,但仍然无法深究这一点。我认为 cocos Activity 可能是一件奇怪的事情。像这样的问题从来都不是他们看起来的样子。拜托,有没有人知道发生了什么,或者我做错了什么?谢谢!
编辑:
根据要求,这里是 logcat 输出。感谢 Vikas Patidar 的评论,我能够开始看到这个段错误:
12-12 11:32:37.414: I/DEBUG(28509): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
12-12 11:32:37.414: I/DEBUG(28509): Build fingerprint: 'verizon_wwe/inc/inc:2.3.4/GRJ22/389630.15:user/release-keys'
12-12 11:32:37.414: I/DEBUG(28509): pid: 28510, tid: 28520 >>> org.cocos2dx.extbeatanni <<<
12-12 11:32:37.414: I/DEBUG(28509): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000042
12-12 11:32:37.414: I/DEBUG(28509): r0 00000038 r1 00000002 r2 00000002 r3 00000002
12-12 11:32:37.414: I/DEBUG(28509): r4 44e4754a r5 44e5aee0 r6 44f5a780 r7 000020f8
12-12 11:32:37.414: I/DEBUG(28509): r8 80018380 r9 44e4754a 10 44e5aecc fp 800a73d4
12-12 11:32:37.414: I/DEBUG(28509): ip 000000f8 sp 44f5a730 lr 8001c1ac pc 8001d2a0 cpsr 00000010
12-12 11:32:37.414: I/DEBUG(28509): d0 42156fb442156fe8 d1 42156e7c42156e6f
12-12 11:32:37.414: I/DEBUG(28509): d2 42156ee442156e15 d3 42156f4c42156f42
12-12 11:32:37.414: I/DEBUG(28509): d4 421e17e0421e17ac d5 421e1848421e1814
12-12 11:32:37.414: I/DEBUG(28509): d6 421e18b0421e187c d7 421e1918421e18e4
12-12 11:32:37.414: I/DEBUG(28509): d8 0000000000000000 d9 0000000000000000
12-12 11:32:37.414: I/DEBUG(28509): d10 0000000000000000 d11 0000000000000000
12-12 11:32:37.414: I/DEBUG(28509): d12 0000000000000000 d13 0000000000000000
12-12 11:32:37.414: I/DEBUG(28509): d14 0000000000000000 d15 0000000000000000
12-12 11:32:37.414: I/DEBUG(28509): d16 0000001040529e50 d17 3fdffffffddaaf00
12-12 11:32:37.414: I/DEBUG(28509): d18 3fe0000000000000 d19 3fe000000112a880
12-12 11:32:37.414: I/DEBUG(28509): d20 0000000000000000 d21 3f872e5c54a96637
12-12 11:32:37.414: I/DEBUG(28509): d22 3e21e7c5992989f4 d23 bda8fae9be8838d4
12-12 11:32:37.414: I/DEBUG(28509): d24 3fc74721cad6b0ed d25 3fc39a09d078c69f
12-12 11:32:37.414: I/DEBUG(28509): d26 0000000000000000 d27 0000000000000000
12-12 11:32:37.414: I/DEBUG(28509): d28 0000000000000000 d29 0000000000000000
12-12 11:32:37.414: I/DEBUG(28509): d30 0000000000000000 d31 0000000000000000
12-12 11:32:37.414: I/DEBUG(28509): scr 80000012
12-12 11:32:37.454: I/DEBUG(28509): #00 pc 0001d2a0 /system/lib/libdvm.so
12-12 11:32:37.454: I/DEBUG(28509): #01 pc 000228ac /system/lib/libdvm.so
12-12 11:32:37.454: I/DEBUG(28509): #02 pc 000217a4 /system/lib/libdvm.so
12-12 11:32:37.454: I/DEBUG(28509): #03 pc 00060b58 /system/lib/libdvm.so
12-12 11:32:37.454: I/DEBUG(28509): #04 pc 0004cf86 /system/lib/libdvm.so
12-12 11:32:37.454: I/DEBUG(28509): #05 pc 00149378 /data/data/org.cocos2dx.extbeatanni/lib/libgame.so
12-12 11:32:37.454: I/DEBUG(28509): #06 pc 001493fa /data/data/org.cocos2dx.extbeatanni/lib/libgame.so
12-12 11:32:37.464: I/DEBUG(28509): #07 pc 001bb3e6 /data/data/org.cocos2dx.extbeatanni/lib/libgame.so
12-12 11:32:37.464: I/DEBUG(28509): #08 pc 001bb45c /data/data/org.cocos2dx.extbeatanni/lib/libgame.so
12-12 11:32:37.464: I/DEBUG(28509): #09 pc 001b9ce6 /data/data/org.cocos2dx.extbeatanni/lib/libgame.so
12-12 11:32:37.464: I/DEBUG(28509): #10 pc 001e4bf4 /data/data/org.cocos2dx.extbeatanni/lib/libgame.so
12-12 11:32:37.464: I/DEBUG(28509): #11 pc 001e4e02 /data/data/org.cocos2dx.extbeatanni/lib/libgame.so
12-12 11:32:37.464: I/DEBUG(28509): #12 pc 001c865c /data/data/org.cocos2dx.extbeatanni/lib/libgame.so
12-12 11:32:37.464: I/DEBUG(28509): #13 pc 001cb104 /data/data/org.cocos2dx.extbeatanni/lib/libgame.so
12-12 11:32:37.464: I/DEBUG(28509): #14 pc 000181b4 /system/lib/libdvm.so
12-12 11:32:37.464: I/DEBUG(28509): code around pc:
12-12 11:32:37.464: I/DEBUG(28509): 8001d280 e2522001 e48a1004 1afffffb e1d030bc
12-12 11:32:37.464: I/DEBUG(28509): 8001d290 ea00001c e1b02627 e245a014 e1d410b4
12-12 11:32:37.464: I/DEBUG(28509): 8001d2a0 e1d090ba e1d030bc 0a000016 e2622005
12-12 11:32:37.464: I/DEBUG(28509): 8001d2b0 e08ff202 eb0000c5 e207cc0f e795232c
12-12 11:32:37.464: I/DEBUG(28509): 8001d2c0 e1a00000 e52a2004 e201ca0f e795252c
12-12 11:32:37.464: I/DEBUG(28509): code around lr:
12-12 11:32:37.464: I/DEBUG(28509): 8001c18c e7952103 e3520000 0a000508 e5922000
12-12 11:32:37.464: I/DEBUG(28509): 8001c19c e5922074 e5054008 e7920101 eb000439
12-12 11:32:37.464: I/DEBUG(28509): 8001c1ac e320f000 e320f000 e320f000 e320f000
12-12 11:32:37.464: I/DEBUG(28509): 8001c1bc e320f000 e1d430b4 e1d410b2 e7952103
12-12 11:32:37.464: I/DEBUG(28509): 8001c1cc e3520000 0a0004f9 e5922000 e5922074
12-12 11:32:37.464: I/DEBUG(28509): stack:
12-12 11:32:37.464: I/DEBUG(28509): 44f5a6f0 80018380 /system/lib/libdvm.so
12-12 11:32:37.464: I/DEBUG(28509): 44f5a6f4 0032a760
12-12 11:32:37.464: I/DEBUG(28509): 44f5a6f8 44e5ae4c
12-12 11:32:37.464: I/DEBUG(28509): 44f5a6fc afd13795 /system/lib/libc.so
12-12 11:32:37.464: I/DEBUG(28509): 44f5a700 0032a760
12-12 11:32:37.464: I/DEBUG(28509): 44f5a704 80055c61 /system/lib/libdvm.so
12-12 11:32:37.464: I/DEBUG(28509): 44f5a708 4051f610
12-12 11:32:37.464: I/DEBUG(28509): 44f5a70c 00000000
12-12 11:32:37.464: I/DEBUG(28509): 44f5a710 00000000
12-12 11:32:37.464: I/DEBUG(28509): 44f5a714 44f5a788
12-12 11:32:37.464: I/DEBUG(28509): 44f5a718 4051f610
12-12 11:32:37.464: I/DEBUG(28509): 44f5a71c 80067bb7 /system/lib/libdvm.so
12-12 11:32:37.464: I/DEBUG(28509): 44f5a720 4271fbe0
12-12 11:32:37.464: I/DEBUG(28509): 44f5a724 44e5ae78
12-12 11:32:37.464: I/DEBUG(28509): 44f5a728 df002777
12-12 11:32:37.464: I/DEBUG(28509): 44f5a72c e3a070ad
12-12 11:32:37.464: I/DEBUG(28509): #00 44f5a730 00000004
12-12 11:32:37.464: I/DEBUG(28509): 44f5a734 44f5a780
12-12 11:32:37.464: I/DEBUG(28509): 44f5a738 00000001
12-12 11:32:37.464: I/DEBUG(28509): 44f5a73c 00334060
12-12 11:32:37.464: I/DEBUG(28509): 44f5a740 0032a768
12-12 11:32:37.464: I/DEBUG(28509): 44f5a744 000171a8
12-12 11:32:37.464: I/DEBUG(28509): 44f5a748 800acdc8
12-12 11:32:37.464: I/DEBUG(28509): 44f5a74c fffffe78
12-12 11:32:37.474: I/DEBUG(28509): 44f5a750 800a73d4
12-12 11:32:37.474: I/DEBUG(28509): 44f5a754 800228b0 /system/lib/libdvm.so
12-12 11:32:37.474: I/DEBUG(28509): #01 44f5a758 44f5a780
12-12 11:32:37.474: I/DEBUG(28509): 44f5a75c 0032a760
12-12 11:32:37.474: I/DEBUG(28509): 44f5a760 80022820 /system/lib/libdvm.so
12-12 11:32:37.474: I/DEBUG(28509): 44f5a764 42361bd0
12-12 11:32:37.474: I/DEBUG(28509): 44f5a768 00000000
12-12 11:32:37.474: I/DEBUG(28509): 44f5a76c 800217a8 /system/lib/libdvm.so
最佳答案
我弄清楚了导致崩溃的原因。在我的 JNI 代码 env->CallVoidMethod(classRet, methodRet); 行中,我将 jclass 传递给它,它指向 ExtremeBeatAnnihilation 类.这不应该是 jclass。这实际上应该是一个 jobject,它指向当前正在运行的 ExtremeBeatAnnihilation Activity 的实例。因为我有这个错误,它是在随机实例而不是正在运行的实例中调用方法,所以在不在正在运行的 Activity 中时尝试切换 Activity 会导致它崩溃。
编辑:
应要求,这里是使用来自原生 Android 的 JNI 调用切换 Activity 的工作代码(这是根据我的代码修改的,以便更通用,所以如果有错误请告诉我):
JNIEnv* env;
JavaVM* jvm = cocos2d::JniHelper::getJavaVM();
if (NULL == jvm)
CCLog("Failed to get the JavaVM");
jint ret = jvm->GetEnv((void**)&env, JNI_VERSION_1_4);
if (ret != JNI_OK)
CCLog("Failed to get then JNIEnv");
jclass myClass = env->FindClass("org/cocos2dx/extbeatanni/ExtremeBeatAnnihilation");
if (!myClass)
CCLog("Failed to find class ExtremeBeatAnnihilation");
jmethodID getObjectMethod = env->GetStaticMethodID(myClass, "getObject", "()Ljava/lang/Object;");
if(!getObjectMethod)
CCLog("Failed to find method getObject");
jobject myInstance = env->CallStaticObjectMethod(myClass, getObjectMethod);
if(!myInstance)
CCLog("Failed to get the current instance of the running activity");
jmethodID startupFileExploreMethod = env->GetMethodID(myClass, "startupFileExplore", "()V");
if (!startupFileExploreMethod)
CCLog("Failed to find method startupFileExplore");
// call the java method within the ExtremeBeatAnnihilation activity that will start up file explore
env->CallNonvirtualVoidMethod(myInstance, myClass, startupFileExploreMethod);
Cocos2dxActivity代码:
public class ExtremeBeatAnnihilation extends Cocos2dxActivity{
private static final int REQUEST_SONG_FILE = 0; // flag for file explore to return a selected song
private static Object activity; // current running instance of this activity
private String selectedSong; // song that was selected in the file explorer
// called on the startup of the game; will save the instance created to be returned later
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
activity = this;
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
// returns the currently running instance of this activity
public static Object getObject()
{
Log.i("cppCall", "Returning activity");
return activity;
}
// starts the file explore activity to allow the user to choose a song on their SD card
public void startupFileExplore()
{
try
{
Intent fileExploreIntent = new Intent(ExtremeBeatAnnihilation.this, FileExplore.class);
if(fileExploreIntent != null)
{
startActivityForResult(fileExploreIntent, REQUEST_SONG_FILE);
}
else
{
Log.d("Extreme Beat Annihilation", "FileExploreIntent null\n");
}
}
catch(Exception e)
{
Log.d("Extreme", "Error" + e.getMessage());
}
}
// returns the selected song
public String getSelectedSong()
{
return selectedSong;
}
// called when returning from the file explore; gets the selected song that was returned
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_SONG_FILE)
{
selectedSong = data.getStringExtra("Song File");
}
}
static {
System.loadLibrary("game");
}
}
关于java - 在 Android 上从 cocos2d-x Activity 切换到另一个 Activity 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20508149/
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>
我想用ruby编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr
当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少