当前位置:首页 » 操作系统 » the7源码

the7源码

发布时间: 2023-04-02 09:10:21

1. Struts的资源文件时如何初始化的--struts源码学习 - 轮上飞 - BlogJa...

[2]系统是如何启动和初始化struts的在Web.xml中有这么一段代码: action org.apache.struts.action.ActionServlet config /WEB-INF/struts-config.xml debug 3 detail 3 0 startThread com.cgogo.ypindex.StartThread startParam 2 1 action *.do 在web.xml中会配置struts的中央控制器类。Web.xml配置文件的初始化是由容器来实现载入和初始化的。如果你使用的是知凳tomcat的话,那么就是由tomcat在启动的时候会载入此web.xml文件,也就为此web应用创建了一个web Context,此context也就是你Web应用的访问入口。载入中央控制器org.apache.struts.action.ActionServlet,这是一个Servlet,那么,其就要进行蚂判servlet的初始化操作。此action是如何对Struts系统进行初始化的呢?[3]init()--ActionServlet如何初始化Struts系统?看一下ActionServlet的源代码:我们知道,在一个Servlet中,在其启动的时候,首先要执行init()方法,那么我们搭物旅先来看一下actionServlet的init()方法的源代码: /** * Initialize this servlet. Most of the processing has been factored into * support methods so that you can override particular functionality at a * fairly granular level. * * @exception ServletException if we cannot configure ourselves correctly */ public void init() throws ServletException { // Wraps the entire initialization in a try/catch to better handle // unexpected exceptions and errors to provide better feedback // to the developer try {(1) initInternal();(2) initOther();(3) initServlet(); getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this);(4) initMoleConfigFactory(); // Initialize moles as needed MoleConfig moleConfig = initMoleConfig("", config);(5) initMoleMessageResources(moleConfig);(6) initMoleDataSources(moleConfig);(7) initMolePlugIns(moleConfig); moleConfig.freeze();(8) 初始化配置参数 Enumeration names = getServletConfig().getInitParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); if (!name.startsWith("config/")) { continue; } String prefix = name.substring(6); moleConfig = initMoleConfig (prefix, getServletConfig().getInitParameter(name)); initMoleMessageResources(moleConfig); initMoleDataSources(moleConfig); initMolePlugIns(moleConfig); moleConfig.freeze(); } this.initMolePrefixes(this.getServletContext()); this.destroyConfigDigester(); } catch (UnavailableException ex) { throw ex; } catch (Throwable t) { // The follow error message is not retrieved from internal message // resources as they may not have been able to have been // initialized log.error("Unable to initialize Struts ActionServlet e to an " + "unexpected exception or error thrown, so marking the " + "servlet as unavailable. Most likely, this is e to an " + "incorrect or missing library dependency.", t); throw new UnavailableException(t.getMessage()); } } 先来看一下初始化(1)的部分initInternal()。 [4] initInternal()--内部资源文件的初始化initInternal()就是实现内部资源文件的初始化的,也就是转为Struts系统本身提供的以下错误信息提示等文字的国际化实现的。我们看一下源代码是如何实现的: /** *. * *@ */ protectedvoidinitInternal() throwsServletException { // :FIXME: Document UnavailableException try{ internal= MessageResources.getMessageResources(internalName); } catch(MissingResourceException e) { log.error("Cannot load internal resources from ‘"+ internalName+ "‘", e); thrownewUnavailableException ("Cannot load internal resources from ‘"+ internalName+ "‘"); } }Struts根据配置文件的名字得到一个资源文件。internalName就是内部资源文件的名称,其在actionServlet中定义: /** *. *@sinceStruts1.1 */ protectedString internalName= "org.apache.struts.action.ActionResources";取得后的对象是一个MessageResources的对象,保存在internal中, /** * The resources object for our internal resources. */ protected MessageResources internal = null;经过此初始化后,internal就不在是null了。至此就实现完成了内部资源文件的初始化。 /** * Initialize other global characteristics of the controller servlet. * * @exception ServletException if we cannot initialize these resources */ protected void initOther() throws ServletException { String value = null; value = getServletConfig().getInitParameter("config"); if (value != null) { config = value; } // Backwards compatibility for form beans of java wrapper classes // Set to true for strict Struts 1.0 compatibility value = getServletConfig().getInitParameter("convertNull"); if ("true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value) || "on".equalsIgnoreCase(value) || "y".equalsIgnoreCase(value) || "1".equalsIgnoreCase(value)) { convertNull = true; } if (convertNull) { ConvertUtils.deregister(); ConvertUtils.register(new BigDecimalConverter(null), BigDecimal.class); ConvertUtils.register(new BigIntegerConverter(null), BigInteger.class); ConvertUtils.register(new BooleanConverter(null), Boolean.class); ConvertUtils.register(new ByteConverter(null), Byte.class); ConvertUtils.register(new CharacterConverter(null), Character.class); ConvertUtils.register(new DoubleConverter(null), Double.class); ConvertUtils.register(new FloatConverter(null), Float.class); ConvertUtils.register(new IntegerConverter(null), Integer.class); ConvertUtils.register(new LongConverter(null), Long.class); ConvertUtils.register(new ShortConverter(null), Short.class); } }然后就执行(3)initServlet(); [6] initServlet()--如何初始化servlet这个初始化主要是初始化servlet的,哪些servlet呢? /** * Initialize the servlet mapping under which our controller servlet * is being accessed. This will be used in the &html:form * tag to generate correct destination URLs for form submissions. * * @throws ServletException if error happens while scanning web.xml */ protected void initServlet() throws ServletException { // Remember our servlet name //这里保存当前的servlet名字,保存在actionServlet的servletName属性中 this.servletName = getServletConfig().getServletName(); // Prepare a Digester to scan the web application deployment descriptor Digester digester = new Digester(); digester.push(this); digester.setNamespaceAware(true); digester.setValidating(false); // Register our local of the DTDs that we can find for (int i = 0; i < registrations.length; i += 2) { URL url = this.getClass().getResource(registrations[i+1]); if (url != null) { digester.register(registrations[i], url.toString()); } } // Configure the processing rules that we need digester.addCallMethod("web-app/servlet-mapping", "addServletMapping", 2); digester.addCallParam("web-app/servlet-mapping/servlet-name", 0); digester.addCallParam("web-app/servlet-mapping/url-pattern", 1); // Process the web application deployment descriptor if (log.isDebugEnabled()) { log.debug("Scanning web.xml for controller servlet mapping"); } //取得当前的配置文件 InputStream input = getServletContext().getResourceAsStream("/WEB-INF/web.xml"); if (input == null) { log.error(internal.getMessage("configWebXml")); throw new ServletException(internal.getMessage("configWebXml")); } try { //解析当前配置文件digester.parse(input); } catch (IOException e) { log.error(internal.getMessage("configWebXml"), e); throw new ServletException(e); } catch (SAXException e) { log.error(internal.getMessage("configWebXml"), e); throw new ServletException(e); } finally { try { //

2. 求C++小游戏源代码啊~

一个恋爱小测试贼灵验哦
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,a,b,c,d,e,f,g,h,i,j,k,l,sum;
cout<<"欢迎来到恋爱指数测试器*>-<*"<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
cout<<"独家的哦*^0^*"<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
cout<<"以下异性均为合适年龄"<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
cout<<"下列问题如果是则输入2,如果不是则输入1,一点也没感觉输入0"<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
cout<<"加油,面对你自己!*-o-*"<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
cout<<"question one:"<<"你是否面对异性时有莫名心跳?"<<endl;
cin>>n;
cout<<endl;
cout<<"question two:"<<"你是否有看到异性被撩时很愤怒?"<<endl;
cin>>m;
cout<<endl;
cout<<"question three:"<<"你是否惧怕见到一位异性的家长"<<endl;
cin>>a;
cout<<endl;
cout<<"question four:"<<"你是否经常刷一位异性的QQ或其他软件"<<endl;
cin>>b;
cout<<endl;
cout<<"question five:"<<"想不想真心和Ta用情头?"<<endl;
cin>>c;
cout<<endl;
cout<<"question six:"<<"和Ta邂逅过吗?"<<endl;
cin>>d;
cout<<endl;
cout<<"question seven:"<<"吃过同一个饭碗里的东西吗?"<<endl;
cin>>e;
cout<<endl;
cout<<"question eight:"<<"有过一个人在梦里与Ta相遇吗?"<<endl;
cin>>f;
cout<<endl;
cout<<"question nine:"<<"有为了等Ta一个人站在风雨中吗?"<<endl;
cin>>g;
cout<<endl;
cout<<"question ten:"<<"想kissTa不,想摸Ta的头发吗?"<<endl;
cin>>h;
cout<<endl;
sum=n+m+a+b+c+d+e+f+g+h;
cout<<"正在测评中,请稍后..."<<endl;
for(int i=1;i<=1000000000;i++)
l=i;
if(sum>=16&&sum<=20)
cout<<"你的恋爱指数为:A。你是一个深深爱着Ta的人,你往往会走到最后^-^。"<<endl;
if(sum<=15&&sum>=12)
cout<<"你的恋爱指数为:B。你是一个矛盾却又不失爱意的人,你的爱往往一波三折!-!。"<<endl;
if(sum<=11&&sum>=7)
cout<<"你的恋爱指数为:C。你是一个有点点情丝的人,你想表,却又惧怕现实,你仍须努力o-o。"<<endl;
if(sum<=6&&sum>=0)
cout<<"你的恋爱指数为:D。你是一个无暇无垢,不食人间烟火的人,想一路踏歌,证道路上需佳人陪伴+-+。"<<endl;
if(sum>20||sum<0)
cout<<"你出格了哟ooo.ooo"<<endl;
cout<<"人生在世,恍如昨世,孤独的身影终难走远,你的那个Ta就在不远方,就如漫天繁星,总有一颗属于你!"<<endl;\
cout<<"快抓紧你身边的那个Ta^-^oooooo"<<endl;
cout<<endl;
cout<<"作品创造者:yang sky one"<<endl;
cout<<"恋爱指数测试器已关闭,需重启………………"<<endl;
return 0;
}

