java.lang.noclassdeffounderror android应用程序

java.lang.noclassdeffounderror android应用程序,java,android,eclipse,Java,Android,Eclipse,我正在尝试制作一个可以在json解析器后台运行的应用程序,但每次ATTPT都会出错。我试过很多次使用清洁项目,但都不起作用 public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ma

我正在尝试制作一个可以在json解析器后台运行的应用程序,但每次ATTPT都会出错。我试过很多次使用清洁项目,但都不起作用

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
  Button startButton = (Button) findViewById(R.id.button);
startButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        Intent intent = new Intent(MainActivity.this, QuizActivity.class);
        startActivity(intent);
        }
    });
}
这是我的主要活动

package com.fyp.please;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class QuizActivity extends ActionBarActivity {
private TextView quizQuestion;

private RadioGroup radioGroup;
private RadioButton optionOne;
private RadioButton optionTwo;
private RadioButton optionThree;
private RadioButton optionFour;

private int currentQuizQuestion;
private int quizCount;

private QuizWrapper firstQuestion;
private List<QuizWrapper> parsedObject;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_quiz);

    quizQuestion = (TextView) findViewById(R.id.quiz_question);

    radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
    optionOne = (RadioButton) findViewById(R.id.radio0);
    optionTwo = (RadioButton) findViewById(R.id.radio1);
    optionThree = (RadioButton) findViewById(R.id.radio2);
    optionFour = (RadioButton) findViewById(R.id.radio3);

    Button previousButton = (Button) findViewById(R.id.previousquiz);
    Button nextButton = (Button) findViewById(R.id.nextquiz);

    AsyncJsonObject asyncObject = new AsyncJsonObject();
    asyncObject.execute("");

    nextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            int radioSelected = radioGroup.getCheckedRadioButtonId();
            int userSelection = getSelectedAnswer(radioSelected);

            int correctAnswerForQuestion = firstQuestion.getCorrectAnswer();

            if (userSelection == correctAnswerForQuestion) {
                // correct answer
                Toast.makeText(QuizActivity.this,
                        "You got the answer correct", Toast.LENGTH_LONG)
                        .show();
                currentQuizQuestion++;
                if (currentQuizQuestion >= quizCount) {
                    Toast.makeText(QuizActivity.this,
                            "End of the Quiz Questions", Toast.LENGTH_LONG)
                            .show();
                    return;
                } else {
                    firstQuestion = parsedObject.get(currentQuizQuestion);
                    quizQuestion.setText(firstQuestion.getQuestion());
                    String[] possibleAnswers = firstQuestion.getAnswers()
                            .split(",");
                    uncheckedRadioButton();
                    optionOne.setText(possibleAnswers[0]);
                    optionTwo.setText(possibleAnswers[1]);
                    optionThree.setText(possibleAnswers[2]);
                    optionFour.setText(possibleAnswers[3]);
                }
            } else {
                // failed question
                Toast.makeText(QuizActivity.this,
                        "You chose the wrong answer", Toast.LENGTH_LONG)
                        .show();
                return;
            }
        }
    });
    previousButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            currentQuizQuestion--;
            if (currentQuizQuestion < 0) {
                return;
            }
            uncheckedRadioButton();
            firstQuestion = parsedObject.get(currentQuizQuestion);
            quizQuestion.setText(firstQuestion.getQuestion());
            String[] possibleAnswers = firstQuestion.getAnswers()
                    .split(",");
            optionOne.setText(possibleAnswers[0]);
            optionTwo.setText(possibleAnswers[1]);
            optionThree.setText(possibleAnswers[2]);
            optionFour.setText(possibleAnswers[3]);
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_quiz, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

private class AsyncJsonObject extends AsyncTask<String, Void, String> {

    private ProgressDialog progressDialog;

    @Override
    protected String doInBackground(String... params) {

        HttpClient httpClient = new DefaultHttpClient(new BasicHttpParams());
        HttpPost httpPost = new HttpPost(
                "http://192.168.1.5/Android_Quiz/index1.php");
        String jsonResult = "";

        try {
            HttpResponse response = httpClient.execute(httpPost);
            jsonResult = inputStreamToString(
                    response.getEntity().getContent()).toString();
            System.out.println("Returned Json object "
                    + jsonResult.toString());

        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return jsonResult;
    }

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
        progressDialog = ProgressDialog.show(QuizActivity.this,
                "Downloading Quiz", "Wait....", true);
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        progressDialog.dismiss();
        System.out.println("Resulted Value: " + result);
        parsedObject = returnParsedJsonObject(result);
        if (parsedObject == null) {
            return;
        }
        quizCount = parsedObject.size();
        firstQuestion = parsedObject.get(0);

        quizQuestion.setText(firstQuestion.getQuestion());
        String[] possibleAnswers = firstQuestion.getAnswers().split(",");
        optionOne.setText(possibleAnswers[0]);
        optionTwo.setText(possibleAnswers[1]);
        optionThree.setText(possibleAnswers[2]);
        optionFour.setText(possibleAnswers[3]);
    }

