Issue with program ab - java

when using the ab.jar in eclipse I get the following error when trying to run the bot.
“Could not find class ‘org.alicebot.ab.Bot’, referenced from method…”. The chat class is being imported but the bot class cannot be imported.
Here is my code:
import org.alicebot.ab.Bot;
import org.alicebot.ab.Chat;
import android.annotation.SuppressLint;
import android.app.ActionBar.LayoutParams;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
public class MainActivity extends Activity {
String usertext; String response;
String botname="MAVIS";
Bot mavis=new Bot(botname);
Chat chat= new Chat(mavis);
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final LinearLayout ll1 = (LinearLayout) findViewById(R.id.ll1);
final LinearLayout ll2 = (LinearLayout) findViewById(R.id.ll2);
final ScrollView scv = (ScrollView) findViewById(R.id.sv);
final Button btn = (Button) findViewById(R.id.button1);
final EditText medit = (EditText) findViewById(R.id.editText1);
btn.setOnClickListener(new View.OnClickListener() {
#SuppressLint("NewApi")
#Override
public void onClick(View v) {
TextView tvu=new TextView(v.getContext());
TextView tvb=new TextView(v.getContext());
TextView tvut=new TextView(v.getContext());
TextView tvbt=new TextView(v.getContext());
TextView tvdivider1=new TextView(v.getContext());
TextView tvdivider2=new TextView(v.getContext());
final LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
tvu.setLayoutParams(lparams);
tvb.setLayoutParams(lparams);
tvut.setLayoutParams(lparams);
tvbt.setLayoutParams(lparams);
tvdivider1.setLayoutParams(lparams);
tvdivider2.setLayoutParams(lparams);
usertext = medit.getText().toString();
if(usertext.trim().length() != 0){
ll1.addView(tvu);
ll1.addView(tvb);
ll2.addView(tvut);
ll2.addView(tvbt);
ll1.addView(tvdivider1);
ll2.addView(tvdivider2);
response=chat.multisentenceRespond(usertext);
tvu.setText("User");
tvb.setText(botname);
tvbt.setText(" : "+ response);
tvut.setText(" : "+ usertext);
medit.setText(" ");
tvdivider1.setText(" ");
tvdivider2.setText(" --------------------");
}
else{
//do nothing
}
}
});
scv.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
scv.post(new Runnable() {
public void run() {
scv.fullScroll(View.FOCUS_DOWN);
}
});
}
});
}
}
I have imported the external library and defined the classpath for it. I have also copied the ab.jar in my project folder and even defined the classpath for it. But nothing seems to be working. Am I doing this wrong or are there more libraries that are needed for this to work. Anybody have a solution to my problem?

Your bot name here is MAVIS..did you change the folder name from the bots.zip???else change it..or simply use the predefined bot names(alice2 etc).
Thankz

Related

RunTime error in android studios, with no syntax errors. Created program programmatically

I am new to android studios and was tasked with creating an app programmatically. Depending on which button is pressed, the color description is displayed. I have a feeling it has something to do with the layout I created. Every time I run the program the app crashes and I cannot figure out why. Below is my code:
package com.example.hw3ex2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.view.ViewGroup.LayoutParams;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
LinearLayout layout;
LinearLayout.LayoutParams layoutParams;
String plumDescription = getResources().getString(R.string.plum_is);
String blueDescription = getResources().getString(R.string.blue_is);
String goldDescription = getResources().getString(R.string.gold_is);
String descriptionString;
TextView tv;
Button btnPlum;
Button btnBlue;
Button btnGold;
private int button_color = getResources().getColor(R.color.button_color);
private int background_color=getResources().getColor(R.color.background_color);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buildGUIByCode();
}
private void buildGUIByCode() {
LayoutParams params =
new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
//create a layout
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
//create textview
tv = new TextView(this);
tv.setLayoutParams(params);
layout.addView(tv);
//create buttons and add them to layout
btnPlum = new Button(this);
btnPlum.setTag("plum");
btnPlum.setText("Plum");
btnPlum.setLayoutParams(params);
layout.addView(btnPlum);
btnPlum.setOnClickListener(this);
btnPlum.setBackgroundColor(button_color);
btnBlue = new Button(this);
btnBlue.setTag("blue");
btnBlue.setText("Blue");
btnBlue.setLayoutParams(params);
layout.addView(btnBlue);
btnBlue.setOnClickListener(this);
btnBlue.setBackgroundColor(button_color);
btnGold = new Button(this);
btnGold.setTag("gold");
btnGold.setText("Gold");
btnGold.setLayoutParams(params);
layout.addView(btnGold);
btnGold.setOnClickListener(this);
btnGold.setBackgroundColor(button_color);
setContentView(layout);
}
#Override
public void onClick(View view) {
Object tag = view.getTag();
if ("plum".equals(tag)) {//get plum_is string and display in textView
tv.setText(plumDescription);
} else if ("blue".equals(tag)) {//get blue_is string and display in textview
tv.setText(blueDescription);
} else if ("gold".equals(tag)) {//get gold_is string and display in textview
tv.setText(goldDescription);
}
System.out.println(descriptionString);
}
}
I see that you're invoking getResources() before onCreate,
you need to move all of those initialization that uses getResources() within onCreate
public class MainActivity ... {
String plumDescription; // don't initialize here
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
plumDescription = getResources().getString(R.string.plum_is); // initialize after onCreate
}
}