3. 源码打包apk使用RecyclerView时遇到的坑

最近在做一个系统通知栏的项目叫MsgCenter。使用Android studio开发的.
使用了脚本拷贝与复制

LIBS="/Users/love/Desktop/moran2/MsgCenter/app/libs"
SRC="/Users/love/Desktop/moran2/MsgCenter/app/src/main/java/*"
RES="/Users/love/Desktop/moran2/MsgCenter/app/src/main/res"

ANDROIDMANIFEST="app/src/main/AndroidManifest.xml"

DES="/Users/love/Desktop/moran2/MsgCenter/MsgCenter"

mkdir -p $DES/src

cp -r LIBS DES
cp -r SRC DES/src
cp -r RES DES
cp -r JNI DES
cp ANDROIDMANIFEST DES
cp ANDROIDMK DES
然后提交到服务器打包报错:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: net.imoran.notification.lib, PID: 2630
java.lang.ExceptionInInitializerError
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.getInstance(NotificationWindowManager.java:115)
at net.imoran.notification.lib.service.StarStatusService.onBind(StarStatusService.java:32)
at android.app.ActivityThread.handleBindService(ActivityThread.java:3158)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread H.handleMessage(ActivityThread.java:1582) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5795) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:834)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:724)
Caused by: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at net.imoran.notification.lib.manager.NotificationManager.initRootView(NotificationManager.java:51)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.initAdapterView(NotificationWindowManager.java:200)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.<init>(NotificationWindowManager.java:123)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.<init>(NotificationWindowManager.java:34)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager .(NotificationWindowManager.java:111) at net.imoran.notification.lib.windowmanager.NotificationWindowManager.getInstance(NotificationWindowManager.java:115) at net.imoran.notification.lib.service.StarStatusService.onBind(StarStatusService.java:32) at android.app.ActivityThread.handleBindService(ActivityThread.java:3158) at android.app.ActivityThread.-wrap2(ActivityThread.java) at android.app.ActivityThread H.handleMessage(ActivityThread.java:1582)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5795)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:834) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:724) Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView at android.view.LayoutInflater.createView(LayoutInflater.java:645) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at net.imoran.notification.lib.manager.NotificationManager.initRootView(NotificationManager.java:51) at net.imoran.notification.lib.windowmanager.NotificationWindowManager.initAdapterView(NotificationWindowManager.java:200) at net.imoran.notification.lib.windowmanager.NotificationWindowManager.(NotificationWindowManager.java:123) at net.imoran.notification.lib.windowmanager.NotificationWindowManager.(NotificationWindowManager.java:34) at net.imoran.notification.lib.windowmanager.NotificationWindowManager .<clinit>(NotificationWindowManager.java:111)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.getInstance(NotificationWindowManager.java:115)
at net.imoran.notification.lib.service.StarStatusService.onBind(StarStatusService.java:32)
at android.app.ActivityThread.handleBindService(ActivityThread.java:3158)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread H.handleMessage(ActivityThread.java:1582) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5795) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:834)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:724)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at net.imoran.notification.lib.manager.NotificationManager.initRootView(NotificationManager.java:51)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.initAdapterView(NotificationWindowManager.java:200)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.<init>(NotificationWindowManager.java:123)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.<init>(NotificationWindowManager.java:34)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager .(NotificationWindowManager.java:111) at net.imoran.notification.lib.windowmanager.NotificationWindowManager.getInstance(NotificationWindowManager.java:115) at net.imoran.notification.lib.service.StarStatusService.onBind(StarStatusService.java:32) at android.app.ActivityThread.handleBindService(ActivityThread.java:3158) at android.app.ActivityThread.-wrap2(ActivityThread.java) at android.app.ActivityThread H.handleMessage(ActivityThread.java:1582)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5795)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:834) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:724) Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/recyclerview/R styleable;
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:590)
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:551)
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at net.imoran.notification.lib.manager.NotificationManager.initRootView(NotificationManager.java:51)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.initAdapterView(NotificationWindowManager.java:200)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.<init>(NotificationWindowManager.java:123)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.<init>(NotificationWindowManager.java:34)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager .(NotificationWindowManager.java:111) at net.imoran.notification.lib.windowmanager.NotificationWindowManager.getInstance(NotificationWindowManager.java:115) at net.imoran.notification.lib.service.StarStatusService.onBind(StarStatusService.java:32) at android.app.ActivityThread.handleBindService(ActivityThread.java:3158) at android.app.ActivityThread.-wrap2(ActivityThread.java) at android.app.ActivityThread H.handleMessage(ActivityThread.java:1582)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5795)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:834) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:724) Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.recyclerview.R styleable" on path: DexPathList[[zip file "/flysystem/app/mor-notification.apk"],nativeLibraryDirectories=[/system/lib64/mor-notification, /flysystem/app/mor-notification.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:590)
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:551)
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at net.imoran.notification.lib.manager.NotificationManager.initRootView(NotificationManager.java:51)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.initAdapterView(NotificationWindowManager.java:200)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.<init>(NotificationWindowManager.java:123)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.<init>(NotificationWindowManager.java:34)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager .(NotificationWindowManager.java:111) at net.imoran.notification.lib.windowmanager.NotificationWindowManager.getInstance(NotificationWindowManager.java:115) at net.imoran.notification.lib.service.StarStatusService.onBind(StarStatusService.java:32) at android.app.ActivityThread.handleBindService(ActivityThread.java:3158) at android.app.ActivityThread.-wrap2(ActivityThread.java) at android.app.ActivityThread H.handleMessage(ActivityThread.java:1582)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5795)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:834) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:724) Suppressed: java.lang.ClassNotFoundException: android.support.v7.recyclerview.R styleable
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 28 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
07-20 14:14:31.557 2630-2664/net.imoran.notification.lib I/System: FinalizerDaemon: finalize objects = 2695

