Can't use Document in jsoup - java

I'm trying to use jsoup to parse HTML to my android app.
but It seems the error occur at Document.
"Document cannot be resolved to be a type"
"Jsoup cannot be resolved"
Could anyone help me solve this? because I've not found the way to solve it.
import java.net.URL;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
URL url = new URL("http://google.com");
Document document = Jsoup.parse(url, 5000);
}

"Jsoup cannot be resolved"
Because you didn't import the library properly. You have to make a lib folder put the .jar in the folder then, add the build path.

Related

Android SDK - Changing Properties in Array List

Can anyone please help me out. I'm having problems changing my array list properties. I am more familiar with changing properties via the XML file. Here is my code:
package com.example.examproject;
import java.util.Random;
import android.os.Bundle;
import android.app.ListActivity;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.content.Intent;
public class Menu_Lists extends ListActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] myAttractions = new String[2];
myAttractions[0] = "Grocery List";
myAttractions[1] = "Go Back";
setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, myAttractions));
}
protected void onListItemClick(ListView l, View v, int position, long id) {
switch(position) {
case 0: {
startActivity(new Intent(Menu_Lists.this, MainActivity.class));
break;
}
default: {
startActivity(new Intent(Menu_Lists.this, MainActivity.class));
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
What I would like to do is to change the background color. That's my main goal. I would also like each option to change color whenever the user hovers over a specific option.
Please go easy with the terminologies as well. I am still a beginner with Android SDK.
Thanks in advance.

Runtime error : NullPointerException in android although it is working on java normally

package com.example.climaconproject;
import java.net.InetSocketAddress;
import java.util.Collection;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
import com.nxp.jip.JIPImpl;
import com.nxp.jip.PacketHandlerIPv6;
import com.nxp.jip.exception.JipException;
import com.nxp.jip.service.JenNetIPNetwork;
import com.nxp.jip.service.Node;
import com.nxp.jip.service.Service;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView display= (TextView) findViewById(R.id.textView2);
PacketHandlerIPv6 my_packet = new PacketHandlerIPv6();
JIPImpl my_jip = new JIPImpl(my_packet);
Service service =new Service(my_jip);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
and the runtime error is
Fatal exception: receive
java.lang.NullExceptionPointer
at com.nxp.jip.PacketHandlerIPv6$ReceiveWorker.run(PAcketHandlerIPv6.java:223)
When i run the same lines of the code on a java program it works normally but in android the NullPointerException runtime error appears
You need at least the internet permission. Edit your AndroidManifest.xml and add
<uses-permission android:name="android.permission.INTERNET" />
inside the manifest element i.e. outside application.

How to put Interfaces in a library for android App

to the point, i am working in a library for android app's, all programing part is almost finish, i am testing a idea.
the idea is put some interfaces in the librery that i am working, and this GUI can be loaded in the main app.
i try to do it but i get to error the first was i did not declare the activity in the AndroidManifest in the main app, the second one is the one a i cant solve, the autogenerated Class R don't capture the GUI that it is in the librery.
it is anyway i can do this or it is imposible.
code to see what i am trying todo
in my librery (movilsecure)
EmisionActivity.java (have the activity_emision.xml in the res of my librery)
in the Main Android App (
import ve.com.idyseg.movilsecure.EmisionActivity;
import ve.com.idyseg.movilsecure.MSMasterControllerTEST;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void captureEvent (View v){
Intent intento = new Intent(this,EmisionActivity.class);
startIntent(intento);
}
}
In Eclipses, right click the project, the click Build Path then click Add Library. Please comment if you're still stuck.
In the library's manifest, in the <activity> node, did you set android:exported="true"?
Example:
<activity
android:name="com.example.app.EmisionActivity"
android:exported="true">
</activity>

The import android.widget.TextView cannot resolve

Here's the code:
package com.example.sample;
import android.os.Bundle;
import android.widget.TextView; // (errorL:" the import android.widget.TextView cannot resolve")
import android.app.Activity;
import android.view.Menu;
public class PlayerActivity extends Activity {
int count=0;
TextView // error:"syntax error on token "TextView",delete this tokon)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_player);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.player, menu);
return true;
}
}
Go to Project > Clean on eclipse.
Sometimes eclipse does that to you. First of all, try to exit out from eclipse and restart it, it should fix your issue. If it doesn't try Project->clean project. If it still doesn't work, make sure you haven't mess up with R.java file. If you are not sure, simply create new project and copy, Paste your code.
I hope this helps.

trying to dynamically insert photos into horizontalscrollview (android)

I am trying to extract photos from my drawable folder into an ImageView array and add the views from the array as childs to the linearlayout which is part of the horizontalscrollview.
However when I launch the app, it stops unexpectedly. Would anyone know if there is any problem with my code. Thanks a mil for your help.
package com.example.myfirstapp;
import java.lang.reflect.Field;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.text.Layout;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class NewGallery extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_gallery);
LinearLayout gallery = (LinearLayout) findViewById(R.id.mygallery);
Field[] field = R.drawable.class.getFields();
final int arraylength = field.length;
ImageView[] images = new ImageView[arraylength];
for (int i=0; i<=arraylength; i=i+1)
{
images[i] = new ImageView(getApplicationContext());
images[i].setImageDrawable(getResources().getDrawable(getResources().getIdentifier("icon"+i, "drawable", getPackageName())));
gallery.addView(images[i]);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_new_gallery, menu);
return true;
}
If you are using Eclipse, refer to logcat error messages. I think you got a ClassCastException due to incorrect casting :
LinearLayout gallery = (LinearLayout) findViewById(R.id.mygallery).
Are you sure you are casting the correct view ?

Categories