How can you write to a file that is not in the sdcard, it's a highscore text file that I just want my int "clicked" to go in there.
(Lol yeah.)
I doubt you can write text into a file that is NOT in the sdcard, unless you have root permission. However, you can store those highscores etc in a SQLite Database or SharedPreferences.
frenzyboi said:
I doubt you can write text into a file that is NOT in the sdcard, unless you have root permission. However, you can store those highscores etc in a SQLite Database or SharedPreferences.
Click to expand...
Click to collapse
Okey, thanks! Then how would I be able to write to SharedPreferences (as it seems it is much easier than SQLiteDatabase?)
I read the site but couldn't manage it.
Create a SharedPreferences.Editor object and use its put... methods with a tag for your int. Then call apply() or commit() and retrieve the value later with a PreferenceManager (setDefaultValues(this, R.xml.whatever, false) and getDefaultSharedPreferences (this) ... ). It's the usual way to get preferences, same as if you saved them in a PreferenceActivity.
You CAN create a text file on the /data directory without root permissions!
However, this can be done just in the directory of your app. Check this tutorial: http://developer.android.com/training/basics/data-storage/files.html#WriteInternalStorage
It IS possible!
For SharedPreferences:
Instantiate a new SharedPreferences:
Code:
SharedPreferences prefs = this.getSharedPreferences("com.example.app", Context.MODE_PRIVATE);
To edit a value:
Code:
prefs.edit().putString("highscore", "12345").commit();
where "putString" can be "putInt", "putLong" and "highscore" can be any words you want.
To read the value:
Code:
String highscore = prefs.getString("highscore, "0");
where "highscore" must be the same value a the one when you're editing, and 0 is the default value if there is no value stored previously.
To save a file like what Nikwen said:
http://stackoverflow.com/questions/13161470/saving-file-in-internal-storage-android
----------------
However in my opinion, I think SharedPreference is easier as everything is handled by the OS itself, without you needing to read the file line by line, parse the data and get what you need.
frenzyboi said:
For SharedPreferences:
Instantiate a new SharedPreferences:
Code:
SharedPreferences prefs = this.getSharedPreferences("com.example.app", Context.MODE_PRIVATE);
To edit a value:
Code:
prefs.edit().putString("highscore", "12345").commit();
where "putString" can be "putInt", "putLong" and "highscore" can be any words you want.
To read the value:
Code:
String highscore = prefs.getString("highscore, "0");
where "highscore" must be the same value a the one when you're editing, and 0 is the default value if there is no value stored previously.
To save a file like what Nikwen said:
http://stackoverflow.com/questions/13161470/saving-file-in-internal-storage-android
----------------
However in my opinion, I think SharedPreference is easier as everything is handled by the OS itself, without you needing to read the file line by line, parse the data and get what you need.
Click to expand...
Click to collapse
how can we access the committed data from another class?
You can only get access to the SharedPreferences from an activity or a class with an activity context like a dialog with getActivity(). Then use the SharedPreferences prefs = this.getSharedPreferences("com.whatever",...)
frenzyboi said:
For SharedPreferences:
Instantiate a new SharedPreferences:
Code:
SharedPreferences prefs = this.getSharedPreferences("com.example.app", Context.MODE_PRIVATE);
To edit a value:
Code:
prefs.edit().putString("highscore", "12345").commit();
where "putString" can be "putInt", "putLong" and "highscore" can be any words you want.
To read the value:
Code:
String highscore = prefs.getString("highscore, "0");
where "highscore" must be the same value a the one when you're editing, and 0 is the default value if there is no value stored previously.
To save a file like what Nikwen said:
http://stackoverflow.com/questions/13161470/saving-file-in-internal-storage-android
----------------
However in my opinion, I think SharedPreference is easier as everything is handled by the OS itself, without you needing to read the file line by line, parse the data and get what you need.
Click to expand...
Click to collapse
What means with "com.example.app"? Is that just my package? And where should the file be placed in eclipse before running?
If I got like a number that is changing each time I click a button, and then I timer that counts from 60 down to 0, when it's on 0 I have onFinish method, what should I put there to make the text inside highscore.txt file to edit to what my int is (clicked)?
It's hard to explain.. :/
Edit:
I have this code:
Code:
SharedPreferences prefs = getSharedPreferences("com.SAH.clickr", Context.MODE_PRIVATE);
String highscore = prefs.getString("highscore", "0");
final TextView text2 = (TextView) findViewById(R.id.highscore);
text2.setText("Highscore: " + highscore);
When running it has to force close upon start (this code is in the onCreate method).
I get this error in the logcat:
Code:
06-24 14:03:58.187: I/Process(275): Sending signal. PID: 275 SIG: 9
06-24 14:04:05.886: W/ActivityThread(290): Application com.SAH.clickr can be debugged on port 8100...
06-24 14:04:06.226: D/AndroidRuntime(290): Shutting down VM
06-24 14:04:06.226: W/dalvikvm(290): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-24 14:04:06.236: E/AndroidRuntime(290): FATAL EXCEPTION: main
06-24 14:04:06.236: E/AndroidRuntime(290): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.SAH.clickr/com.SAH.clickr.MainActivity}: java.lang.NullPointerException
06-24 14:04:06.236: E/AndroidRuntime(290): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-24 14:04:06.236: E/AndroidRuntime(290): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-24 14:04:06.236: E/AndroidRuntime(290): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-24 14:04:06.236: E/AndroidRuntime(290): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-24 14:04:06.236: E/AndroidRuntime(290): at android.os.Handler.dispatchMessage(Handler.java:99)
06-24 14:04:06.236: E/AndroidRuntime(290): at android.os.Looper.loop(Looper.java:123)
06-24 14:04:06.236: E/AndroidRuntime(290): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-24 14:04:06.236: E/AndroidRuntime(290): at java.lang.reflect.Method.invokeNative(Native Method)
06-24 14:04:06.236: E/AndroidRuntime(290): at java.lang.reflect.Method.invoke(Method.java:521)
06-24 14:04:06.236: E/AndroidRuntime(290): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-24 14:04:06.236: E/AndroidRuntime(290): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-24 14:04:06.236: E/AndroidRuntime(290): at dalvik.system.NativeStart.main(Native Method)
06-24 14:04:06.236: E/AndroidRuntime(290): Caused by: java.lang.NullPointerException
06-24 14:04:06.236: E/AndroidRuntime(290): at com.SAH.clickr.MainActivity.onCreate(MainActivity.java:72)
06-24 14:04:06.236: E/AndroidRuntime(290): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-24 14:04:06.236: E/AndroidRuntime(290): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-24 14:04:06.236: E/AndroidRuntime(290): ... 11 more
NullPointer, where is that?
addemod said:
What means with "com.example.app"? Is that just my package? And where should the file be placed in eclipse before running?
If I got like a number that is changing each time I click a button, and then I timer that counts from 60 down to 0, when it's on 0 I have onFinish method, what should I put there to make the text inside highscore.txt file to edit to what my int is (clicked)?
It's hard to explain.. :/
Edit:
I have this code:
Code:
SharedPreferences prefs = getSharedPreferences("com.SAH.clickr", Context.MODE_PRIVATE);
String highscore = prefs.getString("highscore", "0");
[/CODE ]
[/QUOTE]
Your shared preferences object is null I guess try SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference(this) ;
I suggest use a sqlite database for highscore shared preferences can easily be tampred
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
sak-venom1997 said:
Your shared preferences object is null I guess try SharedPreferences prefs = PreferenceManager.getDefaultSharedPreference(this) ;
I suggest use a sqlite database for highscore shared preferences can easily be tampred
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
I was about to try SQLite Db but I guess it's too hard for a beginner like me, if you can't explain a little bit how to do it?
addemod said:
I were about to try SQLite Db but I guess it's too hard for a beginner like me, if you can't explain a little bit how to do it?
Click to expand...
Click to collapse
It requires understanding of SQL databases read about it Implementation of it in android is easy but meanwhile try the SharedPreference
Sent from my GT-S5302 using Tapatalk 2
sak-venom1997 said:
It requires understanding of SQL databases read about it Implementation of it in android is easy but meanwhile try the SharedPreference
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
I can understand sql / mysql with tables and such. I understand it when I read it but I can never write it out of my mind.
addemod said:
I can understand sql / mysql with tables and such. I understand it when I read it but I can never write it out of my mind.
Click to expand...
Click to collapse
To avoid Sql and
To prevent tampering of highscore data try simple encoding like representing 1 by 'a' in the shared preference value or something else of that kind
Sent from my GT-S5302 using Tapatalk 2
nikwen said:
You CAN create a text file on the /data directory without root permissions!
However, this can be done just in the directory of your app. Check this tutorial: http://developer.android.com/training/basics/data-storage/files.html#WriteInternalStorage
It IS possible!
Click to expand...
Click to collapse
Did you see this?
In my opinion it is the easiest method.
nikwen said:
Did you see this?
In my opinion it is the easiest method.
Click to expand...
Click to collapse
Yeah I tried but it didn't really work out that well :/
As said, I am very beginner to Android Development
addemod said:
Yeah I tried but it didn't really work out that well :/
As said, I am very beginner to Android Development
Click to expand...
Click to collapse
Do you still have your code. Post it and I will look at it.
nikwen said:
Do you still have your code. Post it and I will look at it.
Click to expand...
Click to collapse
Nah, I removed the code but I can try again and see if I can get it to work or not
nikwen said:
Do you still have your code. Post it and I will look at it.
Click to expand...
Click to collapse
Forget everything below, I fixed it, I just put "inputStream.read()" instead of inputStream in "if(inputStream > clicked)"
Thx everyone.
Now, it just says that I didn't beat my highscore even if it is a 0 inside the text file.. :/
!!OLD BELOW!!
Okey so here's the code that should work, the only thing that is not working is that I want it to write to the file ONLY if the int "clicked" value is higher than the value inside the file.
Code:
Code:
String filename = "highscore.txt";
FileOutputStream outputStream;
FileInputStream inputStream;
try {
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
inputStream = openFileInput(filename);
if(inputStream > clicked){
outputStream.write(clicked);
outputStream.close();
}
}catch (Exception e) {
e.printStackTrace();
}
addemod said:
Forget everything below, I fixed it, I just put "inputStream.read()" instead of inputStream in "if(inputStream > clicked)"
Thx everyone.
Now, it just says that I didn't beat my highscore even if it is a 0 inside the text file.. :/
!!OLD BELOW!!
Okey so here's the code that should work, the only thing that is not working is that I want it to write to the file ONLY if the int "clicked" value is higher than the value inside the file.
Code:
Code:
String filename = "highscore.txt";
FileOutputStream outputStream;
FileInputStream inputStream;
try {
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
inputStream = openFileInput(filename);
if(inputStream > clicked){
outputStream.write(clicked);
outputStream.close();
}
}catch (Exception e) {
e.printStackTrace();
}
Click to expand...
Click to collapse
You cannot compare ints and InputStreams.
You need to read the value from the file as a String using a BufferedReader and then get it as an int using Integer.parseInt().
Then you can compare the values.
Related
I want to developer RSS FEED reader for android. I am following this tutorial : http://www.ibm.com/developerworks/xml/tutorials/x-androidrss/downloads.html
I am not getting any error in the program but not getting desired output
**This is my logcat:**
Code:
07-20 16:12:23.531: ERROR/Zygote(33): setreuid() failed. errno: 2
07-20 16:12:35.101: ERROR/Zygote(33): setreuid() failed. errno: 17
07-20 16:12:37.031: ERROR/BatteryService(59): usbOnlinePath not found
07-20 16:12:37.031: ERROR/BatteryService(59): batteryVoltagePath not found
07-20 16:12:37.031: ERROR/BatteryService(59): batteryTemperaturePath not found
07-20 16:12:37.061: ERROR/SurfaceFlinger(59): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
07-20 16:12:47.381: ERROR/EventHub(59): could not get driver version for /dev/input/mouse0, Not a typewriter
07-20 16:12:47.412: ERROR/EventHub(59): could not get driver version for /dev/input/mice, Not a typewriter
07-20 16:12:47.812: ERROR/System(59): Failure starting core service
07-20 16:12:47.812: ERROR/System(59): java.lang.SecurityException
07-20 16:12:47.812: ERROR/System(59): at android.os.BinderProxy.transact(Native Method)
07-20 16:12:47.812: ERROR/System(59): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
07-20 16:12:47.812: ERROR/System(59): at android.os.ServiceManager.addService(ServiceManager.java:72)
07-20 16:12:47.812: ERROR/System(59): at com.android.server.ServerThread.run(SystemServer.java:184)
07-20 16:12:49.591: ERROR/SoundPool(59): error loading /system/media/audio/ui/Effect_Tick.ogg
07-20 16:12:49.591: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressStandard.ogg
07-20 16:12:49.602: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressSpacebar.ogg
07-20 16:12:49.612: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressDelete.ogg
07-20 16:12:49.622: ERROR/SoundPool(59): error loading /system/media/audio/ui/KeypressReturn.ogg
07-20 16:12:52.672: ERROR/ThrottleService(59): Could not open GPS configuration file /etc/gps.conf
07-20 16:12:54.551: ERROR/logwrapper(145): executing /system/bin/tc failed: No such file or directory
07-20 16:12:54.691: ERROR/logwrapper(147): executing /system/bin/tc failed: No such file or directory
07-20 16:12:54.781: ERROR/logwrapper(149): executing /system/bin/tc failed: No such file or directory
07-20 16:13:17.789: ERROR/HierarchicalStateMachine(59): TetherMaster - unhandledMessage: msg.what=3
07-20 16:13:38.669: INFO/ActivityManager(59): Start proc com.svox.pico for broadcast com.svox.pico/.VoiceDataInstallerReceiver: pid=268 uid=10028 gids={}
07-20 16:13:38.689: WARN/RecognitionManagerService(59): no available voice recognition services found
07-20 16:13:39.370: DEBUG/dalvikvm(59): GC_EXPLICIT freed 9347 objects / 593752 bytes in 302ms
07-20 16:13:39.590: DEBUG/dalvikvm(165): GC_EXPLICIT freed 2883 objects / 156272 bytes in 1275ms
07-20 16:13:39.659: INFO/installd(35): unlink /data/dalvik-cache/[email protected]@[email protected]
07-20 16:13:39.782: DEBUG/AndroidRuntime(118): Shutting down VM
07-20 16:13:39.789: DEBUG/jdwp(118): adbd disconnected
07-20 16:13:39.809: INFO/AndroidRuntime(118): NOTE: attach of thread 'Binder Thread #3' failed
07-20 16:13:39.879: INFO/ActivityThread(268): Publishing provider com.svox.pico.providers.SettingsProvider: com.svox.pico.providers.SettingsProvider
07-20 16:13:40.131: DEBUG/KeyguardViewMediator(59): pokeWakelock(5000)
07-20 16:13:40.429: DEBUG/KeyguardViewMediator(59): pokeWakelock(5000)
07-20 16:13:40.511: DEBUG/AndroidRuntime(278): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
07-20 16:13:40.511: DEBUG/AndroidRuntime(278): CheckJNI is ON
07-20 16:13:41.740: INFO/ActivityManager(59): Displayed activity com.android.launcher/com.android.launcher2.Launcher: 50234 ms (total 50234 ms)
07-20 16:13:42.340: DEBUG/AndroidRuntime(278): --- registering native functions ---
07-20 16:13:43.790: INFO/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.msi.androidrss/.ShowDescription }
07-20 16:13:43.890: DEBUG/AndroidRuntime(278): Shutting down VM
07-20 16:13:43.910: DEBUG/jdwp(278): adbd disconnected
07-20 16:13:43.960: INFO/AndroidRuntime(278): NOTE: attach of thread 'Binder Thread #3' failed
07-20 16:13:44.099: INFO/ActivityManager(59): Start proc com.msi.androidrss for activity com.msi.androidrss/.ShowDescription: pid=286 uid=10042 gids={1015}
07-20 16:13:45.939: INFO/ARMAssembler(59): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x2ff7e0:0x2ff8ec] in 7962326 ns
07-20 16:13:46.670: INFO/ActivityManager(59): Displayed activity com.msi.androidrss/.ShowDescription: 2691 ms (total 2691 ms)
**This is my manifest.xml**
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.msi.androidrss"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".RSSReader"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</intent-filter>
</activity>
</application>
</manifest>
**This is one of my .java program "RSSReader.java"**
Code:
package com.msi.androidrss;
import android.app.Activity;
import android.os.Bundle;
import android.view.*;
import android.widget.TextView;
import android.widget.ListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.util.Log;
import java.net.URL;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.content.Intent;
import com.msi.androidrss.ShowDescription;
public class RSSReader extends Activity implements OnItemClickListener
{
public final String RSSFEEDOFCHOICE = "http://www.ibm.com/developerworks/views/rss/customrssatom.jsp?zone_by=XML&zone_by=Java&zone_by=Rational&zone_by=Linux&zone_by=Open+source&zone_by=WebSphere&type_by=Tutorials&search_by=&day=1&month=06&year=2007&max_entries=20&feed_by=rss&isGUI=true&Submit.x=48&Submit.y=14";
private static final int SELECT = 0;
private static final int REFRESH = 1;
public final String tag = "RSSReader";
private RSSFeed feed = null;
/** Called when the activity is first created. */
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
// go get our feed!
feed = getFeed(RSSFEEDOFCHOICE);
// display UI
UpdateDisplay();
}
private RSSFeed getFeed(String urlToRssFeed)
{
try
{
// setup the url
URL url = new URL(urlToRssFeed);
// create the factory
SAXParserFactory factory = SAXParserFactory.newInstance();
// create a parser
SAXParser parser = factory.newSAXParser();
// create the reader (scanner)
XMLReader xmlreader = parser.getXMLReader();
// instantiate our handler
RSSHandler theRssHandler = new RSSHandler();
// assign our handler
xmlreader.setContentHandler(theRssHandler);
// get our data via the url class
InputSource is = new InputSource(url.openStream());
// perform the synchronous parse
xmlreader.parse(is);
// get the results - should be a fully populated RSSFeed instance, or null on error
return theRssHandler.getFeed();
}
catch (Exception ee)
{
// if we have a problem, simply return null
return null;
}
}
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
menu.add(0, RSSReader.SELECT, 0, "Choose RSS Feed").setIcon(android.R.drawable.ic_menu_mapmode);
//menu.add(0,0,"Choose RSS Feed");
//menu.add(0,1,"Refresh");
menu.add(0, RSSReader.REFRESH, 0, "Refresh").setIcon(android.R.drawable.ic_menu_mapmode);
Log.i(tag,"onCreateOptionsMenu");
return true;
}
@Override
public boolean onMenuItemSelected(final int featureId, final MenuItem item) {
switch (item.getItemId()) {
case RSSReader.SELECT:
Log.i(tag,"Set RSS Feed");
return true;
case RSSReader.REFRESH:
Log.i(tag,"Refreshing RSS Feed");
return true;
}
return false;
}
private void UpdateDisplay()
{
TextView feedtitle = (TextView) findViewById(R.id.feedtitle);
TextView feedpubdate = (TextView) findViewById(R.id.feedpubdate);
ListView itemlist = (ListView) findViewById(R.id.itemlist);
if (feed == null)
{
feedtitle.setText("No RSS Feed Available");
return;
}
feedtitle.setText(feed.getTitle());
feedpubdate.setText(feed.getPubDate());
ArrayAdapter<RSSItem> adapter = new ArrayAdapter<RSSItem>(this,android.R.layout.simple_list_item_1,feed.getAllItems());
itemlist.setAdapter(adapter);
itemlist.setOnItemClickListener(this);
itemlist.setSelection(0);
}
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
Log.i(tag,"item clicked! [" + feed.getItem(position).getTitle() + "]");
Intent itemintent = new Intent(this,ShowDescription.class);
Bundle b = new Bundle();
b.putString("title", feed.getItem(position).getTitle());
b.putString("description", feed.getItem(position).getDescription());
b.putString("link", feed.getItem(position).getLink());
b.putString("pubdate", feed.getItem(position).getPubDate());
itemintent.putExtra("android.intent.extra.INTENT", b);
startActivity(itemintent);
}
}
**This is one of my .java program "ShowDescription.java"**
Code:
package com.msi.androidrss;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.content.Intent;
import android.view.*;
public class ShowDescription extends Activity
{
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.showdescription);
String theStory = null;
Intent startingIntent = getIntent();
if (startingIntent != null)
{
Bundle b = startingIntent.getBundleExtra("android.intent.extra.INTENT");
if (b == null)
{
theStory = "bad bundle?";
}
else
{
theStory = b.getString("title") + "\n\n" + b.getString("pubdate") + "\n\n" + b.getString("description").replace('\n',' ') + "\n\nMore information:\n" + b.getString("link");
}
}
else
{
theStory = "Information Not Found.";
}
TextView db= (TextView) findViewById(R.id.storybox);
db.setText(theStory);
Button backbutton = (Button) findViewById(R.id.back);
backbutton.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
finish();
}
});
}
}
**As an output I am getting "*"NO RSS FEED AVAILABLE"*", why ?**
**HELP!!!**
I found the IBM tutorial very hard to follow, I eventually read RSS through a simpler way. Here is a link to the tutorial I wrote after:
http://droidapp.co.uk/?p=166
eatmold said:
I found the IBM tutorial very hard to follow, I eventually read RSS through a simpler way. Here is a link to the tutorial I wrote after:
http://droidapp.co.uk/?p=166
Click to expand...
Click to collapse
Thanks, could you plz upload the full source code ?
Does it support images and clickable feed so that clicking any feed directs the user to the website ?
I will upload the full source of my app today.
It will read any section of the xml so if there are images you will be able to extract the URL and use it in your app. It does support clickable feed also, just by extracting the post URL again.
The app I made is for an audio podcast.
Here you go... hope it helps
http://dl.dropbox.com/u/6876950/EppyGibbonPodcast.zip
help
hello tony,
first thank you for the source code.
I tried running your source code but I am getting these error messages:
Code:
Description Resource Path Location Type
Project 'EppyGibbonPodcast' is missing required library: 'C:\Users\Tony.DZNT\AndroidDev\android-sdk-windows\extras\android\compatibility\v4\android-support-v4.jar' EppyGibbonPodcast Build path Build Path Problem
The project cannot be built until build path errors are resolved EppyGibbonPodcast Unknown Java Problem
Attribute minSdkVersion (4) is lower than the project target API level (10) AndroidManifest.xml /EppyGibbonPodcast line 1 Android ADT Problem
This is the version of my eclipse:
Code:
Eclipse IDE for Java Developers
Version: Helios Service Release 2
Build id: 20110218-0911
I am using 2.2 but I can see you created this code for 2.3. I do have API installed for 3.0 and 3.1 etc so I should be at-least able to run the program on virtual mobile (on PC thru eclipse) but getting the above error msgs.
Please Help.
I just found the file "android-support-v4.jar" in this location:
D:\Android\AndroidSDK\android-sdk-windows\extras\android\compatibility\v4
now how and where I can link this path ?
eatmold said:
I found the IBM tutorial very hard to follow, I eventually read RSS through a simpler way. Here is a link to the tutorial I wrote after:
http://droidapp.co.uk/?p=166
Click to expand...
Click to collapse
very clean and precise. i really like well compartmentalized code
iamsuper123 said:
I just found the file "android-support-v4.jar" in this location:
D:\Android\AndroidSDK\android-sdk-windows\extras\android\compatibility\v4
now how and where I can link this path ?
Click to expand...
Click to collapse
Sorry, I must have left that in from when I was playing with Fragments, it's not needed. You can remove it from the build path. Right click the project, properties, then find and remove from build path.
Hi tony,
I did try to remove it and now I am getting these errors:
Code:
Description Resource Path Location Type
FragmentActivity cannot be resolved to a type podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 14 Java Problem
FragmentActivity cannot be resolved to a type podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 19 Java Problem
The import android.support cannot be resolved podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 8 Java Problem
The method findViewById(int) is undefined for the type podcast podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 24 Java Problem
The method findViewById(int) is undefined for the type podcast podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 27 Java Problem
The method findViewById(int) is undefined for the type podcast podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 30 Java Problem
The method getIntent() is undefined for the type podcast podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 32 Java Problem
The method onCreate(Bundle) of type podcast must override a superclass method podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 17 Java Problem
The method setContentView(int) is undefined for the type podcast podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 21 Java Problem
The method startActivity(Intent) is undefined for the type new View.OnClickListener(){} podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 57 Java Problem
The method startActivity(Intent) is undefined for the type new View.OnClickListener(){} podcast.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 67 Java Problem
AdapterView is a raw type. References to generic type AdapterView<T> should be parameterized main.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 50 Java Problem
Attribute minSdkVersion (4) is lower than the project target API level (10) AndroidManifest.xml /EppyGibbonPodcast line 1 Android ADT Problem
The import com.owentech.eppygibbonpodcast.R is never used arrays.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 3 Java Problem
I would deeply appreciate if you could upload a fresh copy of source code without this fragment file / issue.
thank you
OK. I'll upload again tomorrow.
thanks i will keep an eye on your site and here
I have re-uploaded the source, now without the Fragment compatability.
http://dl.dropbox.com/u/6876950/EppyGibbonPodcast.zip
Let me know if you have any problems, but this should run fine now.
Tony
thank you very much tony
it does work now.
I just get these warnings:
Code:
Description Resource Path Location Type
AdapterView is a raw type. References to generic type AdapterView<T> should be parameterized main.java /EppyGibbonPodcast/src/com/owentech/eppygibbonpodcast line 50 Java Problem
AdapterView is a raw type. References to generic type AdapterView<T> should be parameterized rsstest.java /rsstest/src/com/owentech/eppygibbonpodcast line 50 Java Problem
Attribute minSdkVersion (4) is lower than the project target API level (10) AndroidManifest.xml /EppyGibbonPodcast line 1 Android ADT Problem
I tested the code and I think it only works for the RSS FEED that you added in the code.
I tried other rss feed like "http://rss.news.yahoo.com/rss/mostviewed" mentioned on your website (in comments) and few other rss feeds but nothing seems to be working.
(thanks once for all the help)
I wouldn't worry about those warnings.
The app I have uploaded is specifically for the Epileptic Gibbon Podcast, which is a wordpress site.
The code should just need slight changes to match the rss feed you want to use. I suggest you download the rss xml for Epileptic Gibbon and the rss xml for Yahoo and compare the differences.
really great code.
Thanks.
I could really use some help.
I would like to use this app to pull feeds for this site.
http://las-vegas-drunk-driving-attorney.com/
But have no idea how to add this to eclipse and then turn it in to an app.
Could someone help out with the steps to take?
Thank.
Hi Guys,I am Developing an Android App for Local Bus Schedule, When Applying a specific Query, My App Crashes in As Soon as it starts.
Here is MY LOG:
Code:
03-12 07:33:54.564: E/SQLiteLog(3580): (1) near "pnotocdm": syntax error
03-12 07:33:54.564: D/AndroidRuntime(3580): Shutting down VM
03-12 07:33:54.564: W/dalvikvm(3580): threadid=1: thread exiting with uncaught exception (group=0x41665c80)
03-12 07:33:54.574: E/AndroidRuntime(3580): FATAL EXCEPTION: main
03-12 07:33:54.574: E/AndroidRuntime(3580): Process: com.arif.pnobusfinder, PID: 3580
03-12 07:33:54.574: E/AndroidRuntime(3580): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.arif.pnobusfinder/com.arif.pnobusfinder.MainActivity}: android.database.sqlite.SQLiteException: near "pnotocdm": syntax error (code 1): , while compiling: SELECT * pnotocdm where KEY_TIME = ?
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2215)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2265)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.app.ActivityThread.access$800(ActivityThread.java:145)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.os.Handler.dispatchMessage(Handler.java:102)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.os.Looper.loop(Looper.java:136)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.app.ActivityThread.main(ActivityThread.java:5081)
03-12 07:33:54.574: E/AndroidRuntime(3580): at java.lang.reflect.Method.invokeNative(Native Method)
03-12 07:33:54.574: E/AndroidRuntime(3580): at java.lang.reflect.Method.invoke(Method.java:515)
03-12 07:33:54.574: E/AndroidRuntime(3580): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
03-12 07:33:54.574: E/AndroidRuntime(3580): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-12 07:33:54.574: E/AndroidRuntime(3580): at dalvik.system.NativeStart.main(Native Method)
03-12 07:33:54.574: E/AndroidRuntime(3580): Caused by: android.database.sqlite.SQLiteException: near "pnotocdm": syntax error (code 1): , while compiling: SELECT * pnotocdm where KEY_TIME = ?
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
03-12 07:33:54.574: E/AndroidRuntime(3580): at com.arif.pnobusfinder.DatabaseHandler.getAllBus(DatabaseHandler.java:103)
03-12 07:33:54.574: E/AndroidRuntime(3580): at com.arif.pnobusfinder.MainActivity.onCreate(MainActivity.java:55)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.app.Activity.performCreate(Activity.java:5231)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-12 07:33:54.574: E/AndroidRuntime(3580): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
03-12 07:33:54.574: E/AndroidRuntime(3580): ... 11 more
Here's my Code.
Code:
public class DatabaseHandler extends SQLiteOpenHelper {
// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "timetable";
// Bus table name
static final String TABLE_PNOTOCDM = "pnotocdm";
// Bus Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_BUSNAME = "busname";
private static final String KEY_TIME = "time";
...
public List<Pnotocdm> getAllBus() {
List<Pnotocdm> busList = new ArrayList<Pnotocdm>();
// Select All Query
String selectQuery = " SELECT * " + TABLE_PNOTOCDM + " where KEY_TIME = ? " ;
SQLiteDatabase db = this.getWritableDatabase();
Calendar cal = Calendar.getInstance();
int minute = cal.get(Calendar.MINUTE);
int hour = cal.get(Calendar.HOUR);
String time = String.valueOf(hour)+String.valueOf(minute);
Cursor cursor = db.rawQuery(selectQuery, new String[] {time});
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Pnotocdm bus = new Pnotocdm();
bus.setID(Integer.parseInt(cursor.getString(0)));
bus.setBusName(cursor.getString(1));
bus.setTime(cursor.getString(2));
String name = cursor.getString(1) +"\n"+ cursor.getString(2);
Third.ArrayofName.add(name);
// Adding bus to list
busList.add(bus);
} while (cursor.moveToNext());
}
// return bus list
return busList;
}
I Know the rawquery is wrong but i dont know the Correct Query.
What I Intended is this, The System should compute the Current Time and Check with time Column in the table and Return those values which are greater than the current Time.
The Correct Query Which works in sqlite Browser is
Code:
SELECT busname,time FROM pnotocdm WHERE time>time('now','localtime');
But I dont know how to convert that sql query into java rawquery() method. Please Help
ariftwister said:
Hi Guys,I am Developing an Android App for Local Bus Schedule, When Applying a specific Query, My App Crashes in As Soon as it starts.
Here's my Code.
Code:
public List getAllBus() {
List busList = new ArrayList();
// Select All Query
String selectQuery = " SELECT * " + TABLE_PNOTOCDM + " where KEY_TIME = ? " ;
SQLiteDatabase db = this.getWritableDatabase();
Calendar cal = Calendar.getInstance();
int minute = cal.get(Calendar.MINUTE);
int hour = cal.get(Calendar.HOUR);
String time = String.valueOf(minute)+String.valueOf(hour);
Cursor cursor = db.rawQuery(selectQuery, new String[] {time});
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Pnotocdm bus = new Pnotocdm();
bus.setID(Integer.parseInt(cursor.getString(0)));
bus.setBusName(cursor.getString(1));
bus.setTime(cursor.getString(2));
String name = cursor.getString(1) +"\n"+ cursor.getString(2);
Third.ArrayofName.add(name);
// Adding bus to list
busList.add(bus);
} while (cursor.moveToNext());
}
// return bus list
return busList;
}
I Know the rawquery is wrong but i dont know the Correct Query.
What I Intended is this, The System should compute the Current Time and Check with time Column in the table and Return those values which are greater than the current Time.
Click to expand...
Click to collapse
Important questions first :
What error do you get ? like a NullPointerException or a CursorIndexOutOfBounds etc.
A standard sql syntax for a query would be
SELECT "Column Name" FROM "TABLE NAME" WHERE "your column" = "desired value" I cant say a word more on the query because i dont know what the variables TABLE_PNOTOCDM and KEY_TIME represent
A structure of your table could make things easier
I think u meant
Code:
String time = String.valueOf(hour)+String.valueOf(minute);
instead of
String time = String.valueOf(minute)+String.valueOf(hour);
and if can spare some time please read http://forum.xda-developers.com/showthread.php?t=2439748
Sent from my GT-S5302 using Tapatalk 2
sak-venom1997 said:
Important questions first :
What error do you get ? like a NullPointerException or a CursorIndexOutOfBounds etc.
A standard sql syntax for a query would be
SELECT "Column Name" FROM "TABLE NAME" WHERE "your column" = "desired value" I cant say a word more on the query because i dont know what the variables TABLE_PNOTOCDM and KEY_TIME represent
A structure of your table could make things easier
I think u meant
Code:
String time = String.valueOf(hour)+String.valueOf(minute);
instead of
String time = String.valueOf(minute)+String.valueOf(hour);
and if can spare some time please read http://forum.xda-developers.com/showthread.php?t=2439748
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
Sorry For the Inaccurate Details in my Problem, now i have included all the details
ariftwister said:
Sorry For the Inaccurate Details in my Problem, now i have included all the details
Click to expand...
Click to collapse
looks like a syntax error in your raw query
SELECT "Column Name" FROM "TABLE NAME" WHERE "your column" = "desired value"
Sent from my GT-S5302 using Tapatalk 2
sak-venom1997 said:
looks like a syntax error in your raw query
SELECT "Column Name" FROM "TABLE NAME" WHERE "your column" = "desired value"
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
I got the sql query syntax correct but how to change it to java syntax,?
Sent from my Xperia Mini using Tapatalk 2
ariftwister said:
I got the sql query syntax correct but how to change it to java syntax,?
Sent from my Xperia Mini using Tapatalk 2
Click to expand...
Click to collapse
No dude your SQL syntax is not correct it should look like
String selectQuery = " SELECT * FROM "+TABLE_PNOTOCDM + " WHERE "+KEY_TIME+" = ? " ;
Sent from my GT-S5302 using Tapatalk 2
ariftwister said:
I got the sql query syntax correct but how to change it to java syntax,?
Sent from my Xperia Mini using Tapatalk 2
Click to expand...
Click to collapse
You forgot 'from'
Sent from my GT-S5570 using XDA Premium 4 mobile app
arpitkh96 said:
You forgot 'from'
Sent from my GT-S5570 using XDA Premium 4 mobile app
Click to expand...
Click to collapse
Yes... Thanks...Thats the mistake.. Now the Query is running without any crashes/error. But i dont get the Result i am expecting. I want the rows which is greater than the current time. how to achieve this ?
Code:
SELECT * FROM pnotocdm WHERE time > time('now','localtime');
I want the java query equivalent to the above sql query. Any Help ?
ariftwister said:
Yes... Thanks...Thats the mistake.. Now the Query is running without any crashes/error. But i dont get the Result i am expecting. I want the rows which is greater than the current time. how to achieve this ?
Code:
SELECT * FROM pnotocdm WHERE time > time('now','localtime');
I want the java query equivalent to the above sql query. Any Help ?
Click to expand...
Click to collapse
I think you should firstly check your query in sql then use here.
And your loop maybe the problem.i used like this
while(cursor.moveToNext()){
//get your values
}
Sent from my GT-S5570 using XDA Premium 4 mobile app
^ solved this problem.. Thanks every one.
Sent from my Xperia Mini using Tapatalk 2
I got another problem.
Here's what I'm trying to do,
1. Launch Activity A, Press Button Goto Activity B, Press Button Goto Activity C.
2. Press back button goto Activity B (Activity C is not paused but destroyed)
3. Press button and goto Activity C now again onCreate method is called and activity C is created again.
So why is this happening to my app. I want the activities to pause. How to achieve this?
Thanks in advance.
Sent from my Xperia Mini using Tapatalk 2
when I try to use ShowcaseView I get error
Code:
@override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final ImageButton saveButton = (ImageButton) view.findViewById(R.id.button_Save);
ViewTarget viewTarget = new ViewTarget(saveButton);
showcaseView = new ShowcaseView.Builder(getActivity())
.setTarget(viewTarget)
.setContentTitle("Reset Button")
.setContentText("This will erase all the data in the table except the line that in progress")
.build();
}
when I tried to do the same thing in my fragmentactivity and didn't work, but when I did the same thing but took a view that declared in the fragmentactivity and not in the fragment it worked.
Logcat:
Code:
FATAL EXCEPTION: main
java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:724)
at android.graphics.Bitmap.createBitmap(Bitmap.java:703)
at android.graphics.Bitmap.createBitmap(Bitmap.java:670)
at com.github.amlcurran.showcaseview.ShowcaseView.updateBitmap(ShowcaseView.java:169)
at com.github.amlcurran.showcaseview.ShowcaseView.onGlobalLayout(ShowcaseView.java:343)
at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:839)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2050)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6364)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:561)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
I understand what the error said but how can I fix it?
Basically what I am trying to do is open this testing menu (*#*#4636*#*#) via an app that I am making using Android Studio
I will leave you some screenshots so you know what I am talking about
I have the code that opens the app, but I am missing the package name and/or the activity name that will cause this menu to show up.
Code:
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.chartcross.gpstest"); // This launches GPS test app, I need to launch the testing menu
startActivity(launchIntent);
Thank you! :good:
Try this:
Code:
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:*#*#4636#*#*"));
startActivity(intent);
or
Code:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.TestingSettings");
startActivity(intent);
@mmdeveloper said:
Try this:
Code:
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:*#*#4636#*#*"));
startActivity(intent);
or
Code:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.TestingSettings");
startActivity(intent);
Click to expand...
Click to collapse
Thank you very much, the second one worked fine :good:
When the testing app starts it opens this menu:
Instead, I want it to open directly this menu:
That activity is called com.android.settings.TestingSettingsBroadcastReceiver, but when I do this:
Code:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.TestingSettingsBroadcastReceiver");
startActivity(intent);
The app just crashes with this error:
Code:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.feche.manual3gtoggle/com.feche.manual3gtoggle.Toggle3G}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.settings/com.android.settings.TestingSettingsBroadcastReceiver}; have you declared this activity in your AndroidManifest.xml?
Any idea of why? It says something that I should add to AndroidManifest.xml but since I am new to this I really don't understand to what it reffers. Thanks
EDIT:
Nevermind, I just found out that is called com.android.settings.RadioInfo instead of com.android.settings.TestingSettingsBroadcastReceiver, thanks anyways :highfive:
For your future reference,
Every class which extends activity or fragmentactivity or app combat activity etc.
Then you need to declare that particular class in your AndroidManifest.xml
mantlabs said:
Try this:
Code:
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:*#*#4636#*#*"));
startActivity(intent);
or
Code:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.TestingSettings");
startActivity(intent);
Click to expand...
Click to collapse
above code is not working in my sample do i need to add any permissions in Manifest file can you please help in this thing
sujith.e said:
above code is not working in my sample do i need to add any permissions in Manifest file can you please help in this thing
Click to expand...
Click to collapse
What Android version are you trying? This post was almost 6 years ago.
Hello!
I'm trying to develop my first game in java for android(actually, the game itself is practically done), but now I decided to add admob ads.
The problem is, that when I add to my class "extends Activity", which is neccessary, I get an error "Can't create handler inside thread that has not called Looper.prepare()".
Here is full error:
Code:
06-25 08:55:09.523: E/AndroidRuntime(583): FATAL EXCEPTION: GLThread 5679
06-25 08:55:09.523: E/AndroidRuntime(583): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
06-25 08:55:09.523: E/AndroidRuntime(583): at android.os.Handler.<init>(Handler.java:121)
06-25 08:55:09.523: E/AndroidRuntime(583): at android.app.Activity.<init>(Activity.java:735)
06-25 08:55:09.523: E/AndroidRuntime(583): at com.my.game.GameScreen.<init>(GameScreen.java:67)
06-25 08:55:09.523: E/AndroidRuntime(583): at com.my.game.MainMenuScreen.render(MainMenuScreen.java:157)
06-25 08:55:09.523: E/AndroidRuntime(583): at com.badlogic.gdx.Game.render(Game.java:46)
06-25 08:55:09.523: E/AndroidRuntime(583): at com.my.game.render(MyGame.java:74)
06-25 08:55:09.523: E/AndroidRuntime(583): at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:422)
06-25 08:55:09.523: E/AndroidRuntime(583): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
06-25 08:55:09.523: E/AndroidRuntime(583): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
I read that this error is something with background threads, which I'm not using.
In GameScreen the error occurs here:
Code:
public GameScreen(final MyGame gam) {
In MainMenuScreen:
Code:
game.setScreen(new GameScreen(game));
When I remove "extends Activity" from here(in GameScreen):
Code:
public class GameScreen extends Activity implements Screen {
final MyGame game;
//Defining some textures and variables here
public GameScreen(final MyGame gam) {
this.game = gam;
//some stuff here
if(MyGame.versionStatus == 0)
{
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("TEST_DEVICE_ID")
.build();
adView.loadAd(adRequest);
}
//more stuff here
}
...the problem disappears, but ads don't show
Can you please help me solve it?
You need to add this
runOnUiThread(new Runnable() { public void run() {
// add your stuff here
} });
Hm... I'm not quite sure where exactly should I put it...
I tried that way:
Code:
public GameScreen(final MyGame gam) {
this.game = gam;
runOnUiThread(new Runnable() { public void run() {
//some stuff here
if(MyGame.versionStatus == 0)
{
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("TEST_DEVICE_ID")
.build();
adView.loadAd(adRequest);
}
//more stuff here
}});
}
But it didn't work :/
Still the same error...
urban07 said:
Hm... I'm not quite sure where exactly should I put it...
I tried that way:
Code:
public GameScreen(final MyGame gam) {
this.game = gam;
runOnUiThread(new Runnable() { public void run() {
//some stuff here
if(MyGame.versionStatus == 0)
{
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("TEST_DEVICE_ID")
.build();
adView.loadAd(adRequest);
}
//more stuff here
}});
}
But it didn't work :/
Still the same error...
Click to expand...
Click to collapse
Hello,
Maybe try using getApplicationContext() intead this here:
Code:
AdView adView = (AdView)this.findViewById(R.id.adView);
Try commenting your //some stuff
and see if you still have the problem.
Also, where is your onCreate() method? You should create the AdView there (you are extending an Activity). Create it inside the onCreate method after the setContentView with your xml.
If you still need help, feel free to ask
@mmdeveloper said:
Hello,
Maybe try using getApplicationContext() intead this here:
Code:
AdView adView = (AdView)this.findViewById(R.id.adView);
Try commenting your //some stuff
and see if you still have the problem.
Also, where is your onCreate() method? You should create the AdView there (you are extending an Activity). Create it inside the onCreate method after the setContentView with your xml.
If you still need help, feel free to ask
Click to expand...
Click to collapse
Oh, right... I forgot to say that I moved ad creating to onCreate method Instead of main method.
And how should I use getApplicationContext() in this case?
EDIT: Oh, and yes, when I put all my stuff into comment, I still get this error :/
I suppose I have a really dumb mistake somewhere in code that I can't find... But maybe it's something else.
However, when I remove "extends Activity", there is no error(as well as ads) so I think it is some little, invisible bug :<
Take a look here
I have no experience in libgdx, but it seems that you need to create a layout, create the libgdx View and the AdView and add both of them to the layout in your AndroidApplication
@mmdeveloper said:
Take a look here
I have no experience in libgdx, but it seems that you need to create a layout, create the libgdx View and the AdView and add both of them to the layout in your AndroidApplication
Click to expand...
Click to collapse
Hm... Thanks, I'll be sure to check it out
Maybe it'll help
EDIT:
I've moved all ads-connected commands to AndroidLauncher.java and removed "extends Activity" from GameScreen, and it seems to be working - in logcat, not on my phone
In logcat I can see info like:
06-26 15:41:09.165: I/Ads(25106): Starting ad request.
06-26 15:41:20.766: I/Ads(25106): Scheduling ad refresh 150000 milliseconds from now.
06-26 15:41:21.216: I/Ads(25106): Ad finished loading.
Click to expand...
Click to collapse
.... but then:
06-26 15:43:50.792: I/Ads(25106): Ad is not visible. Not refreshing ad.
06-26 15:43:50.792: I/Ads(25106): Scheduling ad refresh 60000 milliseconds from now.
06-26 15:44:50.791: I/Ads(25106): Ad is not visible. Not refreshing ad.
06-26 15:44:50.791: I/Ads(25106): Scheduling ad refresh 60000 milliseconds from now.
Click to expand...
Click to collapse
Ok, the ad is fully working now - somehow I figured it out, but thanks for a great trace - it really helped me