我有一个应该在我的应用中加载的插件包。 当我在iOS模拟器上运行应用程序时,捆绑包已正确加载,但是当我重新编译项目以便在我的真实设备上运行应用程序时,我收到以下错误:
// The "TryTryTryAgain" class.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.URL;
import java.util.Arrays;
import java.util.TimerTask;
import java.util.Date;
import java.util.Timer;
public class JavaMemoryGame_Final {
static JButton btnStart, buttonArray[] = new JButton[12];
static JFrame start, questions, survey;
static JTextField nameEnter;
static JLabel scoreOutput, lblTitle, lblPrompt1, lblPrompt2, t_fImage, lblInstruct, lblReadyCheck;
static JRadioButton reallyBad, bad, good, reallyGood;
static AudioClip clap, yess, noo;
static ButtonGroup finalSurvey;
static DefaultListModel listModel;
static JList difficulty;
static int randNumGenerator;
static int score = 0, arrayImage[] = new int[12];
private Timer timer = new Timer();
public static JButton[] randNum() {
arrayImage[0] = (int)(Math.random() * 12) + 1;
arrayImage[1] = (int)(Math.random() * 12) + 1;
while (arrayImage[1] == arrayImage[0]) {
arrayImage[1] = (int)(Math.random() * 12) + 1;
}
arrayImage[2] = (int)(Math.random() * 12) + 1;
while (arrayImage[2] == arrayImage[1] || arrayImage[2] == arrayImage[0]) {
arrayImage[2] = (int)(Math.random() * 12) + 1;
}
arrayImage[3] = (int)(Math.random() * 12) + 1;
while (arrayImage[3] == arrayImage[2] || arrayImage[3] == arrayImage[1] || arrayImage[3] == arrayImage[0]) {
arrayImage[3] = (int)(Math.random() * 12) + 1;
}
arrayImage[4] = (int)(Math.random() * 12) + 1;
while (arrayImage[4] == arrayImage[3] || arrayImage[4] == arrayImage[2] || arrayImage[4] == arrayImage[1] || arrayImage[4] == arrayImage[0]) {
arrayImage[4] = (int)(Math.random() * 12) + 1;
}
arrayImage[5] = (int)(Math.random() * 12) + 1;
while (arrayImage[5] == arrayImage[4] || arrayImage[5] == arrayImage[3] || arrayImage[5] == arrayImage[2] || arrayImage[5] == arrayImage[1] || arrayImage[5] == arrayImage[0]) {
arrayImage[5] = (int)(Math.random() * 12) + 1;
}
arrayImage[6] = (int)(Math.random() * 12) + 1;
while (arrayImage[6] == arrayImage[5] || arrayImage[6] == arrayImage[4] || arrayImage[6] == arrayImage[3] || arrayImage[6] == arrayImage[2] || arrayImage[6] == arrayImage[1] || arrayImage[6] == arrayImage[0]) {
arrayImage[6] = (int)(Math.random() * 12) + 1;
}
arrayImage[7] = (int)(Math.random() * 12) + 1;
while (arrayImage[7] == arrayImage[6] || arrayImage[7] == arrayImage[5] || arrayImage[7] == arrayImage[4] || arrayImage[7] == arrayImage[3] || arrayImage[7] == arrayImage[2] || arrayImage[7] == arrayImage[1] || arrayImage[7] == arrayImage[0]) {
arrayImage[7] = (int)(Math.random() * 12) + 1;
}
arrayImage[8] = (int)(Math.random() * 12) + 1;
while (arrayImage[8] == arrayImage[7] || arrayImage[8] == arrayImage[6] || arrayImage[8] == arrayImage[5] || arrayImage[8] == arrayImage[4] || arrayImage[8] == arrayImage[3] || arrayImage[8] == arrayImage[2] || arrayImage[8] == arrayImage[1] || arrayImage[8] == arrayImage[0]) {
arrayImage[8] = (int)(Math.random() * 12) + 1;
}
arrayImage[9] = (int)(Math.random() * 12) + 1;
while (arrayImage[9] == arrayImage[8] || arrayImage[9] == arrayImage[7] || arrayImage[9] == arrayImage[6] || arrayImage[9] == arrayImage[5] || arrayImage[9] == arrayImage[4] || arrayImage[9] == arrayImage[3] || arrayImage[9] == arrayImage[2] || arrayImage[9] == arrayImage[1] || arrayImage[9] == arrayImage[0]) {
arrayImage[9] = (int)(Math.random() * 12) + 1;
}
arrayImage[10] = (int)(Math.random() * 12) + 1;
while (arrayImage[10] == arrayImage[9] || arrayImage[10] == arrayImage[8] || arrayImage[10] == arrayImage[7] || arrayImage[10] == arrayImage[6] || arrayImage[10] == arrayImage[5] || arrayImage[10] == arrayImage[4] || arrayImage[10] == arrayImage[3] || arrayImage[10] == arrayImage[2] || arrayImage[10] == arrayImage[1] || arrayImage[10] == arrayImage[0]) {
arrayImage[10] = (int)(Math.random() * 12) + 1;
}
arrayImage[11] = (int)(Math.random() * 12) + 1;
while (arrayImage[11] == arrayImage[10] || arrayImage[11] == arrayImage[9] || arrayImage[11] == arrayImage[8] || arrayImage[11] == arrayImage[7] || arrayImage[11] == arrayImage[6] || arrayImage[11] == arrayImage[5] || arrayImage[11] == arrayImage[4] || arrayImage[11] == arrayImage[3] || arrayImage[11] == arrayImage[2] || arrayImage[11] == arrayImage[1] || arrayImage[11] == arrayImage[0]) {
arrayImage[11] = (int)(Math.random() * 12) + 1;
}
for (int x = 0; x <= 11; x++) {
buttonArray[x] = new JButton("" + arrayImage[x]);
buttonArray[x].setBackground(Color.orange);
}
for (int i = 0; i <= 11; i++) {
buttonArray[i].setActionCommand("" + arrayImage[i]);
}
return buttonArray;
}
private static void guiApp() {
start = new JFrame("Welcome");
start.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
questions = new JFrame("Memry_Game");
questions.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
survey = new JFrame("How Was It?");
survey.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
btnStart = new JButton("Enter");
lblTitle = new JLabel("Memory Match Game!");
lblInstruct = new JLabel("Welcome to the Memory Match Game!");
lblPrompt1 = new JLabel("Please enter your first name:");
lblPrompt2 = new JLabel("Choose Difficulty (#of seconds):");
nameEnter = new JTextField("");
scoreOutput = new JLabel("Score: " + score + "/15");
reallyBad = new JRadioButton("Really Bad");
bad = new JRadioButton("Bad");
good = new JRadioButton("Good");
reallyGood = new JRadioButton("Really Good");
lblReadyCheck = new JLabel("");
finalSurvey = new ButtonGroup();
finalSurvey.add(reallyBad);
finalSurvey.add(bad);
finalSurvey.add(good);
finalSurvey.add(reallyGood);
//Declare Audio
/*URL ebob = JavaMemoryGame_Final.class.getResource ("");
clap = Applet.newAudioClip (ebob);
URL bob = JavaMemoryGame_Final.class.getResource ("yes-1.wav");
yess = Applet.newAudioClip (bob);
URL tom = JavaMemoryGame_Final.class.getResource ("no-6.wav");
noo = Applet.newAudioClip (tom);*/
//set up radio buttons
finalSurvey = new ButtonGroup();
finalSurvey.add(reallyBad);
finalSurvey.add(bad);
finalSurvey.add(good);
finalSurvey.add(reallyGood);
//Set Up List Model
listModel = new DefaultListModel();
listModel.addElement("10");
listModel.addElement("15");
listModel.addElement("30");
//Set Up List
difficulty = new JList(listModel);
difficulty.setVisibleRowCount(1);
JScrollPane listScroll = new JScrollPane(difficulty);
for (int x = 0; x <= 11; x++) {
buttonArray[x] = new JButton("");
buttonArray[x].setBackground(Color.orange);
}
ButtonHandler onClick = new ButtonHandler();
btnStart.addActionListener(onClick);
for (int y = 0; y <= 11; y++) {
buttonArray[y].addActionListener(onClick);
}
JPanel mainStart = new JPanel(new BorderLayout());
mainStart.setBackground(Color.orange);
mainStart.setForeground(Color.orange);
JPanel scoreStuffs = new JPanel(new GridLayout(1, 2));
JPanel mainContent = new JPanel(new GridLayout(2, 2));
mainContent.setBackground(Color.orange);
mainStart.setForeground(Color.orange);
JPanel gameBoard = new JPanel(new GridLayout(2, 6));
gameBoard.setBackground(Color.orange);
JPanel gameContent = new JPanel(new GridLayout(1, 2));
JPanel mainGame = new JPanel(new BorderLayout());
mainGame.setBackground(Color.orange);
JPanel buttonScore = new JPanel(new GridLayout(3, 1));
buttonScore.setBackground(Color.orange);
JPanel feedbackPanel = new JPanel(new BorderLayout());
feedbackPanel.setForeground(Color.blue);
//Seperate Panels
mainContent.add(lblPrompt1);
mainContent.add(lblPrompt2);
mainContent.add(nameEnter);
mainContent.add(listScroll);
//Score Stuff for main Panel
scoreStuffs.add(scoreOutput);
scoreStuffs.add(btnStart);
//Main Welcome PAnel
mainStart.add(lblInstruct, BorderLayout.NORTH);
mainStart.add(mainContent, BorderLayout.CENTER);
mainStart.add(scoreStuffs, BorderLayout.SOUTH);
//GAme Board
gameContent.add(btnStart);
gameContent.add(scoreOutput);
gameBoard.add(buttonArray[0]);
gameBoard.add(buttonArray[1]);
gameBoard.add(buttonArray[2]);
gameBoard.add(buttonArray[3]);
gameBoard.add(buttonArray[4]);
gameBoard.add(buttonArray[5]);
gameBoard.add(buttonArray[6]);
gameBoard.add(buttonArray[7]);
gameBoard.add(buttonArray[8]);
gameBoard.add(buttonArray[9]);
gameBoard.add(buttonArray[10]);
gameBoard.add(buttonArray[11]);
mainGame.add(gameBoard, BorderLayout.CENTER);
mainGame.add(gameContent, BorderLayout.PAGE_END);
Container contentPane = start.getContentPane();
contentPane.add(mainStart);
Container contentPane1 = questions.getContentPane();
contentPane1.add(mainGame);
Container contentPane2 = survey.getContentPane();
contentPane2.add(feedbackPanel);
start.setSize(600, 450);
start.setVisible(true);
questions.setSize(500, 250);
questions.setVisible(true);
survey.setSize(600, 450);
survey.setVisible(true);
}
private static class ButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
String textFieldValue = nameEnter.getText();
int index = difficulty.getSelectedIndex();
int selected = difficulty.getSelectedValue().toInt();
int check = 0;
while (check == 0) {
if (e.getSource() == ("Enter") && textFieldValue.length() != 0 && index > 0) {
lblPrompt1.setText("Thank You!");
lblPrompt2.setText("Thank You!");
btnStart.setText("Start?");
check = check + 1;
} else if (e.getSource() == ("Enter") && textFieldValue.length() == 0) {
lblPrompt1.setText("Enter first name before continuing!");
btnStart.setText("Check");
}
}
if (e.getSource() == ("Start?")) {
start.setVisible(false);
questions.setVisible(true);
}
}
}
public void startTask() {
timer.schedule(new PeriodicTask(), 0);
}
private class PeriodicTask extends TimerTask {@
Override
public void run() {
System.out.println(System.currentTimeMillis() + " Running");
/* replace with the actual task */
try {
Thread.sleep(15 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
/* end task processing */
System.out.println(System.currentTimeMillis() + " Scheduling 10 seconds from now");
timer.schedule(new PeriodicTask(), 10 * 1000);
}
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
guiApp();
}
}
);
} // main method
} // TryTryTryAgain class
基本上我所做的是:
- 在文档目录中定义文件路径
Error Domain=NSCocoaErrorDomain Code=3587 "dlopen_preflight(/var/mobile/Containers/Data/Application/35F71C99-1072-4772-8BFB-3CB8C034A935/Documents/grandmaAdapter.bundle/grandmaAdapter): no suitable image found. Did find:
/var/mobile/Containers/Data/Application/35F71C99-1072-4772-8BFB-3CB8C034A935/Documents/grandmaAdapter.bundle/grandmaAdapter: mmap() error 1 at address=0x022CF000, size=0x00008000 segment=__TEXT in Segment::map() mapping /var/mobile/Containers/Data/Application/35F71C99-1072-4772-8BFB-3CB8C034A935/Documents/grandmaAdapter.bundle/grandmaAdapter" UserInfo={NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=/var/mobile/Containers/Data/Application/35F71C99-1072-4772-8BFB-3CB8C034A935/Documents/grandmaAdapter.bundle/grandmaAdapter, NSLocalizedFailureReason=The bundle is damaged or missing necessary resources., NSLocalizedDescription=The bundle “grandmaAdapter” couldn’t be loaded because it is damaged or missing necessary resources., NSDebugDescription=dlopen_preflight(/var/mobile/Containers/Data/Application/35F71C99-1072-4772-8BFB-3CB8C034A935/Documents/grandmaAdapter.bundle/grandmaAdapter): no suitable image found. Did find:
/var/mobile/Containers/Data/Application/35F71C99-1072-4772-8BFB-3CB8C034A935/Documents/grandmaAdapter.bundle/grandmaAdapter: mmap() error 1 at address=0x022CF000, size=0x00008000 segment=__TEXT in Segment::map() mapping /var/mobile/Containers/Data/Application/35F71C99-1072-4772-8BFB-3CB8C034A935/Documents/grandmaAdapter.bundle/grandmaAdapter, NSBundlePath=/var/mobile/Containers/Data/Application/35F71C99-1072-4772-8BFB-3CB8C034A935/Documents/grandmaAdapter.bundle}
- 然后加载包
NSString *bundleName = [NSString stringWithFormat:@"%@.bundle", bundle];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
filePath = [documentsDirectory stringByAppendingPathComponent:bundleName];
在这里我得到了上面的错误
有人可以帮助我吗?感谢
解决
错误与缺少代码签名有关。 正如本文所述:http://ddeville.me/2014/04/dynamic-linking/ 需要对插件进行签名,以便使用以下命令加载到实际设备上:
NSBundle *plugin = [[NSBundle alloc] initWithPath:filePath];
NSError *err;
if(![plugin loadAndReturnError:&err]) {
// err contains error info
} else {
// bundle loaded properly
}
答案 0 :(得分:0)
您的捆绑加载代码看起来不错,直到loadAndReturnError:
。在弄清楚如何加载包时,我遇到了同样的错误。
我知道这听起来很反直觉,但你不需要调用那种方法。相反,请尝试以下方法。
我希望这有帮助!如果您仍然遇到错误,那么问题可能在于您创建捆绑包的方式。
UIView *resourceView = nil;
NSBundle *resourceBundle = [NSBundle bundleWithPath:resourcePath];
@try {
//Try to load the NIB from the given bundle
resourceView = [[resourceBundle loadNibNamed:nibName owner:owner options:nil] lastObject];
}
@catch (NSException *exception) {
//do nothing - will search in main bundle
}
//If loading from the given bundle failed, try loading from the main bundle
if (!resourceView) {
NSBundle *resourceBundle = [NSBundle mainBundle];
@try {
resourceView = [[resourceBundle loadNibNamed:nibName owner:owner options:nil] lastObject];
}
@catch (NSException *exception) {
//do nothing - will return nil, indicating an error occurred
}
}
return resourceView;
谨慎之词
在走这条路之前,请务必注意,您确实需要创建捆绑包的唯一原因是添加XIB文件。对于任何其他资产,例如图像,音频或视频文件,只需简单压缩文件并从服务器位置下载它们就可以解压缩到文档目录中。(/ p>
如果您需要更新XIB使用的资产,则最好以编程方式加载这些资源,而不是在XIB中设置它们(或者除了在XIB中设置默认值之外)。这样,您就可以免于使用捆绑方法,而是使用上面提到的压缩存档。