cabosun 0 Newbie Poster

So im setting up this gui, but im getting this Nullpointer exception:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at addressbook.dnDisplay.jButton1ActionPerformed(dnDisplay.java:222)
	at addressbook.dnDisplay.access$600(dnDisplay.java:22)
	at addressbook.dnDisplay$7.actionPerformed(dnDisplay.java:128)
	at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
	at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
	at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
	at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
	at java.awt.Component.processMouseEvent(Component.java:6289)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
	at java.awt.Component.processEvent(Component.java:6054)
	at java.awt.Container.processEvent(Container.java:2041)
	at java.awt.Component.dispatchEventImpl(Component.java:4652)
	at java.awt.Container.dispatchEventImpl(Container.java:2099)
	at java.awt.Component.dispatchEvent(Component.java:4482)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
	at java.awt.Container.dispatchEventImpl(Container.java:2085)
	at java.awt.Window.dispatchEventImpl(Window.java:2478)
	at java.awt.Component.dispatchEvent(Component.java:4482)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
	at java.awt.EventQueue.access$000(EventQueue.java:85)
	at java.awt.EventQueue$1.run(EventQueue.java:603)
	at java.awt.EventQueue$1.run(EventQueue.java:601)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
	at java.awt.EventQueue$2.run(EventQueue.java:617)
	at java.awt.EventQueue$2.run(EventQueue.java:615)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

SearchModify.java

package addressbook;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.util.List; 
import javax.swing.JButton;
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.BoxLayout;
import javax.swing.BorderFactory;
import javax.swing.JOptionPane;


public class dnDisplay extends javax.swing.JFrame {
    
    
   private javax.swing.ButtonGroup Type;
    private javax.swing.JRadioButton doctorRadio;
    private javax.swing.JTextField fName;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField lName;
    private javax.swing.JRadioButton nurseRadio;
    private javax.swing.JTextField Pass;
    private javax.swing.JComboBox Specialty;
    private javax.swing.JTextField Username;
    private List<Dn> results;
   private AddDoctorNurseQueries addDoctorNurseQueries;

 
   
    public dnDisplay() {
        initComponents();
       
    }

    private void initComponents() {

       // AddDoctorNurseQueries = new AddDoctorNurseQueries();
        Type = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        lName = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        fName = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        Username = new javax.swing.JTextField();
        Pass = new …
cabosun 0 Newbie Poster

So im doing this swing java gui project where the admin can login and search, modify and add users to the database mysql.

Im having trouble putting in the right getParameter to get:

type = radio group button of 2 with 1 as Doctor and 1 as Nurse
Specialty = a list of different doctor specialties such as Plastic Surgeon, Pediatrician and etc.

Am I setting the 'get' right? for type(radiogroup) and specialty(drop down list)
Line 4 and 9 respectively are where i get errors.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                      
        int result = AddDoctorNurseQueries.addPerson( 
               
                type.getSelectedItem().toString(),
                lname.getText(), 
                fname.getText(), 
                username.getText(), 
                pass.getText(), 
                specialty.getSelectedItem().toString() );
      
      if ( result == 1 )
         JOptionPane.showMessageDialog( this, "Person added!",
            "Person added", JOptionPane.PLAIN_MESSAGE );
      else
         JOptionPane.showMessageDialog( this, "Person not added!",
            "Error", JOptionPane.PLAIN_MESSAGE );
          
    }
cabosun 0 Newbie Poster

I have this program that I am working on that I am trying to insert user entered integers till a "-1" is detected and it will stop inserting the integers into the Tree and print it out inOrder.

I am geting 2 errors:

File: S:\makeup1.java [line: 9]
Error: S:\makeup1.java:9: cannot find symbol
symbol : class Tree
location: class makeup1

File: S:\makeup1.java [line: 9]
Error: S:\makeup1.java:9: cannot find symbol
symbol : class Tree
location: class makeup1

import java.util.Scanner;
import java.io.*;

public class makeup1{
  
    public static void main(String [] args){
    
    int n;
    Tree t = new Tree();
    Scanner scanner = new Scanner(System.in);
    
    while(n!=-1){
      System.out.println("input integer into tree: ");
      n = scanner.nextInt();
      insert(t,n);
    }
   
  }
   public static class tree{
    public int value;
    public tree right;
    public tree left;
    public tree(int V, tree L, tree R){
      {
        value = V;
        left = L;
        right = R;
      }
    }
  }
   
