Pretty printing a method in ASM Bytecode - java

I am trying (with no success) to print only the contents of a given method. The following code almost does the trick:
class MyTraceMethodVisitor extends MethodVisitor {
public MyTraceMethodVisitor(MethodVisitor mv) {
super(Opcodes.ASM4, mv);
}
#Override
public void visitMaxs(int maxStack, int maxLocals) {
}
}
class MyClassVisitor extends ClassVisitor {
public MyClassVisitor(ClassVisitor cv) {
super(Opcodes.ASM4, cv);
}
#Override
public FieldVisitor visitField(int access, String name, String desc,
String signature, Object value) {
return null;
}
#Override
public MethodVisitor visitMethod(int access, String name, String desc,
String signature, String[] exceptions) {
if (name.equals("get777"))
return new MyTraceMethodVisitor(super.visitMethod(access, name, desc, signature, exceptions));
return null;
}
}
running it with
ClassReader classReader = new ClassReader("something.Point");
PrintWriter printWriter = new PrintWriter(System.out);
TraceClassVisitor traceClassVisitor = new TraceClassVisitor(printWriter);
MyClassVisitor myClassVisitor = new MyClassVisitor(traceClassVisitor);
classReader.accept(myClassVisitor, ClassReader.SKIP_DEBUG);
resulting in
// class version 50.0 (50)
// access flags 0x21
public class something/Point {
// access flags 0x1
public get777()I
SIPUSH 777
IRETURN
}
What I'd like to get was just
SIPUSH 777
IRETURN
without signature, comments and whatsoever.
How can I accomplish that?

The answer is already pretty old and involves writing much code.
As of asm v5 printing method instructions is straightforward:
// Setup for asm ClassReader, ClassWriter and your implementation of the ClassVisitor(e.g.: YourClassVisitor)
final ClassReader reader = new ClassReader(classBytes);
final ClassWriter writer = new ClassWriter(classReader, ClassWriter.COMPUTE_MAXS);
final ClassVisitor visitor =new YourClassVisitor(Opcodes.ASM5, visitor);
In your implementation of the ClassVisitor, simply override the visitMethod method. Here an example:
public class YourClassVisitor extends ClassVisitor {
public InstrumentationClassVisitor(int api, ClassVisitor cv) {
super(api, cv);
}
#Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions);
Printer p = new Textifier(Opcodes.ASM5) {
#Override
public void visitMethodEnd() {
print(new PrintWriter(System.out)); // print it after it has been visited
}
};
return new TraceMethodVisitor(mv, p);
}
}
The TraceMethodVisitor will receive the event calls for visiting method instructions etc. by the classVisitor. The code will then be printed by the TraceMethodVisitor with the help of the Printer.

