Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在使用jar文件的android代码中找不到类Def错误_Android_Jar_Noclassdeffounderror - Fatal编程技术网

在使用jar文件的android代码中找不到类Def错误

在使用jar文件的android代码中找不到类Def错误,android,jar,noclassdeffounderror,Android,Jar,Noclassdeffounderror,我在Eclispe ADT for android中使用一个简单的android代码来反转输入字符串。反转字符串函数是单独编写的,我已将其导出为jar文件。然后我将jar添加到我的android项目的libs文件夹中。在构建项目时,eclipse没有显示amy错误,但在运行时,在给出用户输入字符串并单击字符串按钮后,仿真器显示消息“不幸的是,‘我的第一个项目’已停止” 这是我的主要安卓活动课程 package com.example.myfirstproject; import Reverse

我在Eclispe ADT for android中使用一个简单的android代码来反转输入字符串。反转字符串函数是单独编写的,我已将其导出为jar文件。然后我将jar添加到我的android项目的libs文件夹中。在构建项目时,eclipse没有显示amy错误,但在运行时,在给出用户输入字符串并单击字符串按钮后,仿真器显示消息“不幸的是,‘我的第一个项目’已停止”

这是我的主要安卓活动课程

package com.example.myfirstproject;

import Reverse.ReverseSentence;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.Menu;
import android.widget.Toast;
import android.widget.EditText;
import android.widget.RadioButton;

public class MainActivity extends Activity {
private EditText text1,text2;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    text1=(EditText)findViewById(R.id.editText1);
    text2=(EditText)findViewById(R.id.editText2);

}

public void onClick(View view) {
    switch (view.getId()) {
    case R.id.button1:
      RadioButton celsiusButton = (RadioButton) findViewById(R.id.radio0);
      RadioButton fahrenheitButton = (RadioButton) findViewById(R.id.radio1);
      if (text1.getText().length() == 0) {
        Toast.makeText(this, "Please enter a valid number",
            Toast.LENGTH_LONG).show();
        return;
      }

      float inputValue = Float.parseFloat(text1.getText().toString());
      if (celsiusButton.isChecked()) {
        text1.setText(String
            .valueOf(convertFahrenheitToCelsius(inputValue)));
        celsiusButton.setChecked(false);
        fahrenheitButton.setChecked(true);
      } else {
        text1.setText(String
            .valueOf(convertCelsiusToFahrenheit(inputValue)));
        fahrenheitButton.setChecked(false);
        celsiusButton.setChecked(true);
      }
      break;
    case R.id.button2:
        String inputString=text2.getText().toString();
        if(text2.getText().length()==0){
        Toast.makeText(this, "You have enetered blank ", Toast.LENGTH_LONG).show();
        return;
        }

        try{
        //Reverse.ReverseSentence rObj=new Reverse.ReverseSentence();
        ReverseSentence rObj=new ReverseSentence();

        String outputString=new String();
        outputString=rObj.reverseString(inputString);
        text2.setText(outputString);
        }
        catch(Exception e){
            e.printStackTrace();
        }
        break;
    }
  }
// Converts to celsius
  private float convertFahrenheitToCelsius(float fahrenheit) {
    return ((fahrenheit - 32) * 5 / 9);
  }

  // Converts to fahrenheit
  private float convertCelsiusToFahrenheit(float celsius) {
    return ((celsius * 9) / 5) + 32;
  }

  //Reverses a string

  /*public String reverseString(String input){
        String original,reverse="";
        //Scanner scanner=new Scanner(System.in);

        original=input;
        System.out.println("The input string is "+ original);

        int length=original.length();

        for(int i=length-1;i>=0;i--){
            reverse=reverse+original.charAt(i);

            }

        return reverse;     

    }*/

@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;
}
}

我正在使用的jar文件包含以下组件。 1个META-INF文件夹, 2.类路径文件, 3.属性文件 4包含两个类文件Palindrome.class和
反向内容类

这两个类的源代码如下:-

回文类 反向强度等级:- 我没有找到解决问题的方法。我已经尝试将Android首选项->编译器->JDK遵从性修正到1.7,因为我的java代码是使用JDK1.7构建的。 但我仍然会遇到应用程序崩溃的问题

我使用EclipseJunoEE作为java开发IDE,使用EclipseJavaADT作为Android IDE

这是一个简单的程序,用于检查android中jar文件的可用性,但我发现了noClassDefFound错误。可能我遗漏了一些东西,这是一个愚蠢的问题,但我仍然无法解决这个问题

请帮助……

试试这个方法

1.Right click on your project and go to Properties.
2.go to java build path..//which is on the 5th position on left side
3.go to Order and Export tab.
4.check(Tick Mark) on your selected jar file. and click ok.
5.Now, clean your project and Run.

我认为你有两个选择:

1-将jar库的编译器设置为1.6

或者,让您的jar库实际上成为一个android项目,并在eclipse中将其标记为“库”


如果您的jar库根本不使用任何android代码,我会选择1。

我已经尝试过了,但它显示了相同的错误。我从android代码调用jar文件中的方法的代码部分是否有任何错误?请显示您的日志…您对此有答案吗?如果你有,你能接受下面的答案吗?或者在下面贴上你自己的答案,然后接受吗?
package Reverse;

public class ReverseSentence {

String original,reverse="";
public ReverseSentence(){

}
public ReverseSentence(String input){
    this.original=input;

}
public String reverseString(String input){

    //Scanner scanner=new Scanner(System.in);

    original=input;
    System.out.println("The input string is "+ original);

    int length=original.length();

    for(int i=length-1;i>=0;i--){
        reverse=reverse+original.charAt(i);

        }

    return reverse;     

}



}
1.Right click on your project and go to Properties.
2.go to java build path..//which is on the 5th position on left side
3.go to Order and Export tab.
4.check(Tick Mark) on your selected jar file. and click ok.
5.Now, clean your project and Run.