   public static tree insert(tree t, int i){
     if(t==null){
      return null; 
     }
     if(t.left!=null){
       insert(t.left, i);
     }
     else if(t.right!=null){
       insert(t.right, i);
     }
   }
   public static tree treesort(tree t){
     if(t==null){
       return null;
     }
     if(!(t.left==null)){
       return t.left;
     }
     return t.right;
   }

}

Can anyone help me out?

cabosun 0 Newbie Poster

So I have two MAL programs that I am getting 2 errors in each of them. I am using xSpim on unix to run this program. I wrote this using the windows version PCSPIM which compiled the program and ran it flawlessly. But when I tried to run it using XSPIM on unix there are errors.

The Error is in the Last 2 lines of this program or Lines 276 and 277.

spim: (parser) Unknown character on line 276 of file p5a.mal
li $v0, 10

spim: (parser) syntax error on line 277of file P5a.mal
syscall

#This program is going to take an input positive integer. The number is assumed to be
#greater than zero. The program will find the Highest power of 2 that Divides the given
#value, no of 1's in binary representation of the given number and sum of digits.

#All the variables are going to be declared in the data section.
.data
#The messages which are going to be printed out in different situations needs to be 
#stored in memory.
Output_MaxDivisor_Message: .asciiz "Highest power of 2 that divides the given value = "
Output_NumberOf1_Message: .asciiz "No. of 1's in the binary representation = "
Output_SumOfDigit_Message: .asciiz "Sum of decimal digits = "
Input_Message: .asciiz "Input value: "
New_Line:		.asciiz "\n"

#This variable is going to hold the input integer.
Input_Number: .word 0

#This variable is going to store the power of 2 which will completly divide the input number
Max_Divisor: .word 0 …
cabosun 0 Newbie Poster

How can I alter what I have now so that It will continue to read user input until the user types:

-1

and then it will stop?

cabosun 0 Newbie Poster

I am having trouble figuring out how to read input from the keyboard and inserting that into a LinkedList. Any help or suggestions would be greatly appreciated.

import java.util.*;
import java.util.Scanner;
import java.io.*;

public class listlist{