This seems to do the trick.. although I don't understand how:
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.util.Printer;
import org.objectweb.asm.util.Textifier;
import org.objectweb.asm.util.TraceClassVisitor;
public class BytecodePrettyPrinter {
/**
* Gets us the bytecode method body of a given method.
* #param className The class name to search for.
* #param methodName The method name.
* #param methodDescriptor The method's descriptor.
* Can be null if one wishes to just get the first
* method with the given name.
* #throws IOException
*/
public static String[] getMethod(String className, String methodName, String methodDescriptor) throws IOException {
ClassReader classReader = new ClassReader(className);
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
TraceClassVisitor traceClassVisitor = new TraceClassVisitor(null, new SourceCodeTextifier(), printWriter);
MethodSelectorVisitor methodSelectorVisitor = new MethodSelectorVisitor(traceClassVisitor, methodName, methodDescriptor);
classReader.accept(methodSelectorVisitor, ClassReader.SKIP_DEBUG);
return toList(stringWriter.toString());
}
/**
* Gets us the bytecode method body of a given method.
* #param className The class name to search for.
* #param methodName The method name.
* #throws IOException
*/
public static String[] getMethod(String className, String methodName) throws IOException {
return getMethod(className, methodName, null);
}
private static String[] toList(String str) {
//won't work correctly for all OSs
String[] operations = str.split("[" + "\n" + "]");
for (int i = 0; i < operations.length; ++i) {
operations[i] = operations[i].trim();
}
return operations;
}
private static class MethodSelectorVisitor extends ClassVisitor {
private final String methodName;
private final String methodDescriptor;
public MethodSelectorVisitor(ClassVisitor cv, String methodName, String methodDescriptor) {
super(Opcodes.ASM4, cv);
this.methodName = methodName;
this.methodDescriptor = methodDescriptor;
}
#Override
public MethodVisitor visitMethod(int access, String name, String desc,
String signature, String[] exceptions) {
if (methodName.equals(name)) {
if (methodDescriptor == null)
return new MaxVisitFilterMethodVisitor(super.visitMethod(access, name, desc, signature, exceptions));
if (methodDescriptor.equals(desc))
return new MaxVisitFilterMethodVisitor(super.visitMethod(access, name, desc, signature, exceptions));
}
return null;
}
}
private static class MaxVisitFilterMethodVisitor extends MethodVisitor {
public MaxVisitFilterMethodVisitor(MethodVisitor mv) {
super(Opcodes.ASM4, mv);
}
#Override
public void visitMaxs(int maxStack, int maxLocals) {
}
}
private static class SourceCodeTextifier extends Printer {
public SourceCodeTextifier() {
this(Opcodes.ASM4);
}
protected SourceCodeTextifier(final int api) {
super(api);
}
#Override
public void visit(
final int version,
final int access,
final String name,
final String signature,
final String superName,
final String[] interfaces)
{
}
#Override
public void visitSource(final String file, final String debug) {
}
#Override
public void visitOuterClass(
final String owner,
final String name,
final String desc)
{
}
#Override
public Textifier visitClassAnnotation(
final String desc,
final boolean visible)
{
return new Textifier();
}
#Override
public void visitClassAttribute(final Attribute attr) {
}
#Override
public void visitInnerClass(
final String name,
final String outerName,
final String innerName,
final int access)
{
}
#Override
public Textifier visitField(
final int access,
final String name,
final String desc,
final String signature,
final Object value)
{
return new Textifier();
}
#Override
public Textifier visitMethod(
final int access,
final String name,
final String desc,
final String signature,
final String[] exceptions)
{
Textifier t = new Textifier();
text.add(t.getText());
return t;
}
#Override
public void visitClassEnd() {
}
#Override
public void visit(final String name, final Object value) {
}
#Override
public void visitEnum(
final String name,
final String desc,
final String value)
{
}
#Override
public Textifier visitAnnotation(
final String name,
final String desc)
{
return new Textifier();
}
#Override
public Textifier visitArray(
final String name)
{
return new Textifier();
}
#Override
public void visitAnnotationEnd() {
}
#Override
public Textifier visitFieldAnnotation(
final String desc,
final boolean visible)
{
return new Textifier();
}
#Override
public void visitFieldAttribute(final Attribute attr) {
visitAttribute(attr);
}
#Override
public void visitFieldEnd() {
}
#Override
public Textifier visitAnnotationDefault() {
return new Textifier();
}
#Override
public Textifier visitMethodAnnotation(
final String desc,
final boolean visible)
{
return new Textifier();
}
#Override
public Textifier visitParameterAnnotation(
final int parameter,
final String desc,
final boolean visible)
{
return new Textifier();
}
#Override
public void visitMethodAttribute(final Attribute attr) {
}
#Override
public void visitCode() {
}
#Override
public void visitFrame(
final int type,
final int nLocal,
final Object[] local,
final int nStack,
final Object[] stack)
{
}
#Override
public void visitInsn(final int opcode) {
}
#Override
public void visitIntInsn(final int opcode, final int operand) {
}
#Override
public void visitVarInsn(final int opcode, final int var) {
}
#Override
public void visitTypeInsn(final int opcode, final String type) {
}
#Override
public void visitFieldInsn(
final int opcode,
final String owner,
final String name,
final String desc)
{
}
#Override
public void visitMethodInsn(
final int opcode,
final String owner,
final String name,
final String desc)
{
}
#Override
public void visitInvokeDynamicInsn(
String name,
String desc,
Handle bsm,
Object... bsmArgs)
{
}
#Override
public void visitJumpInsn(final int opcode, final Label label) {
}
#Override
public void visitLabel(final Label label) {
}
#Override
public void visitLdcInsn(final Object cst) {
}
#Override
public void visitIincInsn(final int var, final int increment) {
}
#Override
public void visitTableSwitchInsn(
final int min,
final int max,
final Label dflt,
final Label... labels)
{
}
#Override
public void visitLookupSwitchInsn(
final Label dflt,
final int[] keys,
final Label[] labels)
{
}
#Override
public void visitMultiANewArrayInsn(final String desc, final int dims) {
}
#Override
public void visitTryCatchBlock(
final Label start,
final Label end,
final Label handler,
final String type)
{
}
#Override
public void visitLocalVariable(
final String name,
final String desc,
final String signature,
final Label start,
final Label end,
final int index)
{
}
#Override
public void visitLineNumber(final int line, final Label start) {
}
#Override
public void visitMaxs(final int maxStack, final int maxLocals) {
}
#Override
public void visitMethodEnd() {
}
public void visitAttribute(final Attribute attr) {
}
}
}
and one can run it using:
#Test
public void someTest() throws IOException {
String[] ops = BytecodePrettyPrinter.getMethod("java.lang.String", "<init>", null);
for (String op : ops)
System.out.println(op);
}