从log中我们可以看到,
1.Binary XML file line #22: Binary XML file line #39: Error inflating class android.support.v7.widget.RecyclerView

2.同时还有这样的 java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/recyclerview/R$styleable

3.Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.recyclerview.R$styleable"

一开始只注意到了第一点,于是在网络上查呀查:
就发现大家的说法就是 在eclipse或者android studio上 因为sdk的版本不match,等等的。有的人说把android.support.v7.recyclerview.jar这个包换掉,换成match的版本的就好了,但我这边因为开发方式不一样,就又断掉了。但是却让我知道了是版本的问题

后来
有的人说是
1.AndroidManifest.xml中的targetSDKVersion不对,fix -> NOK。
2.build.gradle中的某些属性不对。fix -> NOK

因为App是独立的apk,就去这5.0,6.0 andorid 的源码中去找android.support.v7.recyclerview.

同时又注意到了这两点错误
2.同时还有这样的 java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/recyclerview/R$styleable

3.Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.recyclerview.R$styleable"

从Log中我们可以看到
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:440)
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:409)
RecyclerView的409 和 440 行出错

就发现了在 frameworks/support/v7/recyclerview/src/android/support/v7/widget/RecyclerView.java中

使用到了R.styleable.RecyclerView这个属性,而第2,3点log中出现的就是R$styleable 的错误。

明确了:在android6.0版本RecyclerView类中用到了R.styleable.RecyclerView这个资源。而android5.0的版本中的RecyclerView类没用到R.styleable.RecyclerView

回到frameworks/support/v7/recyclerview/目录下就会发现
-----------5.0 没有res/ 文件夹
-----------6.0 则有

那么现在中场总结一下,因为andorid5.0中的RexyclerView类中没有使用res资源,而6.0却使用了。同时6.0的res/资源是存在的。只能说明,我们没有引用到,或者说是没有把对应的资源加载,进行编译

问题又来了:res/资源是在哪里加载的?

----------》 Android.mk 文件下有这么一段

发现了android-support-v7-recyclerview的身影

那这内容是什么意思?

1.LOCAL_STATIC_JAVA_LIBARIES 本地静态java库。
2.LOCAL_RESOURCE_DIR 本地资源文件,默认是proct package和device package下面相应的res路径和$(LOCAL_PATH)/res
3.LOCAL_AAPT_FLAGS += -c ldpi -c mdpi
上面指定了编译时打包 ldpi 和mdpi 如果系统默认的是hdpi的话,那就是这三种都会装入包中

在中场总结的时候,已经明确,是因为res资源没有加载。
所以只需要在LOCAL_RESOURCE_DIR中加上frameworks/support/v7/recyclerview/res就可以了

Android.mk文件内容变成:

再次编译,正常运行。

======================================================================================================
其实就是因为android的版本升级,RecyclerView 中的创建LayoutManager的方式发生了改变,旧版本里少了个 R.styleable.RecyclerView, 而在新环境下又没将其编译进去,故有此错。

