Source not found for the file Activity.class - android

I have a problem with creating more than one activity in an Android project. The problem occurs only when i'm debugging. It's not a runtime error. I don't have any clue why i still keep getting this error. I already did a lot of research but now I'm a bit desperate because solutions on the web didn't solve the problem.
The error more detailed:
Source not found
Source not found for the file Activity.class error
The source attachment does not contain the source for the file Activity.class
[Button] Change Attached Source
When i click on that button i see the path to the android.jar file:
C:/Program Files/android/platforms/android-19/android.jar
[SOLVED]
This is an good tutorial how to solve this problem.
https://www.youtube.com/watch?v=IdIZ7r2d4J4

Looking at your code i notice a few anomalies.Please use
protected void onCreate()
and not public void onCreate()

I'm not familiar with Java for Android but it looks like your code is trying to use the same UI space for two fullscreen windows.

May be it is something with casing?
Can you be more specific about your problem.
1) Is it a compile error or runtime?
2) What message you got in either case?
Original doc: http://developer.android.com/training/basics/firstapp/starting-activity.html
Simple code for starting second activity by button with id = button
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button) findViewById(R.id.button);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, SecondActivity.class);
startActivity(i);
}
});
}

Related

Problem Onclick + "v" does not recognize the methods in android studio code

I am fairly new to programming, I was writing an application code in Android Studio but had a problem
It turns out that when I put this line in my code (In image)
it does not detect it and an error occurs both with "onClick" and with "(v)" I reached this point and I don't know how to solve it
Attached images:
[1]: https://i.stack.imgur.com/huZLu.png Error Code
[2]: https://i.stack.imgur.com/hCJYJ.png All Code
I would really appreciate the answer
This problem is eating my head!
Thank you
it's not a big problem, you can write like this, it will solve your issue
mOpicon2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});

Android twitter connection/authentication intent bad formed?

I've been trying to connect to twitter through android for a while.
I'm currently using this api: http://kenai.com/projects/twitterapime/forums/forum/topics/13327-Twitter-API-ME-1-8-Now-with-OAuth-support
I used their exemple with my keys and everything connects without problem. So no problem with configuration.
But in my project which has exactly the same code I can't make it work.
I believe its related with the creation of a new Intent (also this is where the eclipse is point the error)
Im trying to use a custom layout but I don't know what do I need to change to make this specific Twitter layout to work. On main activity I have a button with this:
public void onClick(View v)
{
startActivity(new Intent(this,Twitter.class));
}
on twitter class
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//this.webView = (WebView) findViewById(R.id.webView1);
WebView myWebView = new WebView(this);
setContentView(myWebView);
authenticate();
}
private void authenticate()
{
WebViewOAuthDialogWrapper page = new WebViewOAuthDialogWrapper(webView);
page.setConsumerKey(CONSUMER_KEY);
page.setConsumerSecret(CONSUMER_SECRET);
page.setCallbackUrl(CALLBACK_URL);
page.setOAuthListener(this);
page.login();
}
what requirements/adjustments are needed to make/change to the Twitter activity?
I believe I need to change something in the intent-filter but I don't even understand the work of intents. I've been only making easy layouts.
Note that I also gave internet permissions already.
Looks like i was making 2 mistakes.
First i was trying to use "webView" variable in WebViewOAuthDialogWrapper instead
"myWebView" so it wasn't initialized...
Second looks like i forgot to put the order of which the external libraries were loaded....
So be sure to put external libraries on top in eclipse project.
Lost about 2 days with these problems... oh well

How link 2 layout with a Button

I don't speak english very well, so please try to understand me.
iìm trying to develop a little app for android in eclipse. I've create 2 layout where, in first there are a button and in a second there is only the text "helloword". I want that the button to send me at the "helloworld" layout
I followed a tutorial but it's not correct.
Someone can help me posting th code to implement??
Excuse my English still
and thanks for any help
You need to create two different Activities, with separate layouts. You set their layouts using setContentView inside onCreate. Don't forget to include your activities in the manifest (eclipse generated one for you. follow how it was done in the first activity and you should be fine. no need to add the filters and such, just the .Activity)
then in your first activity's button, do this:
my_button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(this, MySecondActivity.class);
startActivty(i);
}
});
If you want to use just 1 activity then use the following code,
my_button.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
FirstActivity.this.setContentView(R.layout.second_layout);
}
});
Its not so hard just do this:
#Override
public void onClick(View args0) {
setContentView(R.layout.aardelayout);
}
just a simple Search on google and you find your answer .
see this tutorials ( two are in frensh if you are prefering frensh tutorials ) :
tuto1
tuto2
tuto3

Button's OnClick handler can't decide if or what it wants to override

I can get the following to compile (by commenting out the "#Override"):
Button buttonAuthorizeUsers = (Button) findViewById(R.id.buttonAuthorizeUsers);
buttonAuthorizeUsers.setOnClickListener(new OnClickListener() {
//#Override
public void onClick(View v) {
Intent configure = new Intent(OnDemandAndAutomatic_Activity.this, Configure_Activity.class);
OnDemandAndAutomatic_Activity.this.startActivity(configure);
}
});
...but it causes my app to crash. When I comment out it runs fine (but I have no button handler).
Should the class have a "implements OnClickListener"? It seems like I should, but it compiles without it, and won't compile WITH it (whether I comment out the "override" or not, it's unhappy).
as per my suggestion, it is not good to remove #Override line. you need to change to JDK version in your eclipse then you will not get such errors. Follow, following steps for it,
Right Click on your Project & select Properties.
Then from the left section Select Java Compiler & select the Version of the JDK you installed. If it is already selected then de-select it & try it.
Dont remove #Override. just replace
setOnClickListener(new OnClickListener() {
with setOnClickListener(new View.OnClickListener() {
and also replace implements OnClickListener with implements View.OnClickListener in your class declaration line.
save and then compile . your problem will get solved.

How design a button in Eclipse for Android App, so when you click, it takes you to a website

I already asked this question, but got answers that don't work and it counted as "Answered". Maybe someone knows how to design button in Eclipse for an Android app, so it takes you to a website ?Let's say this website.Thanks a lot.
Say u wanna go to google.com
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onOpenWebBrowser(View v)
{
Intent webPageIntent = new Intent(Intent.ACTION_VIEW);
webPageIntent.setData(Uri.parse("https://www.google.co.in/"));
try {
startActivity(webPageIntent);
} catch (ActivityNotFoundException ex) {
}
}
}
Make sure u add uses internet permission to the manifest!
you can refer the following to get an idea ,
see this vogella from there, you can get idea how to create android app which has a Button
http://www.vogella.de/articles/Android/article.html
and then create WebView in xml and map it in java, as
http://developer.android.com/resources/tutorials/views/hello-webview.html
and For mor info refer android people.com
http://www.androidpeople.com/
http://developer.android.com/resources/samples/index.html
and also read my blog to know about android basics
http://sankarganesh-info-exchange.blogspot.com/p/corridor-your-foremost-footstep-in.html
You would need to set up an OnClickListener and tie it to your button. In the Listener's onClick method, you would load the specified URL into the WebView, which, based on your comments, it sounds like you've got that part figured out.

Categories

Resources