Unable to find explicit activity class
关键是我在AndroidManifest.xml中已经把活动声明
(1)
用的类(Settings)是一个系统定义过得类,将之改为其他名字
(2)
查看 在AndroidManifest.xml的application声明 是否一致,大小写
(3)
activity嵌套错误
<activity>
<activity><activity/>
<activity/>
(4)
不是activity 或者没继承activity
(5)
以上方法都没用,关闭avd,重启
使用数组对象创建的数组功能非常强大,在Java语言或者C语言中定义的数组必须满足数组中的每一个元素必须是同样的类型。
而Objective-C语言可以在Array数组中放任意类型的objective-c的对象。有两点值得注意,一是只能放指向这个对象的指针,而不能直接放int ,char,double 等等;二是不能放nil。
使用NSArray关键字创建一个不可变的数组,一旦初始化完毕后这个数组的元素是不可以再动态地添加和删除。
[array count] : 得到这个对象数组的长度。
[array objectAtIndex:0]: 传入数组脚标的id 得到数据对象。
[array arrayWithObjects:xx,xx,xx,nil] :向数组对象初始化赋值。这里可以写任意对象的指针,结尾必须使用nil,标识为数组定义结束。
+ (id)array
WithObjects
:(id)firstObject, ...; //
nil
terminated
- (int)count;
- (id)objectAtIndex:(int)index; //
NSString *s1=[[myarray objectAtIndex: 0];
- (void)makeObjectsPerformSelector:(SEL)aSelector;
- (NSArray *)sortedArrayUsingSelector:(SEL)aSelector;
- (id)lastObject; // returns nil if there are no objects in the array (convenient)
NSArray *arr=[NSArray arrayWithObjects:@"one xiaowang",@"two xiaoli",@"three xiaotian",nil]; NSLog(@"arr count = %d ,%@",[arr count],[arr objectAtIndex:0]);
遍历数组中对象的方法有两种,一种称为普通遍历;另一种称为快速枚举遍历。
但apple认为前者效率低下且安全性不高,推荐使用后者即快速枚举法。
普通遍历方法
for (int i=0;i<[arr count];i++) { NSLog(@"普通遍历:i = %d 时的数组对象为: %@",i,[arr objectAtIndex: i]); }
快速枚举遍历方法
for (NSObject *object in arr) { NSLog(@"快速枚举遍历数组对象为: %@",object); }
动态可变数组的管理方式和不可变数组类似。
NSMutableArray * arr=[NSMutableArray arrayWithCapacity:10]; [arr addObject:@"xiaoli"]; [arr addObject:@"xiaowang"]; [arr addObject:@"xiaotian"]; NSLog(@"arr count = %d ,%@",[arr count],[arr objectAtIndex:0]); for (int i=0;i<[arr count];i++) { NSLog(@"普通遍历:i = %d 时的数组对象为: %@",i,[arr objectAtIndex: i]); } [arr removeObjectAtIndex:1]; for (NSObject *object in arr) { NSLog(@"快速枚举遍历数组对象为: %@",object); }
字典类的对象是使用方式同数组也类似
主要的方法为
- (id)objectForKey:(id)key;
- (NSArray *)allKeys;
- (NSArray *)allValues;
- (void)removeObjectForKey:(id)key;
- (void)addEntriesFromDictionary:(NSDictionary *)otherDictionary;
NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:@"name1",@"key1",@"name2",@"key2",nil]; for (NSString * str_key in [dict allKeys]) { NSLog(@"key is %@",str_key); } for (NSString * str_val in [dict allValues]) { NSLog(@"value is %@",str_val); } NSLog(@"value is %@ at %@",[dict objectForKey:@"key1"],@"key1"); NSMutableDictionary *dict2=[NSMutableDictionary dictionaryWithCapacity:10]; [dict2 setObject:@"name1" forKey:@"key1"]; NSLog(@"dict2 value is %@ at %@",[dict2 objectForKey:@"key2"],@"key2"); [dict2 setObject:@"name2" forKey:@"key2"]; NSLog(@"dict2 value is %@ at %@",[dict2 objectForKey:@"key2"],@"key2");
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import com.sun.image.codec.jpeg.ImageFormatException;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class DownLoadImg {
/**
* @param args
*/
public static void main(String[] args) {
String urlFilePath = "http://mt1.google.cn/vt/v=w2.114&hl=zh-CN&gl=cn&x=1&y=1&z=1";
// String urlFilePath = "http://www.google.cn/intl/zh-CN/images/logo_cn.gif";
String fileFolder = "F:/Google/";
String fileName = "google.png";
String filePath = fileFolder + fileName;
makeDir(fileFolder);
try {
getImageFromUrl(/blog_article/urlFilePath, filePath,1/index.html);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("\n >>> IMAGE DOWNLOAD DONE! <<<\n");
openFileSystemDir(fileFolder);
}
private static void getImageFromUrl(/blog_article/String url, String newFilePath, int sizeReduceRank/index.html)
throws MalformedURLException, IOException {
if (url == null)
return;
URL u = new URL(/blog_article/url/index.html);
// 打开连接
URLConnection con = u.openConnection();
// 设置Java服务器代理连接,要不然报错403
// 浏览器可以访问此url图片并显示,但用Java程序就不行报错Server returned HTTP response code:403 for URL
// 具体原因:服务器的安全设置不接受Java程序作为客户端访问(被屏蔽),解决办法是设置客户端的User Agent
con.setRequestProperty("User-Agent", "Mozilla/4.0(compatible;MSIE 5.0;Windows NT;DigExt)");
// 输入流
InputStream is = con.getInputStream();
Image image = javax.imageio.ImageIO.read(is);
// Image image = javax.imageio.ImageIO.read(new URL(/blog_article/url/index.html));
int width = image.getWidth(null) / sizeReduceRank;
int height = image.getHeight(null) / sizeReduceRank;
// 更改图片大小 sizeRank是原图的缩小的比例 若为2意思为将下载的文件保存为原理图片长宽的1/2
BufferedImage bufferedImage = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
bufferedImage.getGraphics().drawImage(image, 0, 0, width, height, null);
FileOutputStream out = new FileOutputStream(newFilePath);
encode(out, bufferedImage);
out.close();
}
protected static void encode(FileOutputStream out, BufferedImage bufferedImage)
throws ImageFormatException, IOException {
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(bufferedImage);
}
private static void makeDir(String fileFolder) {
File file = new File(fileFolder);
if (!file.exists() && !file.isDirectory())
file.mkdir();
}
private static void openFileSystemDir(String dir) {
String openDirCmdString = "cmd.exe /c start ";
String openDirCmd = openDirCmdString + dir;
System.out.println(openDirCmd);
try {
Runtime r = Runtime.getRuntime();
Process p = r.exec(openDirCmd);
BufferedReader bf = new BufferedReader(new InputStreamReader(
p.getInputStream()));
String line = "";
while ((line = bf.readLine()) != null)
System.out.println(line);
} catch (Exception e) {
e.printStackTrace();
}
}
}