各位少侠也可以在 package 中的res/attrs.xml 下面自己定义一个`````

总体来说将的不是很清楚, 还请大家见谅 。。

4. 求Java 日历的小程序的源代码

当在一段代码块定义一个变量时,Java就在栈中 为这个变量分配内存空间,当该变量退出该作用域后,Java会自动释放掉为该变量所分配的内存空间,该内存空间可以立即被另作他用。

Java内存分配中的堆

堆内存用来存放由new创建的对象和数组。 在堆中分配的内存,由Java虚拟机的自动垃圾回收器来管理。

5. 编译android 源码需要sdk环境吗

下面是android学习手册,可以查看编译源码,360手机助手中下载,

编译环境:ubuntu9.10,widnows平台目前不被支持。

1)安装必要的软件环境

$ sudo apt-get install git-core gnupg sun-java5-jdk flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev

官方推荐的就是上面这些,如果在编译过程中发现某些命令找不到,就apt-get它。可能需要的包还有:

$ sudo apt-get install make
$ sudo apt-get install gcc
$ sudo apt-get install g++
$ sudo apt-get install libc6-dev

$ sudo apt-get install patch
$ sudo apt-get install texinfo

$ sudo apt-get install zlib1g-dev
$ sudo apt-get install valgrind
$ sudo apt-get install python2.5(或者更高版本)

需要注意的是,官方文档说如果用sun-java6-jdk可出问题,得要用sun-java5- jdk。经测试发现,如果仅仅make(make不包括make sdk),用sun-java6-jdk是没有问题的。而make sdk,就会有问题,严格来说是在make doc出问题,它需要的javadoc版本为1.5。

因此,我们安装完sun-java6-jdk后最好再安装sun-java5-jdk,或者只安装sun-java5-jdk。这里sun-java6-jdk和sun-java5-jdk都安装,并只修改javadoc.1.gz和javadoc。因为只有这两个是make sdk用到的。这样的话,除了javadoc工具是用1.5版本,其它均用1.6版本:

$ sudo apt-get install sun-java6-jdk

修改javadoc的link:

$ cd /etc/alternatives
$ sudo rm javadoc.1.gz
$ sudo ln -s /usr/lib/jvm/java-1.5.0-sun/man/man1/javadoc.1.gz javadoc.1.gz
$ sudo rm javadoc
$ sudo ln -s /usr/lib/jvm/java-1.5.0-sun/bin/javadoc javadoc

2)设置环境变量

$ emacs ~/.bashrc

在.bashrc中新增或整合PATH变量,如下:

#java 程序开发/运行的一些环境变量

JAVA_HOME=/usr/lib/jvm/java-6-sun
JRE_HOME=${JAVA_HOME}/jre
export ANDROID_JAVA_HOME=$JAVA_HOME
export CLASSPATH=.:${JAVA_HOME}/lib:$JRE_HOME/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export JAVA_HOME;
export JRE_HOME;
export CLASSPATH;
HOME_BIN=~/bin/
export PATH=${PATH}:${JAVA_PATH}:${HOME_BIN};

保存后,同步更新:

source ~/.bashrc

3)安装repo(用来更新android源码)

创建~/bin目录,用来存放repo程序,如下:

$ cd ~
$ mkdir bin

并加到环境变量PATH中,在第2步中已经加入。

下载repo脚本并使其可执行:

$ curlhttp://android.git.kernel.org/repo>~/bin/repo
$ chmod a+x ~/bin/repo

4)初始化repo

repo是android对git的一个封装,简化了一些git的操作。

创建工程目录:

$ mkdir android
$ cd android

repo初始化:

$ repo init -u git://android.git.kernel.org/platform/manifest.git

在此过程中需要输入名字和email地址。初始化成功后,会显示:

repo initialized in /android

在~/android下会有一个.repo的隐藏目录。

5)同步源代码

$ repo sync

这一步要很久很久。

6)编译android源码,并得到~/android/out目录

$ cd ~/andoird
$ make

这一过程很久。

7)在模拟器上运行编译好的android

编译好android之后,emulator在~/android/out/host/linux-x86/bin下,ramdisk.img,system.img和userdata.img则在~/android/out/target/proct/generic下。

$ cd ~/android/out/host/linux-x86/bin

增加环境变量

$ emacs ~/.bashrc

在.bashrc中新增环境变量,如下

#java 程序开发/运行的一些环境变量

export ANDROID_PRODUCT_OUT=~/android/out/target/proct/generic
ANDROID_PRODUCT_OUT_BIN=~/android/out/host/linux-x86/bin
export PATH=${PATH}:${ANDROID_PRODUCT_OUT_BIN}:${ANDROID_PRODUCT_OUT};

最后,同步这些变化:

$ source ~/.bashrc
$ cd ~/android/out/target/proct/generic
$ emulator -system system.img -data userdata.img -ramdisk ramdisk.img

最后进入android桌面,就说明成功了。

8)编译模块

android中的一个应用程序可以单独编译,编译后要重新生成system.img。

在源码目录下执行

$ . build/envsetup.sh (.后面有空格)

就多出一些命令:

- croot: Changes directory to the top of the tree.
- m: Makes from the top of the tree.
- mm: Builds all of the moles in the current directory.
- mmm: Builds all of the moles in the supplied directories.
- cgrep: Greps on all local C/C++ files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir: Go to the directory containing a file.

可以加—help查看用法。

我们可以使用mmm来编译指定目录的模块,如编译联系人:

$ mmm packages/apps/Contacts/

编完之后生成两个文件:

out/target/proct/generic/data/app/ContactsTests.apk
out/target/proct/generic/system/app/Contacts.apk

可以使用

$ make snod

重新生成system.img,再运行模拟器。

9)编译SDK

直接执行make是不包括make sdk的。make sdk用来生成SDK,这样,我们就可以用与源码同步的SDK来开发android了。

a)修改/frameworks/base/include/utils/Asset.h

‘UNCOMPRESS_DATA_MAX = 1 * 1024 * 1024’ 改为 ‘UNCOMPRESS_DATA_MAX = 2 * 1024 * 1024’

原因是eclipse编译工程需要大于1.3M的buffer;

b)编译ADT

由于本人不使用eclipse,所以没有进行这步;

c)执行make sdk

注意,这里需要的javadoc版本为1.5,所以你需要在步骤1中同时安装sun-java5-jdk

$ make sdk

编译很慢。编译后生成的SDK存放在out/host/linux-x86/sdk/,此目录下有android-sdk_eng.xxx_linux- x86.zip和android-sdk_eng.xxx_linux-x86目录。android-sdk_eng.xxx_linux-x86就是 SDK目录。

实际上,当用mmm命令编译模块时,一样会把SDK的输出文件清除,因此,最好把android-sdk_eng.xxx_linux-x86移出来。

此后的应用开发,就在该SDK上进行,所以把7)对于~/.bashrc的修改注释掉,增加如下一行:

export PATH=${PATH}:~/android/out/host/linux-x86/sdk/android-sdk_eng.xxx_linux-x86/tools

注意要把xxx换成真实的路径;

d)关于环境变量、android工具的选择

目前的android工具有:

A、我们从网上下载的Android SDK,如果你下载过的话( tools下有许多android工具,lib/images下有img映像)
B、我们用make sdk编译出来的SDK( tools下也有许多android工具,lib/images下有img映像)
C、我们用make编译出来的out目录( tools下也有许多android工具,lib/images下有img映像)

那么我们应该用那些工具和img呢?

首先,我们一般不会用A选项的工具和img,因为一般来说它比较旧,也源码不同步。其次,也不会用C选项的工具和img,因为这些工具和img没有经过SDK的归类处理,会有工具和配置找不到的情况;事实上,make sdk产生的很多工具和img,在make编译出来out目录的时候,已经编译产生了,make sdk只是做了而已。

e)安装、配置ADT
略过;

f)创建Android Virtual Device

编译出来的SDK是没有AVD(Android Virtual Device)的,我们可以通过android工具查看:

$ android list

创建AVD:

$ android create avd -t 1 -n myavd

可以android –help来查看上面命令选项的用法。创建中有一些选项,默认就行了。

再执行android list,可以看到AVD存放的位置。

以后每次运行emulator都要加-avd myavd或@myavd选项:

$ emulator -avd myavd

10)编译linux内核映像

a)准备交叉编译工具链

android代码树中有一个prebuilt项目,包含了我们编译内核所需的交叉编译工具。

b)设定环境变量

$ emacs ~/.bashrc

增加如下两行:

export PATH=$PATH:~/android/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin
export ARCH=arm

保存后,同步变化:

$ source ~/.bashrc

c)获得合适的内核源代码

$ cd ~/android

获得内核源代码仓库

$ git clone git://android.git.kernel.org/kernel/common.git kernel
$ cd kernel
$ git branch

显示

* android-2.6.27

说明你现在在android-2.6.27这个分支上,也是kernel/common.git的默认主分支。

显示所有head分支:

$ git branch -a

显示

* android-2.6.27
remotes/origin/HEAD -> origin/android-2.6.27
remotes/origin/android-2.6.25
remotes/origin/android-2.6.27
remotes/origin/android-2.6.29
remotes/origin/android-goldfish-2.6.27
remotes/origin/android-goldfish-2.6.29

我们选取最新的android-goldfish-2.6.29,其中goldfish是android的模拟器模拟的CPU。

$ git checkout -b android-goldfish-2.6.29 origin/android-goldfish-2.6.29
$ git branch

显示

android-2.6.27
* android-goldfish-2.6.29

我们已经工作在android-goldfish-2.6.29分支上了。

d)设定交叉编译参数

打开kernel目录下的Makefile文件,把CROSS_COMPILE指向刚才下载的prebuilt中的arm-eabi编译器.

CROSS_COMPILE ?= arm-eabi-

LDFLAGS_BUILD_ID = $(patsubst -Wl$(comma)%,%,
$(call ld-option, -Wl$(comma)–build-id,))

这一行注释掉,并且添加一个空的LDFLAGS_BUILD_ID定义,如下:

LDFLAGS_BUILD_ID =

e)编译内核映像

$ cd ~/android/kernel
$ make goldfish_defconfig
$ make

f)测试生成的内核映像

$ emulator -avd myavd -kernel ~/android/kernel/arch/arm/boot/zImage

6. 新人求教 驱动源码编译安装

1、安装scons
(1) 下载python2.7, 使用x86_32位,因为scons只有32位安装包可用;
(2) 下载scons2.3.0;
(3) 安装python 和 scons, 将C:\Python27\Scripts写入PATH;
(4) 下载安装pywin32 ,It is recommended you install pywin32 if you want to do parallel builds (scons -j)

2、安装boost库(1.49版本).
解压后双击bootstrap.bat,生成bjam.exe后,cd到目录c:\boost下,(将boost_1_49更名为boost了)编译boost。
编译命令:C:\boost>bjam variant=release --with-filesystem --with-thread --with-date_time --with-program_options threading=multi toolset=msvc-10.0 link=static runtime-link=static address-model=32
这是使用VS2010环境编译的release版本,编译完成后,生成C:\boost\stage\lib文件夹,下面有6个lib库:

如果要编译成debug版本,使用命令:bjam variant=debug --with-filesystem --with-thread --with-date_time --with-program_options threading=multi toolset=msvc-10.0 link=static runtime-link=static address-model=32

编译完成后,生成C:\boost\stage\lib文件夹,下面有10个lib库和dll:

此处为MongoDB文档中对于编译boost库的要求原文:
When using bjam, MongoDB expects
variant=debug for debug builds, and variant=release for release builds
threading=multi
link=static runtime-link=static for release builds
address-model=64 for 64 bit(64位的话,把32换为64)。link=static runtime-link=static,boost需要编译成静态库,因为mongodb只会去链接boost的静态库
address-model=64在win7 64环境下此项必须,不加在编译mongodb的c++ client时会出现链接错误。

3、下载mongo2.4.6源码 http://www.mongodb.org/downloads官网下载
编译Mongoclient.lib

cmd命令提示符下,cd到解压后的文件目录,例如我放在了E盘,E:\mongodb-src-r2.4.6,输入命令:
scons –-dd --32 mongoclient.lib // build C++ client driver library
Add --64 or --32 to get the 64- and 32-bit versions, respectively. Replace --release with --dd to build a debug build.
编译后在mongodb\build\win32\32\dd\client_build\生成mongoclient.lib.

4、测试程序
就用Mongodb自带的例子吧,使用VS2010打开E:\mongodb-src-r2.4.6\src\mongo\client\examples中的simple_client_demo.vcxproj,编译,会提示生成simple_client_demo.sln,保存。
使用debug模式,配置工程环境:打开工程->属性,配置Configuration Properties下的VC++ Directories,头文件路径添加C:\boost,Lib库路径添加boost的lib,以及mongodb client的lib:
C:\boost\stage\lib

E:\mongodb-src-r2.4.6\build\win32\32\dd\client_build
进入C/C++下面的Code Generation,将Runtime Library设置为Multi-threaded Debug (/MTd)
进入Linker下面的Input,设置Additional Dependencies,添加ws2_32.lib,psapi.lib,Dbghelp.lib,mongoclient.lib
将E:\mongodb-src-r2.4.6\build\win32\32\dd\mongo\base下生成的error_codes.h和error_codes.cpp文件,拷贝到E:\mongodb-src-r2.4.6\src\mongo\base目录下。
ok,编译、运行.

5、问题解决
error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj
1>mongoclient_d.lib(dbclient.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj
1>mongoclient_d.lib(assert_util.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj
1>mongoclient_d.lib(jsobj.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj
1>mongoclient_d.lib(status.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj
1>mongoclient_d.lib(mutexdebugger.obj) : error LNK2038: mismatch detected for '_MSC_VER': value '1700' doesn't match value '1600' in error_codes.obj

VS的版本不匹配,lib是在更高级的版本中编译生成的,而使用的时候,是在低级版本中使用的,所以出现了不匹配的错误。例如,我在VS2010 SP1和VS2012的环境下编译的,而使用是在VS2010上使用,所以在编译时,出现了以上问题。

1>mongoclient.lib(stacktrace.obj) : error LNK2001: unresolved external symbol __imp_SymCleanup
1>mongoclient.lib(stacktrace.obj) : error LNK2001: unresolved external symbol __imp_SymGetMoleInfo64
1>mongoclient.lib(stacktrace.obj) : error LNK2001: unresolved external symbol __imp_SymInitialize
1>mongoclient.lib(stacktrace.obj) : error LNK2001: unresolved external symbol __imp_StackWalk64
1>mongoclient.lib(stacktrace.obj) : error LNK2001: unresolved external symbol __imp_SymFromAddr

在工程依赖库中添加Dbghelp.lib

其它问题,看看你手头的编译器、编译出来的boost库版本、mongoclient.lib的版本,是否对应好了。

7. GitHub 上有哪些完整的 iOS-App 源码值得参考

1. Coding iOS 客户端

Coding官方客户端. 笔者强烈推荐的值得学习的完整APP.
GitHub - Coding/Coding-iOS: Coding iOS 客户端源代码
2. OSCHINA 的 iPhone 客户端
开源中国的iPhone客户端源码
https://git.oschina.net/oschina/iphone-app
3. Git@OSC
Git@OSC iPhone 客户端,方便用户查看Git@OSC的项目以及简单的操作issue等
oschina / git-osc-iphone
4. Firefox for iOS
GitHub - mozilla/firefox-ios: Firefox for iOS
5. zulip-ios
Dropbox收购公司内部社交服务商Zulip,然后全部开源,这是iOS App
GitHub - zulip/zulip-ios: Zulip iOS app
6. iOSSF
SegmentFault官方App
GitHub - gaosboy/iOSSF: SegmentFault官方App
7. iReddit
Reddit iPhone客户端
GitHub - reddit/iReddit: The iReddit iPhone app
8. Monkey
GitHub第三方iOS客户端
GitHub - coderyi/Monkey: Monkey is a GitHub third party client for iOS,to show the rank of coders and repositories.
9. Watch
Dribbble第三方客户端
GitHub - tuesda/Watch: A project which demonstrate how to develop a custom client on android for dribbble.com
10. Voice2Note
懒人笔记iOS客户端
GitHub - liaojinxing/Voice2Note: 懒人笔记iOS客户端
11. RSSRead
“已阅”(iOS上开源RSS新闻阅读器)
GitHub - ming1016/RSSRead: “已阅”(iOS上开源RSS新闻阅读器),有兴趣?那就Pull Requests吧
12. BeeFancy
BeeFancy仿Fancy官方APP的WIREFRAME,基于BeeFramework
GitHub - BeeFramework/BeeFancy: 仿Fancy官方APP的WIREFRAME,基于BeeFramework
13. SXNews
模仿网易新闻做的精仿网易新闻
GitHub - dsxNiubility/SXNews: High imitation Neteasy News. (include list,detail,photoset,weather,feedback)
14. Doppio
寻找最近的星巴克
GitHub - chroman/Doppio: An open source iOS app to find the nearest Starbucks store using NSURLSession, AFNetworking 2.0, Mantle and Starbucks private API.
15. Anypic
类似于Instagram的一款App
GitHub - ParsePlatform/Anypic: An open source mobile and web app that lets users share photos similar to Instagram
16. 豆瓣相册
Slowslab iOS应用 豆瓣相册 精选集 开源项目
GitHub - TonnyTao/DoubanAlbum: Slowslab iOS应用 豆瓣相册 精选集 开源项目,仅供学习参考
17. ChatSecure-iOS
Objective-C写的XMPP聊天应用
GitHub - ChatSecure/ChatSecure-iOS: ChatSecure is a free and open source encrypted chat client for iPhone and Android that supports OTR encryption over XMPP.
18. NotificationChat
Objective-C写的完整的聊天应用
GitHub - relatedcode/EncryptedChat: This is a full native iPhone app to create realtime, text based group or private chat with Parse and Firebase.
19. FakeZhihuDaily
仿知乎日报iOS客户端
GitHub - gnou/FakeZhihuDaily: 仿知乎日报iOS客户端
20. ruby-china-for-ios
RubyChina官方客户端
GitHub - ruby-china/ruby-china-for-ios: Ruby China client for iOS
21. Meizi
豆瓣妹子图iOS客户端
GitHub - Sunnyyoung/Meizi: 豆瓣妹子图iOS客户端
22. PlainReader
一款 iOS(iPhone + iPad) 新闻类客户端,内容抓取自http://cnBeta.com
PlainReader/PlainReader at master · guojiubo/PlainReader · GitHub
23. iOS-2048
用Objective-C实现的2048游戏
GitHub - austinzheng/iOS-2048: iOS drop-in library presenting a 2048-style game
24. ECMobile_iOS
基于ECShop的手机商城客户端
GitHub - GeekZooStudio/ECMobile_iOS: 基于ECShop的手机商城客户端
25. wikipedia-ios
维基网络官方App, 已上架
GitHub - wikimedia/wikipedia-ios: The official Wikipedia iOS app.
26. Sol
漂亮的扁平风格的天气App
GitHub - comyarzaheri/Sol: Sol° beautifully displays weather information so you can plan your day accordingly. Check the weather in your current location or any city around the world. Implemented in Objective-C.

8. 如何查看Android SDK源码版本

一种办法是自带SDK管理工具更新:

另外的办法就是:
第一步:查看当前工程的SDK版本;

2.打开工程,查找任意一个函数,点击右键,选择查看源码.

3.提示找不到java源文件,这里需要手动添加源文件;

4.按图选择.这里还没有source的文件夹..所以..去下载相关平台的SDK的java源码;

5.打开网址:http //rgruet free fr/public/
根据SDK版本下载对应的源码,比如2.1的.

6.在SDK平台目录下,新建一个sources文件夹;

7.把源码直接解压到当前文件夹下;

8.再次选择查到源码,并选择sources文件夹;

9.eclipse会自动导入;

10.再次查看函数的源码,是不是代码就出来了.

9. 初级C语言源代码

好的哦
#define N 200
#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
int i,key;
int score=0;/*得分*/
int gamespeed=50000;/*游戏速度自己调整*/
struct Food
{
int x;/*食物的横坐标*/
int y;/*食物的纵坐标*/
int yes;/*判断是否要出现食物的变量*/
}food;/*食物的结构体*/
struct Snake
{
int x[N];
int y[N];
int node;/*蛇的节数*/
int direction;/*蛇移动方向*/
int life;/* 蛇的生命,0活着,1死亡*/
}snake;
void Init(void);/*图形驱动*/
void Close(void);/*图形结束*/
void DrawK(void);/*开始画面*/
void GameOver(void);/*结束游戏*/
void GamePlay(void);/*玩游戏具体过程*/
void PrScore(void);/*输出成绩*/
/*主函数*/
void main(void)
{
Init();/*图形驱动*/
DrawK();/*开始画面*/
GamePlay();/*玩游戏具体过程*/
Close();/*图形结束*/
}
/*图形驱动*/
void Init(void)
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc");
cleardevice();
}
/*开始画面,左上角坐标为(50,40),右下角坐标为(610,460)的围墙*/
void DrawK(void)
{
/*setbkcolor(LIGHTGREEN);*/
setcolor(11);
setlinestyle(SOLID_LINE,0,THICK_WIDTH);/*设置线型*/
for(i=50;i<=600;i+=10)/*画围墙*/
{
rectangle(i,40,i+10,49); /*上边*/
rectangle(i,451,i+10,460);/*下边*/
}
for(i=40;i<=450;i+=10)
{
rectangle(50,i,59,i+10); /*左边*/
rectangle(601,i,610,i+10);/*右边*/
}
}
/*玩游戏具体过程*/
void GamePlay(void)
{
randomize();/*随机数发生器*/
food.yes=1;/*1表示需要出现新食物,0表示已经存在食物*/
snake.life=0;/*活着*/
snake.direction=1;/*方向往右*/
snake.x[0]=100;snake.y[0]=100;/*蛇头*/
snake.x[1]=110;snake.y[1]=100;
snake.node=2;/*节数*/
PrScore();/*输出得分*/
while(1)/*可以重复玩游戏,压ESC键结束*/
{
while(!kbhit())/*在没有按键的情况下,蛇自己移动身体*/
{
if(food.yes==1)/*需要出现新食物*/
{
food.x=rand()%400+60;
food.y=rand()%350+60;
while(food.x%10!=0)/*食物随机出现后必须让食物能够在整格内,这样才可以让蛇吃到*/
food.x++;
while(food.y%10!=0)
food.y++;
food.yes=0;/*画面上有食物了*/
}
if(food.yes==0)/*画面上有食物了就要显示*/
{
setcolor(GREEN);
rectangle(food.x,food.y,food.x+10,food.y-10);
}
for(i=snake.node-1;i>0;i--)/*蛇的每个环节往前移动,也就是贪吃蛇的关键算法*/
{
snake.x[i]=snake.x[i-1];
snake.y[i]=snake.y[i-1];
}
/*1,2,3,4表示右,左,上,下四个方向,通过这个判断来移动蛇头*/
switch(snake.direction)
{
case 1:snake.x[0]+=10;break;
case 2: snake.x[0]-=10;break;
case 3: snake.y[0]-=10;break;
case 4: snake.y[0]+=10;break;
}
for(i=3;i<snake.node;i++)/*从蛇的第四节开始判断是否撞到自己了,因为蛇头为两节,第三节不可能拐过来*/
{
if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0])
{
GameOver();/*显示失败*/
snake.life=1;
break;
}
}
if(snake.x[0]<55||snake.x[0]>595||snake.y[0]<55||
snake.y[0]>455)/*蛇是否撞到墙壁*/
{
GameOver();/*本次游戏结束*/
snake.life=1; /*蛇死*/
}
if(snake.life==1)/*以上两种判断以后,如果蛇死就跳出内循环,重新开始*/
break;
if(snake.x[0]==food.x&&snake.y[0]==food.y)/*吃到食物以后*/
{
setcolor(0);/*把画面上的食物东西去掉*/
rectangle(food.x,food.y,food.x+10,food.y-10);
snake.x[snake.node]=-20;snake.y[snake.node]=-20;
/*新的一节先放在看不见的位置,下次循环就取前一节的位置*/
snake.node++;/*蛇的身体长一节*/
food.yes=1;/*画面上需要出现新的食物*/
score+=10;
PrScore();/*输出新得分*/
}
setcolor(4);/*画出蛇*/
for(i=0;i<snake.node;i++)
rectangle(snake.x[i],snake.y[i],snake.x[i]+10,
snake.y[i]-10);
delay(gamespeed);
setcolor(0);/*用黑色去除蛇的的最后一节*/
rectangle(snake.x[snake.node-1],snake.y[snake.node-1],
snake.x[snake.node-1]+10,snake.y[snake.node-1]-10);
} /*endwhile(!kbhit)*/
if(snake.life==1)/*如果蛇死就跳出循环*/
break;
key=bioskey(0);/*接收按键*/
if(key==ESC)/*按ESC键退出*/
break;
else
if(key==UP&&snake.direction!=4)
/*判断是否往相反的方向移动*/
snake.direction=3;
else
if(key==RIGHT&&snake.direction!=2)
snake.direction=1;
else
if(key==LEFT&&snake.direction!=1)
snake.direction=2;
else
if(key==DOWN&&snake.direction!=3)
snake.direction=4;
}/*endwhile(1)*/
}
/*游戏结束*/
void GameOver(void)
{
cleardevice();
PrScore();
setcolor(RED);
settextstyle(0,0,4);
outtextxy(200,200,"GAME OVER");
getch();
}
/*输出成绩*/
void PrScore(void)
{
char str[10];
setfillstyle(SOLID_FILL,YELLOW);
bar(50,15,220,35);
setcolor(6);
settextstyle(0,0,2);
sprintf(str,"score:%d",score);
outtextxy(55,20,str);
}
/*图形结束*/
void Close(void)
{
getch();
closegraph();
}
#include <dos.h> /*DOS接口函数*/
#include <math.h> /*数学函数的定义*/
#include <conio.h> /*屏幕操作函数*/
#include <stdio.h> /*I/O函数*/
#include <stdlib.h> /*库函数*/
#include <stdarg.h> /*变量长度参数表*/
#include <graphics.h> /*图形函数*/
#include <string.h> /*字符串函数*/
#include <ctype.h> /*字符操作函数*/
#define UP 0x48 /*光标上移键*/
#define DOWN 0x50 /*光标下移键*/
#define LEFT 0x4b /*光标左移键*/
#define RIGHT 0x4d /*光标右移键*/
#define ENTER 0x0d /*回车键*/
void *rar; /*全局变量,保存光标图象*/
struct palettetype palette; /*使用调色板信息*/
int GraphDriver; /* 图形设备驱动*/
int GraphMode; /* 图形模式值*/
int ErrorCode; /* 错误代码*/
int MaxColors; /* 可用颜色的最大数值*/
int MaxX, MaxY; /* 屏幕的最大分辨率*/
double AspectRatio; /* 屏幕的像素比*/
void drawboder(void); /*画边框函数*/
void initialize(void); /*初始化函数*/
void computer(void); /*计算器计算函数*/
void changetextstyle(int font, int direction, int charsize); /*改变文本样式函数*/
void mwindow(char *header); /*窗口函数*/
int specialkey(void) ; /*获取特殊键函数*/
int arrow(); /*设置箭头光标函数*/
/*主函数*/
int main()
{
initialize();/* 设置系统进入图形模式 */
computer(); /*运行计算器 */
closegraph();/*系统关闭图形模式返回文本模式*/
return(0); /*结束程序*/
}
/* 设置系统进入图形模式 */
void initialize(void)
{
int xasp, yasp; /* 用于读x和y方向纵横比*/
GraphDriver = DETECT; /* 自动检测显示器*/
initgraph( &GraphDriver, &GraphMode, "" );
/*初始化图形系统*/
ErrorCode = graphresult(); /*读初始化结果*/
if( ErrorCode != grOk ) /*如果初始化时出现错误*/
{
printf("Graphics System Error: %s\n",
grapherrormsg( ErrorCode ) ); /*显示错误代码*/
exit( 1 ); /*退出*/
}
getpalette( &palette ); /* 读面板信息*/
MaxColors = getmaxcolor() + 1; /* 读取颜色的最大值*/
MaxX = getmaxx(); /* 读屏幕尺寸 */
MaxY = getmaxy(); /* 读屏幕尺寸 */
getaspectratio( &xasp, &yasp ); /* 拷贝纵横比到变量中*/
AspectRatio = (double)xasp/(double)yasp;/* 计算纵横比值*/
}
/*计算器函数*/
void computer(void)
{
struct viewporttype vp; /*定义视口类型变量*/
int color, height, width;
int x, y,x0,y0, i, j,v,m,n,act,flag=1;
float num1=0,num2=0,result; /*操作数和计算结果变量*/
char cnum[5],str2[20]={""},c,temp[20]={""};
char str1[]="1230.456+-789*/Qc=^%";/* 定义字符串在按钮图形上显示的符号 */
mwindow( "Calculator" ); /* 显示主窗口 */
color = 7; /*设置灰颜色值*/
getviewsettings( &vp ); /* 读取当前窗口的大小*/
width=(vp.right+1)/10; /* 设置按钮宽度 */
height=(vp.bottom-10)/10 ; /*设置按钮高度 */
x = width /2; /*设置x的坐标值*/
y = height/2; /*设置y的坐标值*/
setfillstyle(SOLID_FILL, color+3);
bar( x+width*2, y, x+7*width, y+height );
/*画一个二维矩形条显示运算数和结果*/
setcolor( color+3 ); /*设置淡绿颜色边框线*/
rectangle( x+width*2, y, x+7*width, y+height );
/*画一个矩形边框线*/
setcolor(RED); /*设置颜色为红色*/
outtextxy(x+3*width,y+height/2,"0."); /*输出字符串"0."*/
x =2*width-width/2; /*设置x的坐标值*/
y =2*height+height/2; /*设置y的坐标值*/
for( j=0 ; j<4 ; ++j ) /*画按钮*/
{
for( i=0 ; i<5 ; ++i )
{
setfillstyle(SOLID_FILL, color);
setcolor(RED);
bar( x, y, x+width, y+height ); /*画一个矩形条*/
rectangle( x, y, x+width, y+height );
sprintf(str2,"%c",str1[j*5+i]);
/*将字符保存到str2中*/
outtextxy( x+(width/2), y+height/2, str2);
x =x+width+ (width / 2) ; /*移动列坐标*/
}
y +=(height/2)*3; /* 移动行坐标*/
x =2*width-width/2; /*复位列坐标*/
}
x0=2*width;
y0=3*height;
x=x0;
y=y0;
gotoxy(x,y); /*移动光标到x,y位置*/
arrow(); /*显示光标*/
putimage(x,y,rar,XOR_PUT);
m=0;
n=0;
strcpy(str2,""); /*设置str2为空串*/
while((v=specialkey())!=45) /*当压下Alt+x键结束程序,否则执行下面的循环*/
{
while((v=specialkey())!=ENTER) /*当压下键不是回车时*/
{
putimage(x,y,rar,XOR_PUT); /*显示光标图象*/
if(v==RIGHT) /*右移箭头时新位置计算*/
if(x>=x0+6*width)
/*如果右移,移到尾,则移动到最左边字符位置*/
{
x=x0;
m=0;
}
else
{
x=x+width+width/2;
m++;
} /*否则,右移到下一个字符位置*/
if(v==LEFT) /*左移箭头时新位置计算*/
if(x<=x0)
{
x=x0+6*width;
m=4;
} /*如果移到头,再左移,则移动到最右边字符位置*/
else
{
x=x-width-width/2;
m--;
} /*否则,左移到前一个字符位置*/
if(v==UP) /*上移箭头时新位置计算*/
if(y<=y0)
{
y=y0+4*height+height/2;
n=3;
} /*如果移到头,再上移,则移动到最下边字符位置*/
else
{
y=y-height-height/2;
n--;
} /*否则,移到上边一个字符位置*/
if(v==DOWN) /*下移箭头时新位置计算*/
if(y>=7*height)
{
y=y0;
n=0;
} /*如果移到尾,再下移,则移动到最上边字符位置*/
else
{
y=y+height+height/2;
n++;
} /*否则,移到下边一个字符位置*/
putimage(x,y,rar,XOR_PUT); /*在新的位置显示光标箭头*/
}
c=str1[n*5+m]; /*将字符保存到变量c中*/
if(isdigit(c)||c=='.') /*判断是否是数字或小数点*/
{
if(flag==-1) /*如果标志为-1,表明为负数*/
{
strcpy(str2,"-"); /*将负号连接到字符串中*/
flag=1;
} /*将标志值恢复为1*/
sprintf(temp,"%c",c); /*将字符保存到字符串变量temp中*/
strcat(str2,temp); /*将temp中的字符串连接到str2中*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,str2); /*显示字符串*/
}
if(c=='+')
{
num1=atof(str2); /*将第一个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=1; /*做计算加法标志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='-')
{
if(strcmp(str2,"")==0) /*如果str2为空,说明是负号,而不是减号*/
flag=-1; /*设置负数标志*/
else
{
num1=atof(str2); /*将第二个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=2; /*做计算减法标志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*画矩形*/
outtextxy(5*width,height,"0."); /*显示字符串*/
}
}
if(c=='*')
{
num1=atof(str2); /*将第二个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=3; /*做计算乘法标志值*/
setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='/')
{
num1=atof(str2); /*将第二个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=4; /*做计算除法标志值*/
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='^')
{
num1=atof(str2); /*将第二个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=5; /*做计算乘方标志值*/
setfillstyle(SOLID_FILL,color+3); /*设置用淡绿色实体填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*画矩形*/
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='%')
{
num1=atof(str2); /*将第二个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
act=6; /*做计算模运算乘方标志值*/
setfillstyle(SOLID_FILL,color+3); /*设置用淡绿色实体填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*画矩形*/
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='=')
{
num2=atof(str2); /*将第二个操作数转换为浮点数*/
switch(act) /*根据运算符号计算*/
{
case 1:result=num1+num2;break; /*做加法*/
case 2:result=num1-num2;break; /*做减法*/
case 3:result=num1*num2;break; /*做乘法*/
case 4:result=num1/num2;break; /*做除法*/
case 5:result=pow(num1,num2);break; /*做x的y次方*/
case 6:result=fmod(num1,num2);break; /*做模运算*/
}
setfillstyle(SOLID_FILL,color+3); /*设置用淡绿色实体填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*覆盖结果区*/
sprintf(temp,"%f",result); /*将结果保存到temp中*/
outtextxy(5*width,height,temp); /*显示结果*/
}
if(c=='c')
{
num1=0; /*将两个操作数复位0,符号标志为1*/
num2=0;
flag=1;
strcpy(str2,""); /*将str2清空*/
setfillstyle(SOLID_FILL,color+3); /*设置用淡绿色实体填充*/
bar(2*width+width/2,height/2,15*width/2,3*height/2); /*覆盖结果区*/
outtextxy(5*width,height,"0."); /*显示字符串*/
}
if(c=='Q')exit(0); /*如果选择了q回车,结束计算程序*/
}
putimage(x,y,rar,XOR_PUT); /*在退出之前消去光标箭头*/
return; /*返回*/
}
/*窗口函数*/
void mwindow( char *header )
{
int height;
cleardevice(); /* 清除图形屏幕 */
setcolor( MaxColors - 1 ); /* 设置当前颜色为白色*/
setviewport( 20, 20, MaxX/2, MaxY/2, 1 ); /* 设置视口大小 */
height = textheight( "H" ); /* 读取基本文本大小 */
settextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );/*设置文本样式*/
settextjustify( CENTER_TEXT, TOP_TEXT );/*设置字符排列方式*/
outtextxy( MaxX/4, 2, header ); /*输出标题*/
setviewport( 20,20+height+4, MaxX/2+4, MaxY/2+20, 1 ); /*设置视口大小*/
drawboder(); /*画边框*/
}
void drawboder(void) /*画边框*/
{
struct viewporttype vp; /*定义视口类型变量*/
setcolor( MaxColors - 1 ); /*设置当前颜色为白色 */
setlinestyle( SOLID_LINE, 0, NORM_WIDTH );/*设置画线方式*/
getviewsettings( &vp );/*将当前视口信息装入vp所指的结构中*/
rectangle( 0, 0, vp.right-vp.left, vp.bottom-vp.top ); /*画矩形边框*/
}
/*设计鼠标图形函数*/
int arrow()
{
int size;
int raw[]={4,4,4,8,6,8,14,16,16,16,8,6,8,4,4,4}; /*定义多边形坐标*/
setfillstyle(SOLID_FILL,2); /*设置填充模式*/
fillpoly(8,raw); /*画出一光标箭头*/
size=imagesize(4,4,16,16); /*测试图象大小*/
rar=malloc(size); /*分配内存区域*/
getimage(4,4,16,16,rar); /*存放光标箭头图象*/
putimage(4,4,rar,XOR_PUT); /*消去光标箭头图象*/
return 0;
}
/*按键函数*/
int specialkey(void)
{
int key;
while(bioskey(1)==0); /*等待键盘输入*/
key=bioskey(0); /*键盘输入*/
key=key&0xff? key&0xff:key>>8; /*只取特殊键的扫描值,其余为0*/
return(key); /*返回键值*/
}
#include <dos.h> /*DOS接口函数*/
#include <math.h> /*数学函数的定义*/
#include <conio.h> /*屏幕操作函数*/
#include <stdio.h> /*I/O函数*/
#include <stdlib.h> /*库函数*/
#include <stdarg.h> /*变量长度参数表*/
#include <graphics.h> /*图形函数*/
#include <string.h> /*字符串函数*/
#include <ctype.h> /*字符操作函数*/
#define UP 0x48 /*光标上移键*/
#define DOWN 0x50 /*光标下移键*/
#define LEFT 0x4b /*光标左移键*/
#define RIGHT 0x4d /*光标右移键*/
#define ENTER 0x0d /*回车键*/
void *rar; /*全局变量,保存光标图象*/
struct palettetype palette; /*使用调色板信息*/
int GraphDriver; /* 图形设备驱动*/
int GraphMode; /* 图形模式值*/
int ErrorCode; /* 错误代码*/
int MaxColors; /* 可用颜色的最大数值*/
int MaxX, MaxY; /* 屏幕的最大分辨率*/
double AspectRatio; /* 屏幕的像素比*/
void drawboder(void); /*画边框函数*/
void initialize(void); /*初始化函数*/
void computer(void); /*计算器计算函数*/
void changetextstyle(int font, int direction, int charsize); /*改变文本样式函数*/
void mwindow(char *header); /*窗口函数*/
int specialkey(void) ; /*获取特殊键函数*/
int arrow(); /*设置箭头光标函数*/
/*主函数*/
int main()
{
initialize();/* 设置系统进入图形模式 */
computer(); /*运行计算器 */
closegraph();/*系统关闭图形模式返回文本模式*/
return(0); /*结束程序*/
}
/* 设置系统进入图形模式 */
void initialize(void)
{
int xasp, yasp; /* 用于读x和y方向纵横比*/
GraphDriver = DETECT; /* 自动检测显示器*/
initgraph( &GraphDriver, &GraphMode, "" );
/*初始化图形系统*/
ErrorCode = graphresult(); /*读初始化结果*/
if( ErrorCode != grOk ) /*如果初始化时出现错误*/
{
printf("Graphics System Error: %s\n",
grapherrormsg( ErrorCode ) ); /*显示错误代码*/
exit( 1 ); /*退出*/
}
getpalette( &palette ); /* 读面板信息*/
MaxColors = getmaxcolor() + 1; /* 读取颜色的最大值*/
MaxX = getmaxx(); /* 读屏幕尺寸 */
MaxY = getmaxy(); /* 读屏幕尺寸 */
getaspectratio( &xasp, &yasp ); /* 拷贝纵横比到变量中*/
AspectRatio = (double)xasp/(double)yasp;/* 计算纵横比值*/
}
/*计算器函数*/
void computer(void)
{
struct viewporttype vp; /*定义视口类型变量*/
int color, height, width;
int x, y,x0,y0, i, j,v,m,n,act,flag=1;
float num1=0,num2=0,result; /*操作数和计算结果变量*/
char cnum[5],str2[20]={""},c,temp[20]={""};
char str1[]="1230.456+-789*/Qc=^%";/* 定义字符串在按钮图形上显示的符号 */
mwindow( "Calculator" ); /* 显示主窗口 */
color = 7; /*设置灰颜色值*/
getviewsettings( &vp ); /* 读取当前窗口的大小*/
width=(vp.right+1)/10; /* 设置按钮宽度 */
height=(vp.bottom-10)/10 ; /*设置按钮高度 */
x = width /2; /*设置x的坐标值*/
y = height/2; /*设置y的坐标值*/
setfillstyle(SOLID_FILL, color+3);
bar( x+width*2, y, x+7*width, y+height );
/*画一个二维矩形条显示运算数和结果*/
setcolor( color+3 ); /*设置淡绿颜色边框线*/
rectangle( x+width*2, y, x+7*width, y+height );
/*画一个矩形边框线*/
setcolor(RED); /*设置颜色为红色*/
outtextxy(x+3*width,y+height/2,"0."); /*输出字符串"0."*/
x =2*width-width/2; /*设置x的坐标值*/
y =2*height+height/2; /*设置y的坐标值*/
for( j=0 ; j<4 ; ++j ) /*画按钮*/
{
for( i=0 ; i<5 ; ++i )
{
setfillstyle(SOLID_FILL, color);
setcolor(RED);
bar( x, y, x+width, y+height ); /*画一个矩形条*/
rectangle( x, y, x+width, y+height );
sprintf(str2,"%c",str1[j*5+i]);
/*将字符保存到str2中*/
outtextxy( x+(width/2), y+height/2, str2);
x =x+width+ (width / 2) ; /*移动列坐标*/
}
y +=(height/2)*3; /* 移动行坐标*/
x =2*width-width/2; /*复位列坐标*/
}
x0=2*width;
y0=3*height;
x=x0;
y=y0;
gotoxy(x,y); /*移动光标到x,y位置*/
arrow(); /*显示光标*/
putimage(x,y,rar,XOR_PUT);
m=0;
n=0;
strcpy(str2,""); /*设置str2为空串*/
while((v=specialkey())!=45) /*当压下Alt+x键结束程序,否则执行下面的循环*/
{
while((v=specialkey())!=ENTER) /*当压下键不是回车时*/
{
putimage(x,y,rar,XOR_PUT); /*显示光标图象*/
if(v==RIGHT) /*右

10. Java eclipse中无法查看源代码

1.点 “window“-> “Preferences”-> “Java” -> “Installed JRES”;
2.此时"Installed JRES"右边是列表窗格,列空首出了系统中的JRE 环境,选择你的JRE,然后点边上的“Edit...“, 会出现一个窗口(Edit JRE) ;
3.选中rt.jar文件的这一项:“C:\Java\jdk1.5.0_04\jre\lib\rt.jar” 点 左边的“+”号展开它(JDK实际安装路径以你的为准);
4.展开后,可以看到“Source Attachment:(none)”,点这一项,点右边的按拆冲钮“Source Attachment...“,选择你的JDK目录旅亏歼下的 “src.zip”文件;
5.一路点“ok”结束。

热点内容
两位数密码要试多少次能试出来 发布:2024-05-02 11:30:59 浏览:688
ae脚本插件表达式 发布:2024-05-02 11:26:45 浏览:267
手机电脑通用的服务器 发布:2024-05-02 11:25:26 浏览:839
安卓b站账号如何在ios登陆 发布:2024-05-02 11:20:29 浏览:198
微信加密码锁怎么设置 发布:2024-05-02 11:17:24 浏览:584
四川服务器托管云空间云主机 发布:2024-05-02 11:04:28 浏览:962
手机app重编译 发布:2024-05-02 11:01:40 浏览:537
怎么给订制系统平板安装安卓系统 发布:2024-05-02 10:29:59 浏览:260
云服务器做网站服务器用什么系统 发布:2024-05-02 10:20:26 浏览:896
python经典程序实例 发布:2024-05-02 09:42:07 浏览:260