In ASM 4, there is a new abstraction called Printer. you can pass your own Printer instance (e.g. extend or copy Textifier implementation) in constructor of the TraceClassVisitor.

The easiest thing I can think of is to use a regex or another type of string matching that filters out just instructions.
For example, use an OutputStreamWriter to write to a String instead. Keep an array of string values of all ASM opcode types, and then if a line in that String contains an opcode string then the line is an instruction.

Related

How print the entire data structure created with Composite?

I have class-Composite:
public class CompositeText implements ComponentText {
private TypeComponent type;
private String value;
private final List<ComponentText> childComponents;
private CompositeText() {
childComponents = new ArrayList<>();
}
public CompositeText(String value, TypeComponent typeComponent) {
this.value = value;
this.type = typeComponent;
childComponents = new ArrayList<>();
}
#Override
public void add(ComponentText componentText) {
childComponents.add(componentText);
}
#Override
public void remove(ComponentText componentText) {
childComponents.remove(componentText);
}
#Override
public TypeComponent getComponentType() {
return this.type;
}
#Override
public ComponentText getChild(int index) {
return childComponents.get(index);
}
#Override
public int getCountChildElements() {
return childComponents.size();
}
#Override
public int getCountAllElements() {
return childComponents.stream()
.mapToInt(ComponentText::getCountAllElements)
.sum();
}
#Override
public String toString() {
return null;
}
}
I created classes that perform the same action - parsing, parsing text into paragraphs, into sentences, into tokens, into symbols.
public class IntoParagraphParser implements ActionParser {
// call IntoSentenceParser
}
public class IntoSentenceParser implements ActionParser {
// call IntoLexemeParser
}
public class IntoLexemeParser implements ActionParser {
// call IntoSymbolParser
}
public class IntoSymbolParser implements ActionParser {
}
All data is stored in List <ComponentText> childComponents in class-Composite - CompositeText.
How to properly create a method so that it prints all the data that is inside the composite?
I think this will be the method toString() in CompositeText.
Class IntoParagraphParser look:
public class IntoParagraphParser implements ActionParser {
private static final String PARAGRAPH_SPLIT_REGEX = "(?m)(?=^\\s{4})";
private static final IntoParagraphParser paragraphParser = new IntoParagraphParser();
private static final IntoSentenceParser sentenceParser = IntoSentenceParser.getInstance();
private IntoParagraphParser() {
}
public static IntoParagraphParser getInstance() {
return paragraphParser;
}
public ComponentText parse(String text) throws TextException {
ComponentText oneParagraph;
ComponentText componentParagraph = new CompositeText(text, TypeComponent.PARAGRAPH);
String[] arrayParagraph = text.split(PARAGRAPH_SPLIT_REGEX);
for(String element: arrayParagraph) {
oneParagraph = new CompositeText(element, TypeComponent.PARAGRAPH);
oneParagraph.add(sentenceParser.parse(element));
componentParagraph.add(oneParagraph);
}
return componentParagraph;
}
}
Need #Override the method toString() in CompositeText like this:
#Override
public String toString() {
StringBuilder builder = new StringBuilder();
for (ComponentText component : childComponents) {
builder.append(component.toString());
}
return builder.toString();
}
But how to write this code correctly with Stream API?
#Override
public String toString() {
StringBuilder builder = new StringBuilder();
childComponents.stream().map(...????
return builder.toString();
}

How do I set limited generic return type

Taking the following 2 objects, I cant figure out how to make the following work.
public final *Generic SubType* getInfo(){
...
}
First the class I am working with
public class ResultEntry<Type extends ResultType>{
private final Type mType;
private final String mLabel;
private final String mInfo;
private ResultEntry(final Type t, final String label, final String info){
mType = t;
mLabel = label;
mInfo = info;
}
public static ResultEntry<ResultType> newInstance(final String label, final Number info){
return new ResultEntry<>(ResultType.NUMBER, label, info.toString());
}
public static ResultEntry<ResultType> newInstance(final String label, final Boolean info){
return new ResultEntry<>(ResultType.NUMBER, label, info.toString());
}
public static ResultEntry<ResultType> newInstance(final String label, final String info){
return new ResultEntry<>(ResultType.NUMBER, label, info);
}
public final ResultType getType(){
return mType;
}
public final String getLabel(){
return mLabel;
}
public final *Generic SybType* getInfo(){
}
}
And then enum ResultType
public enum ResultType {
STRING ("STRING"),
BOOLEAN ("BOOLEAN"),
NUMBER ("NUMBER");
private final String s;
ResultType(final String string){
s = string;
}
public final boolean isString(){
return s.equals(STRING.s);
}
public final boolean isBoolean(){
return s.equals(BOOLEAN.s);
}
public final boolean isNumber(){
return s.equals(NUMBER.s);
}
}
What I would like to do is have a way to check what mType is (String, Boolean, or Number) and then return that actual object. Something like,
public final *Generic SubType* getInfo(){
if(mType.isString()) return new String();
if(mType.isNumber()) return new Number();
if(mType.isBoolean()) return new Boolean();
}
Though obviously I would have actual information to pass back instead.
But I dont know if that is possible, and if so, I don't know how I would go about doing it. It does appear that Android is able to do it via AsyncTask.
For reference, I found most of this from This Question
I would suggest you do it like this, which doesn't convert the info values to String, i.e. mInfo is Object, not String.
public class ResultEntry<R> {
private final ResultType mType;
private final String mLabel;
private final Object mInfo;
private ResultEntry(final ResultType t, final String label, final Object info) {
this.mType = t;
this.mLabel = label;
this.mInfo = info;
}
public static ResultEntry<Number> newInstance(final String label, final Number info) {
return new ResultEntry<>(ResultType.NUMBER, label, info);
}
public static ResultEntry<Boolean> newInstance(final String label, final Boolean info) {
return new ResultEntry<>(ResultType.BOOLEAN, label, info);
}
public static ResultEntry<String> newInstance(final String label, final String info) {
return new ResultEntry<>(ResultType.STRING, label, info);
}
public final ResultType getType() {
return this.mType;
}
public final String getLabel() {
return this.mLabel;
}
#SuppressWarnings("unchecked")
public final R getInfo() {
return (R) this.mInfo;
}
}
Then you use it like this:
ResultEntry<Number> numEntry = ResultEntry.newInstance("", 5);
ResultEntry<Boolean> boolEntry = ResultEntry.newInstance("", true);
ResultEntry<String> strEntry = ResultEntry.newInstance("", "Foo");
Number numInfo = numEntry.getInfo();
Boolean boolInfo = boolEntry.getInfo();
String strInfo = strEntry.getInfo();

Error with writing to a file in Java [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 4 years ago.
I am getting the following errors.
Exception in thread "main" java.lang.NullPointerException at ReadFile.createDogs(ReadFile.java:41) at ReadFile.main(ReadFile.java:55)
The file is opening to the desktop. I feel I am missing something very
simple. I have included the class file also. The error is specific to
dogOutput.println(dogInfo);
Thank you.
import java.io.*;
import java.io.PrintWriter;
public class ReadFile
{
private static Canine[] getCanine()
{
Canine[] canines= new Canine[5];
canines[0]=new Canine("Thoedore", "Male", "Medium", 7, 50);
canines[1]=new Canine("Magellan", "Male", "Medium", 5, 50);
canines[2]=new Canine("Duffy", "Male", "Small", 10, 10);
canines[3]=new Canine("Sammie", "Female", "Medium", 7, 65);
canines[4]=new Canine("Snowball", "Male", "Small", 13, 17);
return canines;
}
private static PrintWriter createFile(String fileName)
{
try{
File listOfDogs = new File(fileName);
PrintWriter infoToWrite= new PrintWriter
( new BufferedWriter
(new FileWriter(listOfDogs)));
}
catch (IOException e)
{
System.out.println(" An I/O Error Occurred.");
System.exit(0);
}
return null;
}
private static void createDogs(Canine dog, PrintWriter dogOutput)
{
String dogInfo= dog.name + " " + dog.gender+ " " + dog.size +" ";
dogInfo += Integer.toString(dog.age)+ " "+
Double.toString(dog.weight);
dogOutput.println(dogInfo);
}
public static void main (String[] args)
{
Canine[] canines= getCanine();
System.out.println("Here1");
PrintWriter dogOutput =
createFile("/Users/Teacher/Desktop/Dogs.text");
for(Canine dogs: canines)
{
createDogs(dogs, dogOutput);
System.out.println("Here5");
}
dogOutput.close();
}
private static class Canine extends Pet
{
public static final String type="Dog";
public Canine()
{
super.type=this.type;
}
public Canine(String name, String gender, String size, int age, double
weight)
{
super.type=this.type;
super.name=name;
super.gender=gender;
super.size=size;
super.age=age;
super.weight=weight;
}
public static void setType(String word)
{
}
}
private static class Pet
{
public static String type;
public static String color;
public static String gender;
public static String temperment;
public static String food;
public static int age;
public static double weight;
public static String name;
public static String size;
public Pet()
{
}
public Pet(String type,String color,String gender,String temperment,
String food,int age,double weight,String name,String size)
{
type=type;
color=color;
gender=gender;
temperment=temperment;
food=food;
age=age;
weight=weight;
name=name;
size=size;
}
public Pet(String name, String gender, String size, int age, double
weight)
{
name=name;
gender=gender;
size=size;
age=age;
weight=weight;
}
public static String getType()
{
return type;
}
public static String getName()
{
return name;
}
public static String getSize()
{
return size;
}
public static String getColor()
{
return color;
}
public static String getTemperment()
{
return temperment;
}
public static String getFood()
{
return food;
}
public static String getGender()
{
return gender;
}
public static int getAge()
{
return age;
}
public static void setType(String word)
{
type=word;
}
public static void getName(String word)
{
name=word;
}
public static void setSize(String word)
{
size=word;
}
public static void setColor(String word)
{
color=word;
}
public static void getTemperment(String word)
{
temperment=word;
}
public static void setFood(String word)
{
food=word;
}
public static void setGender(String word)
{
gender=word;
}
public static void setAge(int ageSet)
{
age=ageSet;
}
public static void setWeight(double weightSet)
{
weight=weightSet;
}
public static void setName(String NameSet)
{
name=NameSet;
}
public String toString()
{
return ("Type "+type+"\n" +" Name "+name+"\n"+" Age "+age+"\n"+
"Size "+ size+"\n"+" Gender "+gender+"\n"+" Weight "+weight);
}
}
}
Try renaming the dogOutput variable. In java, you can't pass variables between static methods with the same name.
The simple answer: In createFile() you always return null instead of the instance of PrintWriter you just created as infoToWrite.
The complete answer: You need to strengthen your knowledge of OOP. The unnecessary use of static members, for instance, can have undesired effects.

DataFlavor custom class usage

I want to create a custom dataFlavor with my class (Item.class)
#Override
public synchronized void drop(DropTargetDropEvent dtde) {
DataFlavor itemFlavor = new DataFlavor(Item.class, Item.class.getSimpleName());
try{
System.out.println(dtde.getTransferable().getTransferData(itemFlavor));
}catch(UnsupportedFlavorException | IOException e){
e.printStackTrace();
}
}
Item.class
public class Item {
private String classFile;
private String imgFile;
private String imgPath;
public Item(String classFile, String imgFile, String imgPath){
this.classFile = classFile;
this.imgFile = imgFile;
this.imgPath = imgPath;
}
public String getImgFile() {
return imgFile;
}
public void setImgFile(String imgFile) {
this.imgFile = imgFile;
}
public String getClassFile() {
return classFile;
}
public void setClassFile(String classFile) {
this.classFile = classFile;
}
public String getImgPath() {
return imgPath;
}
public void setImgPath(String imgPath) {
this.imgPath = imgPath;
}
}
but I'm getting an error: java.awt.datatransfer.UnsupportedFlavorException: Item
Can you say what is wrong ?
I were using this docs https://docs.oracle.com/javase/tutorial/uiswing/dnd/dataflavor.html
Example, that demonstrate the problem DND Test Project
To get an error, try drag from JTable to JLayeredPane

how to implement Parcelable in android?

can you please tell me how to implement Parcelable in android? Actually I want to send an array list from one activity to another. So I google find in need to Parcelable the dot or model. But I have object of another class so how do I write in Parcelable? In other word
I have this object
DestinationStation destinationStation;
what should i write in this function public void writeToParcel
dest.writeString(destinationStation);
here is my code of both class
public class deparaturedaseboarddto implements Parcelable{
ArrayList<deparaturedaseboarddto> data;
public ArrayList<deparaturedaseboarddto> getData() {
return data;
}
public void setData(ArrayList<deparaturedaseboarddto> data) {
this.data = data;
}
#SerializedName("alertsId")
int alertsId;
#SerializedName("destExpArrival")
String destExpArrival;
#SerializedName("destSchArrival")
String destSchArrival;
#SerializedName("expDepart")
String expDepart;
#SerializedName("filteredStation")
String filteredStation;
#SerializedName("platformNo")
String platformNo;
#SerializedName("rid")
String rid;
#SerializedName("schDepart")
String schDepart;
#SerializedName("toc")
String toc;
#SerializedName("toExpArrival")
String toExpArrival;
#SerializedName("toSchArrival")
String toSchArrival;
#SerializedName("trainID")
String trainID;
#SerializedName("trainLastReportedAt")
String trainLastReportedAt;
#SerializedName("destinationStation")
DestinationStation destinationStation;
public deparaturedaseboarddto(String trainID,String toc,String trainLastReportedAt, String platformNo, String schDepart, String expDepart, int alertsId, String rid, String destSchArrival, String filteredStation, String destExpArrival, String toSchArrival, String toExpArrival,DestinationStation destinationStation){
super();
this.trainID=trainID;
this.toc=toc;
this.trainLastReportedAt=trainLastReportedAt;
this.platformNo=platformNo;
this.schDepart=schDepart;
this.expDepart=expDepart;
this.alertsId=alertsId;
this.destinationStation=destinationStation;
this.toExpArrival=toExpArrival;
this.toSchArrival=toSchArrival;
this.destExpArrival=destExpArrival;
this.filteredStation=filteredStation;
this.destSchArrival=destSchArrival;
this.rid=rid;
}
public DestinationStation getDestinationStation() {
return destinationStation;
}
public void setDestinationStation(DestinationStation destinationStation) {
this.destinationStation = destinationStation;
}
public int getAlertsId() {
return alertsId;
}
public void setAlertsId(int alertsId) {
this.alertsId = alertsId;
}
public String getDestExpArrival() {
return destExpArrival;
}
public void setDestExpArrival(String destExpArrival) {
this.destExpArrival = destExpArrival;
}
public String getDestSchArrival() {
return destSchArrival;
}
public void setDestSchArrival(String destSchArrival) {
this.destSchArrival = destSchArrival;
}
public String getExpDepart() {
return expDepart;
}
public void setExpDepart(String expDepart) {
this.expDepart = expDepart;
}
public String getFilteredStation() {
return filteredStation;
}
public void setFilteredStation(String filteredStation) {
this.filteredStation = filteredStation;
}
public String getPlatformNo() {
return platformNo;
}
public void setPlatformNo(String platformNo) {
this.platformNo = platformNo;
}
public String getRid() {
return rid;
}
public void setRid(String rid) {
this.rid = rid;
}
public String getSchDepart() {
return schDepart;
}
public void setSchDepart(String schDepart) {
this.schDepart = schDepart;
}
public String getToc() {
return toc;
}
public void setToc(String toc) {
this.toc = toc;
}
public String getToExpArrival() {
return toExpArrival;
}
public void setToExpArrival(String toExpArrival) {
this.toExpArrival = toExpArrival;
}
public String getToSchArrival() {
return toSchArrival;
}
public void setToSchArrival(String toSchArrival) {
this.toSchArrival = toSchArrival;
}
public String getTrainID() {
return trainID;
}
public void setTrainID(String trainID) {
this.trainID = trainID;
}
public String getTrainLastReportedAt() {
return trainLastReportedAt;
}
public void setTrainLastReportedAt(String trainLastReportedAt) {
this.trainLastReportedAt = trainLastReportedAt;
}
#Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(alertsId);
dest.writeString(destExpArrival);
dest.writeString(destSchArrival);
dest.writeString(expDepart);
dest.writeString(filteredStation);
dest.writeString(platformNo);
dest.writeString(rid);
dest.writeString(schDepart);
dest.writeString(toc);
dest.writeString(toExpArrival);
dest.writeString(toSchArrival);
dest.writeString(trainID);
dest.writeString(trainLastReportedAt);
dest.writeString(destinationStation);
}
public static final Parcelable.Creator<deparaturedaseboarddto> CREATOR = new Parcelable.Creator<deparaturedaseboarddto>() {
public deparaturedaseboarddto createFromParcel(Parcel in) {
return new deparaturedaseboarddto(in);
}
public deparaturedaseboarddto[] newArray(int size) {
return new deparaturedaseboarddto[size];
}
};
private deparaturedaseboarddto(Parcel in) {
this.alertsId=in.readInt();
this.destExpArrival=in.readString();
this.destSchArrival=in.readString();
this.expDepart=in.readString();
this.filteredStation=in.readString();
this.platformNo=in.readString();
this.rid=in.readString();
this.schDepart=in.readString();
this.toc=in.readString();
this.toExpArrival=in.readString();
this.toSchArrival=in.readString();
this.trainID=in.readString();
this.trainLastReportedAt=in.readString();
}
}
destinationstation:
import com.google.gson.annotations.SerializedName;
public class DestinationStation implements Parcelable {
#SerializedName("crsCode")
String crsCode;
#SerializedName("stationName")
String stationName;
public DestinationStation(String crsCode, String stationName) {
// TODO Auto-generated constructor stub
super();
this.crsCode=crsCode;
this.stationName=stationName;
}
public String getCrsCode() {
return crsCode;
}
public void setCrsCode(String crsCode) {
this.crsCode = crsCode;
}
public String getStationName() {
return stationName;
}
public void setStationName(String stationName) {
this.stationName = stationName;
}
#Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(crsCode);
dest.writeString(stationName);
}
public static final Parcelable.Creator<DestinationStation> CREATOR = new Parcelable.Creator<DestinationStation>() {
public DestinationStation createFromParcel(Parcel in) {
return new DestinationStation(in);
}
public DestinationStation[] newArray(int size) {
return new DestinationStation[size];
}
};
private DestinationStation(Parcel in) {
this.crsCode=in.readString();
this.stationName=in.readString();
}
}
I am getting error in this line
dest.writeString(destinationStation);
Could you please tell how to remove this error?

Categories