我想从包名中获取一个图标。包名称通过套接字传递给我。我正在获取包名称并尝试使用它来获取图标,但它正在抛出异常。我从来没有得到图标的print语句。有什么想法吗?
require 'aws-sdk'
require 'json'
client = Aws::EC2::Client.new
instances = ['i-instanceone', 'i-instancetwo']
volumes = client.describe_volumes({
filters: [{
name: 'attachment.instance-id',
values: instances
}]
}).volumes
list = volumes.flat_map(&:attachments).each_with_object(Hash.new {|k,v| k[v] = {}}) do |vol, hsh|
hsh[vol.instance_id][vol.volume_id] = {
device: vol.device,
attach_time: vol.attach_time
}
end
puts JSON.pretty_generate(list)
# {
# "i-instanceone": {
# "vol-one": {
# "device": "/dev/sda1",
# "attach_time": "2015-02-25 14:24:23 UTC"
# }
# },
# "i-instancetwo": {
# "vol-two": {
# "device": "/dev/sda1",
# "attach_time": "2015-04-27 13:08:14 UTC"
# },
# "vol-three": {
# "device": "/dev/xvdf",
# "attach_time": "2016-04-10 14:45:15 UTC"
# }
# }
# }
抛出的异常是这样的:现在我的例外,当我想要" Iso Mounter"的图标时app,是:
try {
Socket socket = new Socket("192.170.10.15", 5050);
DataInputStream DIS = new DataInputStream(socket.getInputStream());
String packagename = DIS.readUTF();
System.out.println("package name" + packagename);
Drawable icon = getPackageManager().getApplicationIcon(packagename);
System.out.println("icon" + icon);
socket.close();
} catch (Exception e) {
System.out.println("Did not receive string");
}