无法在扩展类上找到方法:

时间:2016-08-09 03:55:05

标签: android native game-maker

您好我在Gamemaker:Studio中制作了一个Android原生扩展程序,当我运行游戏并尝试使用扩展程序时,我在转轮命令窗口中收到此错误代码:

无法在扩展类上找到方法:folderLoader [double,double]

它不会使游戏崩溃或抛出任何其他错误,它只是在java文件中找不到我的方法。这就是我设置它的方式:

编辑扩展包属性 - 常规标签 -

name- DirectoryPicker

android复选框勾选

注入manifest-

<activity
android:name="${YYAndroidPackageName}.DirectoryPicker"
android:label="DirectoryPicker" />

注入gradle(激活我的styles.xml) -

compile 'com.android.support:appcompat-v7:+'

编辑扩展包属性-android选项卡 -

班级名称 - DirectoryPicker

权限 - android.permission.WRITE_EXTERNAL_STORAGE

编辑扩展文件属性框 -

name- DirectoryPicker.extension.gmx

init function-设置为folderLoader

copys仅限于安卓和Android yyc盒子

编辑扩展功能框 -

name- folderLoader

外部名称 - folderLoader

help- folderLoader(double FolderOnly,double ShowHidden)

返回类型框 - 选择双

键和值框 - 参数0 double argument1 double

对象的鼠标左键按下事件的调用代码:

folderLoader(1.0, 0.0);

同一对象中的异步事件(设置为社交事件):

var type2 = string(async_load[? "type2"])
var data2 = string(async_load[? "folder"])
if type2 == "folderFound"
{ 
var text = data2;
}

java文件名为DirectoryPicker.java

package ${YYAndroidPackageName};
import ${YYAndroidPackageName}.R;
import ${YYAndroidPackageName}.RunnerActivity;
import com.yoyogames.runner.RunnerJNILib;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

public class DirectoryPicker extends ListActivity {

private static final int EVENT_OTHER_SOCIAL = 70;
public static final String ONLY_DIRS = "onlyDirs";
public static final String SHOW_HIDDEN = "showHidden";
public static final String CHOSEN_DIRECTORY = "chosenDir";
public static final int PICK_DIRECTORY = 43522432;
private File dir;
private boolean onlyDirs = true;
private boolean showHidden = false;


public void folderLoader(double yesOrNo,double noOrYes)
{
if(yesOrNo == 0.0) onlyDirs = false;
if(yesOrNo == 1.0) onlyDirs = true;
if(noOrYes == 0.0) showHidden = false;
if(noOrYes == 1.0) showHidden = true;
findFolders();
}

public void findFolders() {

Bundle extras = getIntent().getExtras();
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        File Root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        dir = new File(Root.getAbsolutePath());
    }
if (extras != null) {
    showHidden = extras.getBoolean(SHOW_HIDDEN, false);
    onlyDirs = extras.getBoolean(ONLY_DIRS, true);
}

setContentView(R.layout.chooser_list);
setTitle(dir.getAbsolutePath());
Button btnChoose = (Button) findViewById(R.id.btnChoose);
String name = dir.getName();
if(name.length() == 0)
    name = "No folders found";
btnChoose.setText(name);
btnChoose.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        returnDir(dir.getAbsolutePath());
    }
});

ListView lv = getListView();
lv.setTextFilterEnabled(true);

if(!dir.canRead()) {
    Context context = getApplicationContext();
    String msg = "Could not read folders.";
    Toast toast = Toast.makeText(context, msg, Toast.LENGTH_LONG);
    toast.show();
    return;
}

final ArrayList<File> files = filter(dir.listFiles(), onlyDirs, showHidden);
String[] names = names(files);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, names));


lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if(!files.get(position).isDirectory())
            return;
        String path = files.get(position).getAbsolutePath();
        Intent intent = new Intent((RunnerActivity.CurrentActivity), DirectoryPicker.class);
        intent.putExtra(DirectoryPicker.SHOW_HIDDEN, showHidden);
        intent.putExtra(DirectoryPicker.ONLY_DIRS, onlyDirs);
        (RunnerActivity.CurrentActivity).startActivityForResult(intent, PICK_DIRECTORY);
    }
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == PICK_DIRECTORY && resultCode == RESULT_OK) {
    Bundle extras = data.getExtras();
    String path = (String) extras.get(DirectoryPicker.CHOSEN_DIRECTORY);
    returnDir(path);
int dsMapIndex = RunnerJNILib.jCreateDsMap(null, null, null);
RunnerJNILib.DsMapAddString( dsMapIndex, "type2", "folderFound" );
RunnerJNILib.DsMapAddString( dsMapIndex, "folder", path );
RunnerJNILib.CreateAsynEventWithDSMap(dsMapIndex, EVENT_OTHER_SOCIAL);
}
}

private void returnDir(String path) {
Intent result = new Intent();
result.putExtra(CHOSEN_DIRECTORY, path);
setResult(RESULT_OK, result);
finish();
}

public ArrayList<File> filter(File[] file_list, boolean onlyDirs, boolean showHidden) {
ArrayList<File> files = new ArrayList<File>();
for(File file: file_list) {
    if(onlyDirs && !file.isDirectory())
        continue;
    if(!showHidden && file.isHidden())
        continue;
    files.add(file);
}
Collections.sort(files);
return files;
}

public String[] names(ArrayList<File> files) {
String[] names = new String[files.size()];
int i = 0;
for(File file: files) {
    names[i] = file.getName();
    i++;
}
return names;
}
}

我把两个相关的xml文件放在我放在res文件夹中的布局文件夹中,该文件夹位于AndroidSource文件夹中。 我还下载了一些扩展,看看他们是如何做到的,并且他们都在android源文件夹中有一个名为yymanifest.xml的文件,由gamemaker生成,这个文件永远不会在我的扩展项目中创建,我试过保存,导出扩展并重新导入它,但文件永远不会存在,并且它不是你自己制作的文件,游戏制作者必须在制作扩展时生成它,但我怎么能让它做到这一点?

非常感谢任何想法或帮助

1 个答案:

答案 0 :(得分:3)

一切似乎都很好,你需要在menifest文件中提到你的文件夹。