@@ -970,6 +970,8 @@ protected void rebuildSketchbookMenu(JMenu menu) {
970
970
}
971
971
972
972
public Map <String , File > getIDELibs () {
973
+ if (libraries == null )
974
+ return new HashMap <String , File >();
973
975
Map <String , File > ideLibs = new HashMap <String , File >(libraries );
974
976
for (String lib : libraries .keySet ()) {
975
977
if (FileUtils .isSubDirectory (getSketchbookFolder (), libraries .get (lib )))
@@ -979,6 +981,8 @@ public Map<String, File> getIDELibs() {
979
981
}
980
982
981
983
public Map <String , File > getUserLibs () {
984
+ if (libraries == null )
985
+ return new HashMap <String , File >();
982
986
Map <String , File > userLibs = new HashMap <String , File >(libraries );
983
987
for (String lib : libraries .keySet ()) {
984
988
if (!FileUtils .isSubDirectory (getSketchbookFolder (), libraries .get (lib )))
@@ -1002,34 +1006,37 @@ public void actionPerformed(ActionEvent e) {
1002
1006
importMenu .add (addLibraryMenuItem );
1003
1007
1004
1008
// Split between user supplied libraries and IDE libraries
1005
- Map <String , File > ideLibs = getIDELibs ();
1006
- Map <String , File > userLibs = getUserLibs ();
1007
- try {
1008
- // Find the current target. Get the platform, and then select the
1009
- // correct name and core path.
1010
- PreferencesMap prefs = getTargetPlatform ().getPreferences ();
1011
- String targetname = prefs .get ("name" );
1012
-
1013
- if (false ) {
1014
- // Hack to extract these words by gettext tool.
1015
- // These phrases are actually defined in the "platform.txt".
1016
- String notused = _ ("Arduino AVR Boards" );
1017
- notused = _ ("Arduino ARM (32-bits) Boards" );
1018
- }
1009
+ TargetPlatform targetPlatform = getTargetPlatform ();
1010
+ if (targetPlatform != null ) {
1011
+ Map <String , File > ideLibs = getIDELibs ();
1012
+ Map <String , File > userLibs = getUserLibs ();
1013
+ try {
1014
+ // Find the current target. Get the platform, and then select the
1015
+ // correct name and core path.
1016
+ PreferencesMap prefs = targetPlatform .getPreferences ();
1017
+ String targetname = prefs .get ("name" );
1018
+
1019
+ if (false ) {
1020
+ // Hack to extract these words by gettext tool.
1021
+ // These phrases are actually defined in the "platform.txt".
1022
+ String notused = _ ("Arduino AVR Boards" );
1023
+ notused = _ ("Arduino ARM (32-bits) Boards" );
1024
+ }
1019
1025
1020
- JMenuItem platformItem = new JMenuItem (_ (targetname ));
1021
- platformItem .setEnabled (false );
1022
- importMenu .add (platformItem );
1023
- if (ideLibs .size ()>0 ) {
1024
- importMenu .addSeparator ();
1025
- addLibraries (importMenu , ideLibs );
1026
- }
1027
- if (userLibs .size ()>0 ) {
1028
- importMenu .addSeparator ();
1029
- addLibraries (importMenu , userLibs );
1026
+ JMenuItem platformItem = new JMenuItem (_ (targetname ));
1027
+ platformItem .setEnabled (false );
1028
+ importMenu .add (platformItem );
1029
+ if (ideLibs .size () > 0 ) {
1030
+ importMenu .addSeparator ();
1031
+ addLibraries (importMenu , ideLibs );
1032
+ }
1033
+ if (userLibs .size () > 0 ) {
1034
+ importMenu .addSeparator ();
1035
+ addLibraries (importMenu , userLibs );
1036
+ }
1037
+ } catch (IOException e ) {
1038
+ e .printStackTrace ();
1030
1039
}
1031
- } catch (IOException e ) {
1032
- e .printStackTrace ();
1033
1040
}
1034
1041
}
1035
1042
@@ -1132,11 +1139,15 @@ public File scanFatLibrary(File libFolder) {
1132
1139
}
1133
1140
1134
1141
public void onBoardOrPortChange () {
1142
+ TargetPlatform targetPlatform = getTargetPlatform ();
1143
+ if (targetPlatform == null )
1144
+ return ;
1145
+
1135
1146
// Calculate paths for libraries and examples
1136
1147
examplesFolder = getContentFile ("examples" );
1137
1148
toolsFolder = getContentFile ("tools" );
1138
1149
1139
- File platformFolder = getTargetPlatform () .getFolder ();
1150
+ File platformFolder = targetPlatform .getFolder ();
1140
1151
librariesFolders = new ArrayList <File >();
1141
1152
librariesFolders .add (getContentFile ("libraries" ));
1142
1153
librariesFolders .add (new File (platformFolder , "libraries" ));
@@ -1400,6 +1411,9 @@ public void actionPerformed(ActionEvent actionevent) {
1400
1411
*/
1401
1412
protected boolean addSketches (JMenu menu , File folder ,
1402
1413
final boolean replaceExisting ) throws IOException {
1414
+ if (folder == null )
1415
+ return false ;
1416
+
1403
1417
// skip .DS_Store files, etc (this shouldn't actually be necessary)
1404
1418
if (!folder .isDirectory ()) return false ;
1405
1419
@@ -1846,7 +1860,10 @@ static public TargetPlatform getTargetPlatform() {
1846
1860
*/
1847
1861
static public TargetPlatform getTargetPlatform (String packageName ,
1848
1862
String platformName ) {
1849
- return packages .get (packageName ).get (platformName );
1863
+ TargetPackage p = packages .get (packageName );
1864
+ if (p == null )
1865
+ return null ;
1866
+ return p .get (platformName );
1850
1867
}
1851
1868
1852
1869
static public TargetPlatform getCurrentTargetPlatformFromPackage (String pack ) {
0 commit comments