How to set a RelativeLayout background color?

I am trying to set a RelativeLayout backgroundColor and I get cannot resolve symbol
here is my code
package com.example.butka.clickme;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import java.util.Random;
public class MainActivity extends AppCompatActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
//set layout
super.onCreate(savedInstanceState);
RelativeLayout layout1 = new RelativeLayout(this);
layout1.setBackgroundColor(Color.BLACK);
//LayoutParameters
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
params.addRule(RelativeLayout.CENTER_VERTICAL);
//button
Button btn = new Button(this);
btn.setText("Click me");
btn.setBackgroundColor(Color.WHITE);
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
colors();
}
});
//add stuff
layout1.addView(btn, params);
setContentView(layout1);
}
//void on button click
private void colors()
{
Random random = new Random();
short num1 = (short)random.nextInt(9);
if(num1 == 0)
{
layout1.setBackgroundColor(Color.BLACK);
}
}
}
everything runs good, until the color void. the error is cannot resolve symbol But the interesting thing is that I can set the color using layout.setBackgroundColor() before the void.
So the question is, how do you set a layout backgroudColor?
Use this:
layout1.setBackgroundColor(ContextCompat.getColor(this, R.color.black));
or
layout1.setBackgroundColor(Color.parseColor("#000000"));
Your RelativeLayout is in the onCreate() method scope, you must move it to class scope. Like this:
public class MainActivity extends AppCompatActivity {
RelativeLayout layout1; // Make it class scope.
#Override
protected void onCreate(Bundle savedInstanceState) {
//set layout
super.onCreate(savedInstanceState);
RelativeLayout layout1 = new RelativeLayout(this);
layout1.setBackgroundColor(Color.BLACK);
...
}
// Then you can access it from other method:
private void colors() {
Random random = new Random();
short num1 = (short)random.nextInt(9);
if(num1 == 0) {
layout1.setBackgroundColor(Color.BLACK); // You can access it now.
}
}

I want to copy the content of my first activity (i.e the java code ) to my fragment on the click of a button

This is My activity on which there is a button (Source Code) and i want if i click on that button then it should paste all the content(i.e java code of the activity) to my fragment
This is my Fragment . I want to that my java code should be copied to java fragment and xml code should copy to xml fragment Only when i click the Source Code Button on my activity.
This is my Activity Code
package com.example.shivnandan.listview;
import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class main_act extends Activity
{
TextView t1 ,t2;
EditText e1;
Button b1,b2;
// String e;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main_act_layout);
// e =( getIntent().getExtras().getString("main_act"));
t1 = (TextView)findViewById(R.id.textView3);
t2 = (TextView)findViewById(R.id.textView4);
e1 = (EditText)findViewById(R.id.editText);
b1 = (Button)findViewById(R.id.button);
b2 =(Button)findViewById(R.id.button2);
b1.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent i = new Intent(getApplicationContext(),main_act_2.class);
i.putExtra("name",(e1.getText().toString()));
startActivity(i);
}
});
b2.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent i = new Intent(getApplication(),SourceCode_Activity.class);
startActivity(i);
}
});
}
}
This is My Fragment Activity
package com.example.shivnandan.listview;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ScrollView;
import android.widget.TextView;
import android.app.Activity;
import android.widget.ZoomControls;
public class Fragment1 extends android.support.v4.app.Fragment {
ZoomControls z;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View v = inflater.inflate(R.layout.frag1, null);
// return inflater.inflate(R.layout.frag1,container,false);
z = (ZoomControls) v.findViewById(R.id.zoomControls);
final TextView tv1 = (TextView) v.findViewById(R.id.textView7);
z.setOnZoomInClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
float x = tv1.getScaleX();
float y = tv1.getScaleY();
tv1.setScaleX((float) (x + 1));
tv1.setScaleY((float) (y + 1));
}
});
z.setOnZoomOutClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
float x = tv1.getScaleX();
float y = tv1.getScaleY();
tv1.setScaleX((float) (x - 1));
tv1.setScaleY((float) (y - 1));
}
});
return v;
}
}
I dont think you can just copy the source code like that.
One easy way of achieving it would be by defining the strings which are the source codes of whatever you want to display and setting them appropriately as text to a textview in your fragment based on the button clicked.