    private StringBuilder inputStreamToString(InputStream is) {
        String rLine = "";
        StringBuilder answer = new StringBuilder();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        try {
            while ((rLine = br.readLine()) != null) {
                answer.append(rLine);
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return answer;
    }
}

private List<QuizWrapper> returnParsedJsonObject(String result) {

    List<QuizWrapper> jsonObject = new ArrayList<QuizWrapper>();
    JSONObject resultObject = null;
    JSONArray jsonArray = null;
    QuizWrapper newItemObject = null;

    try {
        resultObject = new JSONObject(result);
        System.out.println("Testing the water " + resultObject.toString());
        jsonArray = resultObject.optJSONArray("quiz_questions");
    } catch (JSONException e) {
        e.printStackTrace();
    }
    for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject jsonChildNode = null;
        try {
            jsonChildNode = jsonArray.getJSONObject(i);
            int id = jsonChildNode.getInt("id");
            String question = jsonChildNode.getString("question");
            String answerOptions = jsonChildNode
                    .getString("possible_answers");
            int correctAnswer = jsonChildNode.getInt("correct_answer");
            newItemObject = new QuizWrapper(id, question, answerOptions,
                    correctAnswer);
            jsonObject.add(newItemObject);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return jsonObject;
}

private int getSelectedAnswer(int radioSelected) {

    int answerSelected = 0;
    if (radioSelected == R.id.radio0) {
        answerSelected = 1;
    }
    if (radioSelected == R.id.radio1) {
        answerSelected = 2;
    }
    if (radioSelected == R.id.radio2) {
        answerSelected = 3;
    }
    if (radioSelected == R.id.radio3) {
        answerSelected = 4;
    }
    return answerSelected;
}

private void uncheckedRadioButton() {
    optionOne.setChecked(false);
    optionTwo.setChecked(false);
    optionThree.setChecked(false);
    optionFour.setChecked(false);
    }

}
LogCat窗口

提前谢谢

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.fyp.please"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="19" />

    <uses-permission android:name="android.permission.INTERNET"/>

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name=".MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name="com.fyp.please.QuizActivity"
                android:label="@string/title_activity_quiz" >

                <intent-filter>
                    <action android:name="com.fyp.please.QUIZACTIVITY" />

                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>

            </activity>
        </application>

    </manifest>

清单:-这是清单,我在默认活动中尝试了它,但没有使用意向充气器,但它不起作用:(

也可以-

Intent intent = new Intent(MainActivity.this, QuizActivity.class);
intent.setAction("com.fyp.please.QUIZACTIVITY");
startActivity(intent);



清理并生成项目。从测试设备/avd卸载以前安装的副本。然后再次运行。

确保导出源文件夹、android依赖项和“libs”

您可以编辑类路径并将exported=“true”添加到值中,或者在Eclipse上查看:右键>构建路径..>配置构建路径,在选项卡“Order and Export”下可以设置此值


然后重新构建项目。

你的类在你的android清单中吗?你试过了吗?是的,试过了:(但在我的情况下没有帮助)你也试过其他答案吗?因为你的错误似乎与此相同。请发布你的清单。我没能理解你的答案。你能分享一下它与“libs”的关系吗文件夹?抱歉,我误解了您的问题,您的活动是在源文件夹中还是在jar或Android项目中?这根本不是我的问题:).虽然我相信,我们不能将.java文件放在libs文件夹中,对吗?不,但我们可以将编译好的jar文件放在libs文件夹中,而.class将在jar中,并可用于您的项目中。请参见您的错误“04-20 12:44:06.200:W/dalvikvm(924):无法解析Lcom/fyp/please/QuizActivity的超类;(7)”您可能缺少导出ActionBarCompat库
Intent intent = new Intent(MainActivity.this, QuizActivity.class);
intent.setAction("com.fyp.please.QUIZACTIVITY");
startActivity(intent);
<activity android:name="com.fyp.please.QuizActivity"
          android:label="@string/title_activity_quiz" >

 </activity>