        public static void main(String [] args){

             LinkedList ll = new LinkedList();
             Scanner in = new Scanner(System.in);
             System.out.println("Enter a number: ");
             int n = in.nextInt();

             ll.add(n);

        }
}
cabosun 0 Newbie Poster

I am suppose to make a MakeFile for the 2 source files named p4a.c and p4b.c
Am i doing this makefile correctly? Any suggestions would be so helpful

my MakeFile so far

.SUFFIXES: .c .o
CC - gcc
CFLAGS = -g
.c.o:
     $(CC) $(CFLAGS) -c $,

sample: p4a.c p4b.c
       gcc p4a.c p4b.c -o sample

p4a.c:

p4b.c:

clean:
       rm -f *.o core

p4a.c

#include<stdio.h>
#include<string.h>


main(int argc,char* argv[])
{
	short int a[100][5];
	short int res;


	FILE *fp1;
	if(!(fp1=fopen(argv[1],"r")))
		printf("Error opening file\n");
	else
	{
        FILE *fp2;
		int i,j,k,l;
		i=j=0;
		
		while(!feof(fp1))
		{
			for(j=0;j<4;j++)
				fscanf(fp1,"%d",&a[i][j]); 
			i++;
		}
		
		for(k=0;k<i;k++)
		{
			unsigned short int musk=!0; //musk=11...111
			musk=musk|15;				//musk=000..001111
			musk=musk<<12;				//musk=111100..000
			
			res=0;
			for(l=0;l<4;l++)
			{
				short int temp=(a[k][l]&musk);
				res=res|temp;
				musk=musk>>4;
			}
			a[k][4]=res;
		}

		
		if(!(fp2=fopen(argv[2],"w")))
			printf("Error:cannot open file");
		else
		{
			for(k=0;k<i;k++)
			{
				for(j=0;j<5;j++)
					fprintf(fp2,"%d%s",a[k][j],"\t");
				fprintf(fp2,"%s","\n");
			}
			fclose(fp1);
			fclose(fp2);
		}

}

	return 0;
}

p4b.c

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct token
{
	char name[15];
	int def,usecount,use[100];
}identifier;

identifier id[1000];
int idcounter;

void search(char* token,int linenum)
{
	int i;
	for(i=0;i<idcounter;i++)	//check if already exist
	{
		if(!strcmp(token,id[i].name))		
		{
			id[i].use[id[i].usecount]=linenum;
			id[i].usecount++;
			return;
		}

	}
	//insert
	strcpy(id[idcounter].name,token);
	id[idcounter].def=linenum;
	id[idcounter].usecount=0;
	idcounter++;		
	
}

void check(char line[81],int linenum)
{
	char token1[15];
	char* token=(char*)malloc(sizeof(char)*15);
	if(line[0]=='_' || (line[0]>='a' && line[0]<='z') || (line[0]>='A' && line[0]<='Z'))		
	{
		token=strtok(line," ,\t");	//take label
		strcpy(token1,token);
		if(token1[strlen(token1)-1]==':')
			token1[strlen(token1)-1]='\0';
		search(token1,linenum);
		
		token=strtok(0," ,\t");		//skip opcode\datatype
		strcpy(token1,token);
		if(token1[0]=='.')			//check data type
			return;
		while(token)
		{
			token=strtok(0," ,\t");
			if(token)
			{
				strcpy(token1,token);
				if(token1[0]=='#')
					return;			//start of comment
				else if(token1[0]=='_' || (token1[0]>='a' && token1[0]<='z') || (token1[0]>='A' && token1[0]<='Z'))
				{
					if(token1[strlen(token)-1]=='\n')
						token1[strlen(token)-1]='\0';
					search(token1,linenum);
				}
			}
		}
	}
	else …
cabosun 0 Newbie Poster

So I am suppose to write a program that will implementing one method if computing
checksums for a file containing integers.

I am executing the program by a command line from the following form:

p4a inputfile outputfile


I can compile the program in Dev C++ compiler with no errors. But the problem is that
when compile the program in unix command line by:

gcc p4a.c

I get the following errors:

p4a.c: In function `main':
p4a.c:42: parse error before `*'
p4a.c:43: `fp2' undeclared (first use in this function)
p4a.c:43: (Each undeclared identifier is reported only once
p4a.c:43: for each function it appears in.)

Can anyone point me in the right direction in fixing these errors so that I can compile correctly by command line


Here is the code below:

#include<stdio.h>
#include<string.h>


main(int argc,char* argv[])
{
	short int a[100][5];
	short int res;


	FILE *fp1;
	if(!(fp1=fopen(argv[1],"r")))
		printf("Error opening file\n");
	else
	{
		int i,j,k,l;
		i=j=0;
		
		while(!feof(fp1))
		{
			for(j=0;j<4;j++)
				fscanf(fp1,"%d",&a[i][j]); 
			i++;
		}
		
		for(k=0;k<i;k++)
		{
			unsigned short int musk=!0; //musk=11...111
			musk=musk|15;				//musk=000..001111
			musk=musk<<12;				//musk=111100..000
			
			res=0;
			for(l=0;l<4;l++)
			{
				short int temp=(a[k][l]&musk);
				res=res|temp;
				musk=musk>>4;
			}
			a[k][4]=res;
		}

		FILE *fp2;
		if(!(fp2=fopen(argv[2],"w")))
			printf("Error:cannot open file");
		else
		{
			for(k=0;k<i;k++)
			{
				for(j=0;j<5;j++)
					fprintf(fp2,"%d%s",a[k][j],"\t");
				fprintf(fp2,"%s","\n");
			}
			fclose(fp1);
			fclose(fp2);
		}

}

	return 0;
}
cabosun 0 Newbie Poster

Ok I have done the main section of my MergeSort program.

I have to accept 10 integers and put them into a list. I having trouble with inserting user input into a list.

Can anyone help?

import java.util.Scanner;
import java.util.LinkedList;  
 
import java.util.*;
public class mergesort{

public static class lp{
	int first;
	lp rest;

public lp(int f, lp r){
	
	first=f;
	rest=r;
}
}public static void show_list(lp p){
    
    if(p==null){
      System.out.println("null");
    }
     else {
      System.out.println(p.first);
      show_list(p.rest);
    }
  }
   public static lp merge(lp a, lp b){
     
     if(a==null)
       return b;
     
     if(b==null)
        return a; 
     
     if (a.first < b.first){
       return new lp(a.first, merge(a.rest,b));
     }
     else return new lp(b.first,merge(a,b.rest));
   }
   
  public static void main (String [] args){
  	
    lp list1 = new lp();
    
    
  	Scanner scanner = new Scanner(System.in);
  	System.out.println("input ten integers: ");
  	
  	// Part Where i have the problem reading input and putting
  	// into a list
  	for(int i=0; i<10; i++){
  		list1.add();
  	}
  	list1 = scanner.nextInt();
  	
  	
  }

}