Tag: android

android.database.CursorIndexOutOfBoundsException …再一次

所以,我在我的应用程序的用户崩溃报告中有这个错误。 这是报告: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0 at android.database.AbstractCursor.checkPosition(AbstractCursor.) at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.) at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50) at rs.androidaplikacije.zastaveigradovi.Kviz10Hard.nextQuestionGrad(Kviz10Hard.) at rs.androidaplikacije.zastaveigradovi.Kviz10Hard.access$1(Kviz10Hard.) at rs.androidaplikacije.zastaveigradovi.Kviz10Hard$2.run(Kviz10Hard.java:68) at android.os.Handler.handleCallback(Handler.) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.) at android.app.ActivityThread.main(ActivityThread.) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.) at com.android.internal.os.ZygoteInit.main(ZygoteInit.) at dalvik.system.NativeStart.main(Native Method) 这是提到的代码: private void nextQuestionGrad() { flag.setVisibility(View.GONE); dodatnoPitanje.setVisibility(View.VISIBLE); TestAdapter mDbHelper = new TestAdapter(this); […]

HttpPost – >重定向 – >所需响应的位置或主体

以下是将数据POST到网站而不是作为响应重定向的Java代码(状态302)。 它在我的PC(Eclipse,Java,Ubuntu)上完美运行,它完全符合我的要求。 我尝试了很多东西来发布代码function,但我无法做到。 Java代码: // Preparing the CLIENT and POST Method HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(“http://na.leagueoflegends.com/ladders/solo-5×5”); try { // Add your POST METHOD attributes List nameValuePairs = new ArrayList(2); nameValuePairs.add(new BasicNameValuePair(“op”, “Search”)); nameValuePairs.add(new BasicNameValuePair(“player”, “Jaiybe”)); nameValuePairs.add(new BasicNameValuePair(“ladder_id”, “3”)); nameValuePairs.add(new BasicNameValuePair(“form_build_id”, “form-526370b788622996caa3669e7b975ccf”)); nameValuePairs.add(new BasicNameValuePair(“form_id”, “ladders_filter_form”)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post […]

Android将Arraylist数据设置为自定义适配器

我有一个ArrayList statusListTextOnly; 包含一些推文。 现在,如果我像这样使用它 i.setAdapter(new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, statusListTextOnly)); 一切都很好,活动开始,推文在listview中显示。 但我想深入了解我的应用,我想使用自定义适配器。 所以我做了: Tweet[] tweets; TweetAdapter adapter; Tweet weather_data[] = new Tweet[] { new Tweet(statusListTextOnly) }; adapter = new TweetAdapter(MainAcitivity.this, R.layout.listview_item_row, weather_data); i.setAdapter(adapter); 我的推文: public class Tweet { public String title; public Tweet(){ super(); } public Tweet(ArrayList title) { super(); for(String s : title) this.title = s; […]

网络不可用时防止应用崩溃

我有一个应用程序,它具有从服务启动的前台通知。 该服务每秒调用一个用作GPS连接的类。 GPS类使用NETWORK_PROVIDER和GPS_PROVIDER 。 到目前为止,所有工作都是正确的,除了今天发生的事情。 在某些时候,Android系统显示的消息说“除非你连接到wifi网络或移动网络,否则你将无法访问电子邮件和互联网”。 我不太清楚这条消息,但我有两个按钮:“取消”和“确定”。 从口袋里拿出手机时,我可能会点击某些东西。 在此消息之上是另一条消息,说我的应用程序不幸崩溃了。 所以事件的顺序似乎是这样的:网络禁用(?),应用程序崩溃。 我认为我需要以某种方式处理网络错误,但我现在无能为力,因为我无法从错误中获得太多信息。 有什么想法吗? 谢谢

如何通过代理进行所有网络流量?

我有一个应用程序向远程服务器发出http请求。 我使用以下代码执行此操作: HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(“myURL”); try { ArrayList postVariables = new ArrayList(2); postVariables.add(new BasicNameValuePair(“key”,”value”)); httpPost.setEntity(new UrlEncodedFormEntity(postVariables)); HttpResponse response = httpClient.execute(httpPost); String responseString = EntityUtils.toString(response.getEntity()); if (responseString.contains(“\”success\”:true”)){ //this means the request succeeded } else { //failed } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); […]

快速滚动使用UniversalImageloader或使用Views的引用优化ListView

我试图使TimeLine有点类似于Facebook或Instagram。 更接近Instagram。 在图像加载我正在使用库UniversalImageLoader。 我的每个ListView项目行的高度可能超过600dp。 通常我一次拿5件物品。 现在出现的问题是,滚动一点点快速的图像互相替换。 由于视图正在被重用。 图像显示大约需要3-4秒,否则将在listView Row中显示错误的图像。 1-如果有人能够知道如何优化/修复这个快速滚动ImageOverlap问题,否则,2-记录EntireView的方法是什么,让我们说一些“ArrayList”并将其放在当前位置。 注意到还有其他事情发生,不仅mediaDp被改变了。 if (convertView == null) { view = inflator.inflate(R.layout.timeline_list_row, parent, false); viewHolder.userDp = (RoundedImageView) view.findViewById(R.id.userDp); viewHolder.mediaDp = (ImageView) view.findViewById(R.id.imagePostedMedia); /************ Set holder with LayoutInflater ************/ view.setTag(viewHolder); final ViewHolder newHolder = viewHolder; } else viewHolder = (ViewHolder) view.getTag(); imageLoader.displayImage(media.imagePath, viewHolder.mediaDp);

自定义适配器ViewHolder问题

我正在尝试使用自定义适配器列表。 此列表有两种类型的行,但我只使用一种布局(将可见性设置为View.GONE不需要的项目View.GONE )。 但是,当我尝试访问编辑框样式的行时,我不断收到类强制转换exception。 我对自定义适配器的经验很少。 非常感谢您的帮助:D 这是代码(我删除了setonclicklisteners以保持简短): public class SubEventListAdapter extends ArrayAdapter { private ArrayList _items; private Context _context; public SubEventListAdapter(Context context, ArrayList items) { super(context, R.layout.view_select_event_item3, items); this._items = items; this._context = context; } static class ViewHolder { TextView text; ImageButton imagebutton; ImageView check; EditText editText; Button button; } @Override public int getCount() { […]

HttpURLConnection即使在setDoOutput(true)之后执行get请求,setRequestMethod(“POST”)setRequestProperty(“Content”

这是代码: String Surl = “http://mysite.com/somefile”; String charset = “UTF-8”; query = String.format(“param1=%s&param2=%s”, URLEncoder.encode(“param1”, charset), URLEncoder.encode(“param2”, charset)); HttpURLConnection urlConnection = (HttpURLConnection) new URL(Surl + “?” + query).openConnection(); urlConnection.setRequestMethod(“POST”); urlConnection.setDoOutput(true); urlConnection.setUseCaches(false); urlConnection.setAllowUserInteraction(false); urlConnection.setRequestProperty(“Accept-Charset”, charset); urlConnection.setRequestProperty(“User-Agent”,”Android”); urlConnection.setRequestProperty(“Content-Type”,”application/x-www-form-urlencoded;charset=” + charset); urlConnection.connect(); 以上仍然是GET请求。 我在服务器上使用PHP,并且能够通过$_GET变量而不是$_POST变量访问查询的’name = value’参数 测试2.3.7(设备)。 我错过了什么?

使用Json-lib将XML转换为Json

我正在尝试在Android中执行一个项目,我从Web获取文档xml,我想在Json中进行转换。 我正在尝试这个: URL url; InputStream in; try { url = new URL(“http://www.aemet.es/xml/municipios/localidad_41091.xml”); in = url.openStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String result, line = reader.readLine(); result = line; while((line=reader.readLine())!=null){ result+=line; } XMLSerializer serializer = new XMLSerializer(); JSON json = serializer.read( result ); System.out.println(json.toString()); } catch (MalformedURLException e) { e.printStackTrace(); }catch (IOException e) { e.printStackTrace(); […]

自动向数组添加元素

嗨,我不擅长Java,所以请耐心等待。 我正在尝试编写一个非常简单的Android应用程序,我需要一些编码方面的帮助。 事实是,我有一个服务器,它自动生成.png文件,并按数字顺序将它们保存到公共目录。 更新每天进行,并非详尽无遗。 无论如何,我可以将动态值分配给我的应用程序中的数组吗? private String[] myRemoteImages = { “http://sofzh.miximages.com/java/hypotheticalurl1.png”, “http://sofzh.miximages.com/java/hypotheticalurl2.png”, “http://sofzh.miximages.com/java/hypotheticalurl3.png”, “http://sofzh.miximages.com/java/hypotheticalurl4.png”, “http://sofzh.miximages.com/java/hypotheticalurl5.png”, “http://sofzh.miximages.com/java/hypotheticalurl6.png”, “http://sofzh.miximages.com/java/hypotheticalurl7.png”, “http://sofzh.miximages.com/java/hypotheticalurl8.png”, “http://sofzh.miximages.com/java/hypotheticalurl9.png”, “http://sofzh.miximages.com/java/hypotheticalurl10.png”, “http://sofzh.miximages.com/java/hypotheticalurl11.png”, “http://sofzh.miximages.com/java/hypotheticalurl12.png”, //…blah blah blah // these are all dynamically created so I won’t know what is the last number on the list }; 此数组最终将用于使用应用程序从我的服务器获取图像。 它工作到目前为止,但只有硬编码的URL。 我希望这些url是动态的,因为图片的数量会每天都在变化。 我怀疑正则表达式在Java中运行良好但是我再也不是专家了。 想到也许在服务器端编写一个脚本,生成一个现有值列表,并以某种方式解析它与Android应用程序。 谁能指出我正确的方向? 提前致谢。 澄清: 应用程序运行时,arrays不必动态resize。 我需要一种方法来读取远程目录中的现有图像列表,并传递该信息以在运行时自动填充数组。 解决 […]