How to set image resource in Android?

I am writing code for a poker game on eclipse and I am stuck on how to make the card clicked in the cardHand area show up in the playedCards area and have it removed from the deck I am drawing it from. Here's the code:
package com.viktorengineering.poker254;
import java.util.Random;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import java.util.Random;
public class Poker extends Activity {
private ImageView mViewDeck;
private ImageView mViewHand;
private ImageView mViewPlayedCards;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.getWindow().setBackgroundDrawableResource(R.drawable.green_back);
mViewDeck = (ImageView) findViewById(R.id.deckImage);
mViewDeck.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
int[] imagesArray = {R.drawable.clubs_ace, R.drawable.hearts_seven, R.drawable.diamonds_five,
R.drawable.clubs_three, R.drawable.hearts_eight, R.drawable.spades_six};
Random random = new Random();
mViewHand.setImageResource(imagesArray[new Random().nextInt(6)]);
}
});
mViewHand = (ImageView) findViewById(R.id.cardHand);
mViewHand.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mViewPlayedCards.setImageResource(0);
mViewHand.setImageResource(0);
}
});
mViewPlayedCards = (ImageView) findViewById(R.id.playedCards);
}
}
Your Image in Drawable Folder means use bellow code
mViewPlayedCards.setImageResource(R.drawable.icon);
mViewHand.setImageResource(R.drawable.icon_home);

Using simple text view and button widgets in android

Im trying to make a basic program where you press a button and it adds to an integer. Im having trouble updating the text view.
package com.example.curtis.simpleapplication;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
int num;
TextView numview;
private void updateNumber(){
TextView numview = (TextView)findViewById(R.id.Number);
numview.setText(num);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupButton();
}
private void setupButton() {
Button button = (Button) findViewById(R.id.Button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
num = num + 1;
numview.setText(num);
}
});
}
Help would be great im trying to get into android and books havent been very helpful
There are a few mistakes here. First, you are never calling updateNumber() so numviewis never set. Moreover, you have two TextView numView once global in your MainActivity and again in updateNumber(). There is a better way to do this. But first go to activity_main.xml file and within the button tag add the the line android:onClick="onClick" something like this :
<Button
android:id="#+id/button1"
...
android:onClick="onClick"/>
Next in your MainActivity.java, add the following lines of code :
package com.example.curtis.simpleapplication;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
int num = 0;
TextView numview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
numview = (TextView)findViewById(R.id.Number);
}
public void onClick(View view){
num += 1;
numview.setText(String.valueOf(num));
}
}
onClick() will be automatically called when your button is clicked because of the android:onClick property.
you have two different objects with same name and it would cause error.
one of them is defined in your class (TextView numview;) and the other one is defined in your function update number.
in your onClick method you want to change numView defined in your class and it's not initialized. you have to add change your code :
package com.example.curtis.simpleapplication;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
int num;
TextView numview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
numview = (TextView)findViewById(R.id.Number);
setupButton();
}
private void setupButton() {
Button button = (Button) findViewById(R.id.Button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
num = num + 1;
numview.setText(num);
}
});
}
Put this code in your onClick function
num = num + 1;
updateNumber();
You are never calling updateNumber()
package com.example.curtis.simpleapplication;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
int num=0;
TextView numview;
private void updateNumber(int number){
numview = (TextView)findViewById(R.id.Number);
numview.setText(number);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupButton();
}
private void setupButton() {
Button button = (Button) findViewById(R.id.Button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
num = num + 1;
updateNumber(num);
}
});
}

Categories