2016-08-09 124 views
0

喜林使在Gamemaker的Android原生擴展:工作室,當我運行遊戲,並嘗試使用擴展我得到亞軍命令窗口此錯誤代碼:上找不到擴展類方法:

無法找到擴展類的方法:folderLoader [double,double]

它不會崩潰遊戲或拋出任何其他錯誤,它只是無法在java文件中找到我的方法。這就是我把它設置了:

編輯擴展包的屬性,一般製表

名字 - DirectoryPicker

Android的複選框選中

注入到manifest-

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

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

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

編輯擴展包屬性 - 機器人制表

類名稱 - DirectoryPicker

Permissions- android.permission.WRITE_EXTERNAL_STORAGE

編輯擴展文件屬性盒 -

名稱 - DirectoryPicker.extension .gmx

init函數 - 設置爲folderLoader

copys TO-打勾機器人和機器人YYC盒僅

編輯擴展函數盒 -

名稱 - folderLoader

外部名稱 - folderLoader

幫助 - folderLoader(雙FolderOnly,雙ShowHidden )

返回類型box-selected double

鍵和值箱 - 參數0雙參數1雙

爲對象的鼠標左鍵按下事件調用代碼:

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; 
} 
} 

有2個相關的xml文件,我把它放在res文件夾中,這是在AndroidSource文件夾中的佈局文件夾。 我也下載了一些擴展,看看他們是如何做的,他們都在Android源文件夾中有一個名爲yymanifest.xml的文件,它由gamemaker生成,這個文件永遠不會在我的擴展項目中創建,我試過了保存,導出擴展名並重新導入它,但文件永遠不會存在,並且它不是您可以自己創建的文件,gamemaker必須在創建擴展名時生成該文件,但是如何才能獲得它?

任何意見或幫助將不勝感激

+0

您是否嘗試過在編譯之前清除緩存?也可以加倍取小數值? – user2899094

回答

3

好一切似乎罰款,你需要提及你在menifest文件夾中。

+0

好酷,謝謝!我忽略這樣做,我會試一試 – Wraithious

+0

好吧,所以我一直在這個工作了幾天,仍然是相同的錯誤,:無法找到擴展類的方法:null。我知道通過使用java,當你引用一個未初始化的變量時會出現null異常,但是據我所見,一切都已初始化,我已經更新了我的java文件幾次,所以我將編輯我的原始發佈問題新文件和其他我嘗試過的東西 – Wraithious